Skip to content

Commit

Permalink
1.9.0: Update Kord, switch to K2, update check functions
Browse files Browse the repository at this point in the history
Co-authored-by: Luca Kellermann <[email protected]>
  • Loading branch information
gdude2002 and lukellmann committed Jul 1, 2024
1 parent 32d126e commit 23dfa5f
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 87 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ fabric.properties
.env
docs/site
.linkie-cache/
.kotlin/
4 changes: 2 additions & 2 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ repositories {
}

dependencies {
implementation(kotlin("gradle-plugin", version = "1.9.24"))
implementation(kotlin("serialization", version = "1.9.24"))
implementation(kotlin("gradle-plugin", version = "2.0.20-Beta1"))
implementation(kotlin("serialization", version = "2.0.20-Beta1"))

implementation("com.github.ben-manes", "gradle-versions-plugin", "0.50.0")
implementation("com.github.jakemarsden", "git-hooks-gradle-plugin", "0.0.2")
implementation("com.google.devtools.ksp", "com.google.devtools.ksp.gradle.plugin", "1.9.24-1.0.20")
implementation("com.google.devtools.ksp", "com.google.devtools.ksp.gradle.plugin", "2.0.20-Beta1-1.0.22")
implementation("dev.yumi", "yumi-gradle-licenser", "1.2.0")
implementation("io.gitlab.arturbosch.detekt", "detekt-gradle-plugin", "1.23.6")
implementation("org.jetbrains.dokka", "dokka-gradle-plugin", "1.9.20")
Expand Down
8 changes: 5 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#dokka will run out of memory with the default metaspace
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m
org.gradle.parallel=true

kotlin.incremental=true
ksp.incremental=false
projectVersion=1.8.1-SNAPSHOT
#dokka will run out of memory with the default meta space
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m
ksp.useKSP2=true

projectVersion=1.9.0-SNAPSHOT
26 changes: 13 additions & 13 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
[versions]
detekt = "1.23.6" # Note: Plugin versions must be updated in buildSrc/build.gradle.kts
dokka = "1.9.20" # Note: Plugin versions must be updated in buildSrc/build.gradle.kts
kotlin = "1.9.24" # Note: Plugin versions must be updated in buildSrc/build.gradle.kts
kotlin = "2.0.20-Beta1" # Note: Plugin versions must be updated in buildSrc/build.gradle.kts

commons-validator = "1.8.0"
groovy = "3.0.21"
commons-validator = "1.9.0"
groovy = "3.0.22"
icu4j = "75.1"
jansi = "2.4.1"
jemoji = "1.4.1"
jsoup = "1.17.2"
junit = "5.10.2"
kaml = "0.59.0"
junit = "5.10.3"
kaml = "0.60.0"
koin = "3.5.6"
kord = "0.14.0-SNAPSHOT"
kord = "0.15.0-SNAPSHOT"
#kord = "0.12.0"
ksp = "1.9.24-1.0.20"
ktor = "2.3.11"
ksp = "2.0.20-Beta1-1.0.22"
ktor = "2.3.12"
kx-coro = "1.8.1"
kx-ser = "1.6.3"
kx-ser = "1.7.1"
linkie = "1.0.121"
logback = "1.5.6"
logback-groovy = "1.14.5"
logging = "6.0.9"
mongodb = "5.1.0"
pf4j = "3.11.1"
logging = "7.0.0"
mongodb = "5.1.1"
pf4j = "3.12.0"
semver = "2.0.0"
sentry = "7.9.0"
sentry = "7.10.0"
slf4j = "2.0.13"
time4j-base = "5.9.4"
time4j-tzdata = "5.0-2024a"
Expand Down
6 changes: 0 additions & 6 deletions kord-extensions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ dependencies {
kspTest(project(":annotation-processor"))
}

val compileKotlin: KotlinCompile by tasks

compileKotlin.kotlinOptions {
languageVersion = "1.7"
}

dokkaModule {
moduleName = "Kord Extensions"
includes.add("packages.md")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import dev.kord.core.cache.data.toData
import dev.kord.core.entity.Member
import dev.kord.core.entity.interaction.Interaction
import dev.kord.core.event.Event
import dev.kord.core.event.automoderation.AutoModerationActionExecutionEvent
import dev.kord.core.event.automoderation.AutoModerationEvent
import dev.kord.core.event.channel.*
import dev.kord.core.event.channel.thread.*
import dev.kord.core.event.guild.*
Expand All @@ -45,12 +47,27 @@ import kotlinx.coroutines.flow.first
*/
public suspend fun channelFor(event: Event): ChannelBehavior? {
return when (event) {
// KordEx generic event interface
is ChannelEvent -> event.channel

is AutoModerationActionExecutionEvent -> event.channel
is ChannelCreateEvent -> event.channel
is ChannelDeleteEvent -> event.channel
is ChannelPinsUpdateEvent -> event.channel
is ChannelUpdateEvent -> event.channel

is GuildAuditLogEntryCreateEvent -> if (event.auditLogEntry.options?.channelId?.value != null) {
event.kord.unsafe.channel(event.auditLogEntry.options!!.channelId.value!!)
} else {
null
}

is GuildScheduledEventEvent -> if (event.channelId != null) {
event.kord.unsafe.channel(event.channelId!!)
} else {
null
}

is InteractionCreateEvent -> event.interaction.channel
is InviteCreateEvent -> event.channel
is InviteDeleteEvent -> event.channel
Expand All @@ -65,11 +82,10 @@ public suspend fun channelFor(event: Event): ChannelBehavior? {
is TypingStartEvent -> event.channel
is VoiceStateUpdateEvent -> event.kord.unsafe.channel(event.state.channelId ?: return null)
is WebhookUpdateEvent -> event.channel

is ThreadChannelDeleteEvent -> event.old
// is ThreadListSyncEvent -> event.
is ThreadMemberUpdateEvent -> event.member.getThreadOrNull()
// is ThreadMembersUpdateEvent -> event.
is ThreadMembersUpdateEvent -> event.kord.unsafe.channel(event.id)
is ThreadUpdateEvent -> event.channel

else -> null
}
Expand Down Expand Up @@ -110,18 +126,23 @@ public suspend fun topChannelFor(event: Event): ChannelBehavior? {
*/
public suspend fun guildFor(event: Event): GuildBehavior? {
return when (event) {
// KordEx generic event interface
is GuildEvent -> event.guild

is AutoModerationEvent -> event.guild
is BanAddEvent -> event.guild
is BanRemoveEvent -> event.guild

is CategoryCreateEvent -> event.channel.guild
is CategoryDeleteEvent -> event.channel.guild
is CategoryUpdateEvent -> event.channel.guild
is EmojisUpdateEvent -> event.guild
is GuildCreateEvent -> event.guild
is GuildDeleteEvent -> event.guild
is GuildScheduledEventEvent -> event.kord.unsafe.guild(event.guildId)
is GuildUpdateEvent -> event.guild
is IntegrationCreateEvent -> event.guild
is IntegrationDeleteEvent -> event.guild
is IntegrationUpdateEvent -> event.guild
is IntegrationsUpdateEvent -> event.guild

is InteractionCreateEvent -> {
Expand Down Expand Up @@ -158,11 +179,18 @@ public suspend fun guildFor(event: Event): GuildBehavior? {
is NewsChannelCreateEvent -> event.channel.guild
is NewsChannelDeleteEvent -> event.channel.guild
is NewsChannelUpdateEvent -> event.channel.guild
is PresenceUpdateEvent -> event.guild
is ReactionAddEvent -> event.guild
is ReactionRemoveEvent -> event.guild
is TextChannelCreateEvent -> event.channel.guild
is TextChannelDeleteEvent -> event.channel.guild
is TextChannelUpdateEvent -> event.channel.guild
is ThreadChannelCreateEvent -> event.channel.guild
is ThreadUpdateEvent -> event.channel.guild
is ThreadChannelDeleteEvent -> event.channel.guild
is ThreadListSyncEvent -> event.guild
is ThreadMemberUpdateEvent -> event.member.getThreadOrNull()?.guild
is ThreadMembersUpdateEvent -> event.kord.unsafe.guild(event.guildId)
is TypingStartEvent -> event.guild
is VoiceChannelCreateEvent -> event.channel.guild
is VoiceChannelDeleteEvent -> event.channel.guild
Expand All @@ -171,12 +199,8 @@ public suspend fun guildFor(event: Event): GuildBehavior? {
is VoiceStateUpdateEvent -> event.state.getGuildOrNull()
is WebhookUpdateEvent -> event.guild

is ThreadChannelCreateEvent -> event.channel.guild
is ThreadUpdateEvent -> event.channel.guild
// is ThreadChannelDeleteEvent -> event.
is ThreadListSyncEvent -> event.guild
is ThreadMemberUpdateEvent -> event.member.getThreadOrNull()?.guild
// is ThreadMembersUpdateEvent -> event.
// TODO: Kord doesn't have the guild yet?
// is GuildAuditLogEntryCreateEvent -> event.auditLogEntry.userId

else -> null
}
Expand All @@ -195,8 +219,17 @@ public suspend fun guildFor(event: Event): GuildBehavior? {
*/
public suspend fun memberFor(event: Event): MemberBehavior? {
return when (event) {
// KordEx generic event interface
is MemberEvent -> event.member

is AutoModerationActionExecutionEvent -> event.member

is GuildScheduledEventEvent -> if (event.scheduledEvent.creatorId != null) {
event.kord.unsafe.member(event.guildId, event.scheduledEvent.creatorId!!)
} else {
null
}

is InteractionCreateEvent -> {
val guildId = event.interaction.data.guildId.value
?: return null
Expand All @@ -206,6 +239,8 @@ public suspend fun memberFor(event: Event): MemberBehavior? {
.getMemberOrNull(event.interaction.user.id)
}

is InviteCreateEvent -> event.inviterMember

is MemberJoinEvent -> event.member
is MemberUpdateEvent -> event.member
is MessageCreateEvent -> event.member
Expand All @@ -231,9 +266,13 @@ public suspend fun memberFor(event: Event): MemberBehavior? {
is ReactionRemoveEvent -> event.userAsMember
is TypingStartEvent -> event.getGuildOrNull()?.getMemberOrNull(event.userId)
is ThreadChannelCreateEvent -> event.channel.owner.asMember(event.channel.guildId)
// event is ThreadUpdateEvent -> event.
// event is ThreadChannelDeleteEvent -> event.
// event is ThreadListSyncEvent -> event.

is ThreadChannelDeleteEvent -> if (event.channel.data.ownerId.value != null) {
event.kord.unsafe.member(event.channel.guildId, event.channel.data.ownerId.value!!)
} else {
null
}

is ThreadMemberUpdateEvent -> {
val thread = event.member.getThreadOrNull()
?: return null
Expand All @@ -246,7 +285,6 @@ public suspend fun memberFor(event: Event): MemberBehavior? {
event.state.userId
)

// event is ThreadMembersUpdateEvent -> event.
else -> null
}
}
Expand All @@ -264,8 +302,23 @@ public suspend fun memberFor(event: Event): MemberBehavior? {
*/
public suspend fun messageFor(event: Event): MessageBehavior? {
return when (event) {
// KordEx generic event interface
is MessageEvent -> event.message

is AutoModerationActionExecutionEvent -> event.message

is GuildAuditLogEntryCreateEvent -> if (
event.auditLogEntry.options?.channelId?.value != null &&
event.auditLogEntry.options?.messageId?.value != null
) {
event.kord.unsafe.message(
event.auditLogEntry.options!!.channelId.value!!,
event.auditLogEntry.options!!.messageId.value!!
)
} else {
null
}

is MessageCreateEvent -> event.message
is MessageDeleteEvent -> event.message
is MessageUpdateEvent -> event.getMessage()
Expand All @@ -275,11 +328,6 @@ public suspend fun messageFor(event: Event): MessageBehavior? {
is ReactionRemoveEvent -> event.message

is ThreadChannelCreateEvent -> event.channel.getLastMessage()
// is ThreadUpdateEvent -> event.
// is ThreadChannelDeleteEvent -> event.
// is ThreadListSyncEvent -> event.
// is ThreadMemberUpdateEvent -> event.
// is ThreadMembersUpdateEvent -> event.

else -> null
}
Expand All @@ -294,23 +342,17 @@ public suspend fun messageFor(event: Event): MessageBehavior? {
* value.
*
* @param event The event concerning to the channel to retrieve.
* @return A [RoleBehavior] representing the role, or null if there isn't one.
* @return A [RoleBehavior] representing the role, or null if missing.
*/
public fun roleFor(event: Event): RoleBehavior? {
return when (event) {
// KordEx generic event interface
is RoleEvent -> event.role

is RoleCreateEvent -> event.role
is RoleDeleteEvent -> event.role
is RoleUpdateEvent -> event.role

// is ThreadChannelCreateEvent -> event.
// is ThreadUpdateEvent -> event.
// is ThreadChannelDeleteEvent -> event.
// is ThreadListSyncEvent -> event.
// is ThreadMemberUpdateEvent -> event.
// is ThreadMembersUpdateEvent -> event.

else -> null
}
}
Expand Down Expand Up @@ -342,8 +384,11 @@ public suspend fun threadFor(event: Event): ThreadChannelBehavior? =
*/
public suspend fun userFor(event: Event): UserBehavior? {
return when (event) {
// KordEx generic event interface
is UserEvent -> event.user

is AutoModerationActionExecutionEvent -> event.member

is BanAddEvent -> event.user
is BanRemoveEvent -> event.user

Expand All @@ -352,7 +397,22 @@ public suspend fun userFor(event: Event): UserBehavior? {
is DMChannelDeleteEvent -> event.channel.recipients.first { it.id != event.kord.selfId }
is DMChannelUpdateEvent -> event.channel.recipients.first { it.id != event.kord.selfId }

is GuildAuditLogEntryCreateEvent -> if (
event.auditLogEntry.userId != null
) {
event.kord.unsafe.user(event.auditLogEntry.userId!!)
} else {
null
}

is GuildScheduledEventEvent -> if (event.scheduledEvent.creatorId != null) {
event.kord.unsafe.user(event.scheduledEvent.creatorId!!)
} else {
null
}

is InteractionCreateEvent -> event.interaction.user
is InviteCreateEvent -> event.inviter
is MemberJoinEvent -> event.member
is MemberLeaveEvent -> event.user
is MemberUpdateEvent -> event.member
Expand All @@ -362,17 +422,18 @@ public suspend fun userFor(event: Event): UserBehavior? {
is PresenceUpdateEvent -> event.member
is ReactionAddEvent -> event.user
is ReactionRemoveEvent -> event.user
is TypingStartEvent -> event.user
is UserUpdateEvent -> event.user
is ThreadChannelCreateEvent -> event.channel.owner

is VoiceStateUpdateEvent -> event.kord.unsafe.user(event.state.userId)
is ThreadChannelDeleteEvent -> if (event.channel.data.ownerId.value != null) {
event.kord.unsafe.user(event.channel.data.ownerId.value!!)
} else {
null
}

is ThreadChannelCreateEvent -> event.channel.owner
// is ThreadUpdateEvent -> event.
// is ThreadChannelDeleteEvent -> event.
// is ThreadListSyncEvent -> event.
is ThreadMemberUpdateEvent -> event.member
// is ThreadMembersUpdateEvent -> event.
is TypingStartEvent -> event.user
is UserUpdateEvent -> event.user
is VoiceStateUpdateEvent -> event.kord.unsafe.user(event.state.userId)

else -> null
}
Expand Down
Loading

0 comments on commit 23dfa5f

Please sign in to comment.