Skip to content

Commit

Permalink
1.5.1-SNAPSHOT: Kord M6, with a silly hack. Also, #101.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Oct 7, 2021
1 parent 586020d commit e93e957
Show file tree
Hide file tree
Showing 36 changed files with 179 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.kotlindiscord.kord.extensions.utils.env
import org.koin.core.logger.Level

suspend fun main() {
val bot = ExtensibleBot(env("TOKEN")!!) {
val bot = ExtensibleBot(env("TOKEN")) {
koinLogLevel = Level.DEBUG

chatCommands {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.kotlindiscord.kord.extensions.utils.env
import org.koin.core.logger.Level

suspend fun main() {
val bot = ExtensibleBot(env("TOKEN")!!) {
val bot = ExtensibleBot(env("TOKEN")) {
koinLogLevel = Level.DEBUG

chatCommands {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kotlin.incremental = true

ksp.incremental = false

projectVersion = 1.5.0-SNAPSHOT
projectVersion = 1.5.1-SNAPSHOT

#dokka will run out of memory with the default meta space
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ public open class ExtensibleBot(public val settings: ExtensibleBotBuilder, priva

defaultStrategy = settings.cacheBuilder.defaultStrategy

if (settings.intentsBuilder != null) {
this.intents = Intents(settings.intentsBuilder!!)
}

if (settings.shardingBuilder != null) {
sharding(settings.shardingBuilder!!)
}
Expand All @@ -100,15 +96,19 @@ public open class ExtensibleBot(public val settings: ExtensibleBotBuilder, priva
send(this@on)
}
}

registerListeners()
addDefaultExtensions()
}

/** Start up the bot and log into Discord. **/
public open suspend fun start() {
settings.hooksBuilder.runBeforeStart(this)

registerListeners()

getKoin().get<Kord>().login(settings.presenceBuilder)
getKoin().get<Kord>().login {
this.presence(settings.presenceBuilder)
this.intents = Intents(settings.intentsBuilder!!)
}
}

/** This function sets up all of the bot's default event listeners. **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import dev.kord.core.behavior.GuildBehavior
import dev.kord.core.behavior.UserBehavior
import dev.kord.core.behavior.channel.ChannelBehavior
import dev.kord.core.builder.kord.KordBuilder
import dev.kord.core.builder.kord.Shards
import dev.kord.core.cache.KordCacheBuilder
import dev.kord.core.event.message.MessageCreateEvent
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.gateway.Intents
import dev.kord.gateway.builder.PresenceBuilder
import dev.kord.gateway.builder.Shards
import dev.kord.rest.builder.message.create.MessageCreateBuilder
import mu.KLogger
import mu.KotlinLogging
Expand Down Expand Up @@ -346,7 +346,6 @@ public open class ExtensibleBotBuilder {
hooksBuilder.runCreated(bot)
hooksBuilder.runBeforeExtensionsAdded(bot)

bot.addDefaultExtensions()
extensionsBuilder.extensions.forEach { bot.addExtension(it) }

hooksBuilder.runAfterExtensionsAdded(bot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public suspend fun topChannelFor(event: Event): ChannelBehavior? {
* @param event The event concerning to the channel to retrieve.
* @return A [Long] representing the channel ID, or null if there isn't one.
*/
public suspend fun channelIdFor(event: Event): Long? {
public suspend fun channelIdFor(event: Event): ULong? {
return when (event) {
is ChannelCreateEvent -> event.channel.id.value
is ChannelDeleteEvent -> event.channel.id.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public abstract class ApplicationCommandRegistry : KoinComponent {
): T? {
try {
if (guild != null) {
kord.editApplicationCommandPermissions(kord.resources.applicationId, guild.id, commandId) {
kord.editApplicationCommandPermissions(guild.id, commandId) {
injectRawPermissions(this, command)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public open class DefaultApplicationCommandRegistry : ApplicationCommandRegistry
try {
commandsWithPerms.forEach { (guildId, commands) ->
if (guildId != null) {
kord.bulkEditApplicationCommandPermissions(kord.resources.applicationId, guildId) {
kord.bulkEditApplicationCommandPermissions(guildId) {
commands.forEach { (id, commandObj) ->
command(id) { injectRawPermissions(this, commandObj) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.event.interaction.MessageCommandInteractionCreateEvent
import dev.kord.rest.builder.message.create.EphemeralInteractionResponseCreateBuilder
import dev.kord.rest.builder.message.create.InteractionResponseCreateBuilder

public typealias InitialEphemeralMessageResponseBuilder =
(suspend EphemeralInteractionResponseCreateBuilder.(MessageCommandInteractionCreateEvent) -> Unit)?
(suspend InteractionResponseCreateBuilder.(MessageCommandInteractionCreateEvent) -> Unit)?

/** Ephemeral message command. **/
public class EphemeralMessageCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.behavior.interaction.respondPublic
import dev.kord.core.event.interaction.MessageCommandInteractionCreateEvent
import dev.kord.rest.builder.message.create.PublicInteractionResponseCreateBuilder
import dev.kord.rest.builder.message.create.InteractionResponseCreateBuilder

public typealias InitialPublicMessageResponseBuilder =
(suspend PublicInteractionResponseCreateBuilder.(MessageCommandInteractionCreateEvent) -> Unit)?
(suspend InteractionResponseCreateBuilder.(MessageCommandInteractionCreateEvent) -> Unit)?

/** Public message command. **/
public class PublicMessageCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.entity.interaction.GroupCommand
import dev.kord.core.entity.interaction.SubCommand
import dev.kord.core.event.interaction.ChatInputCommandInteractionCreateEvent
import dev.kord.rest.builder.message.create.EphemeralInteractionResponseCreateBuilder
import dev.kord.rest.builder.message.create.InteractionResponseCreateBuilder

public typealias InitialEphemeralSlashResponseBuilder =
(suspend EphemeralInteractionResponseCreateBuilder.(ChatInputCommandInteractionCreateEvent) -> Unit)?
(suspend InteractionResponseCreateBuilder.(ChatInputCommandInteractionCreateEvent) -> Unit)?

/** Ephemeral slash command. **/
public class EphemeralSlashCommand<A : Arguments>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import dev.kord.core.behavior.interaction.respondPublic
import dev.kord.core.entity.interaction.GroupCommand
import dev.kord.core.entity.interaction.SubCommand
import dev.kord.core.event.interaction.ChatInputCommandInteractionCreateEvent
import dev.kord.rest.builder.message.create.PublicInteractionResponseCreateBuilder
import dev.kord.rest.builder.message.create.InteractionResponseCreateBuilder

public typealias InitialPublicSlashResponseBehavior =
(suspend PublicInteractionResponseCreateBuilder.(ChatInputCommandInteractionCreateEvent) -> Unit)?
(suspend InteractionResponseCreateBuilder.(ChatInputCommandInteractionCreateEvent) -> Unit)?

/** Public slash command. **/
public class PublicSlashCommand<A : Arguments>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ private const val DEFAULT_RADIX = 10
public
class NumberChoiceConverter(
private val radix: Int = DEFAULT_RADIX,
choices: Map<String, Int>,
override var validator: Validator<Int> = null
) : ChoiceConverter<Int>(choices) {
choices: Map<String, Long>,
override var validator: Validator<Long> = null
) : ChoiceConverter<Long>(choices) {
override val signatureTypeString: String = "converters.number.signatureType"

override suspend fun parse(parser: StringParser?, context: CommandContext, named: String?): Boolean {
val arg: String = named ?: parser?.parseNext()?.data ?: return false

try {
this.parsed = arg.toInt(radix)
this.parsed = arg.toLong(radix)
} catch (e: NumberFormatException) {
val errorString = if (radix == DEFAULT_RADIX) {
context.translate("converters.number.error.invalid.defaultBase", replacements = arrayOf(arg))
Expand All @@ -67,7 +67,7 @@ class NumberChoiceConverter(
IntChoiceBuilder(arg.displayName, arg.description).apply {
required = true

this@NumberChoiceConverter.choices.forEach { choice(it.key, it.value) }
this@NumberChoiceConverter.choices.forEach { choice(it.key, it.value.toInt()) }
}

override suspend fun parseOption(context: CommandContext, option: OptionValue<*>): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.event.interaction.UserCommandInteractionCreateEvent
import dev.kord.rest.builder.message.create.EphemeralInteractionResponseCreateBuilder
import dev.kord.rest.builder.message.create.InteractionResponseCreateBuilder

public typealias InitialEphemeralUserResponseBuilder =
(suspend EphemeralInteractionResponseCreateBuilder.(UserCommandInteractionCreateEvent) -> Unit)?
(suspend InteractionResponseCreateBuilder.(UserCommandInteractionCreateEvent) -> Unit)?

/** Ephemeral user command. **/
public class EphemeralUserCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.behavior.interaction.respondPublic
import dev.kord.core.event.interaction.UserCommandInteractionCreateEvent
import dev.kord.rest.builder.message.create.PublicInteractionResponseCreateBuilder
import dev.kord.rest.builder.message.create.InteractionResponseCreateBuilder

public typealias InitialPublicUserResponseBuilder =
(suspend PublicInteractionResponseCreateBuilder.(UserCommandInteractionCreateEvent) -> Unit)?
(suspend InteractionResponseCreateBuilder.(UserCommandInteractionCreateEvent) -> Unit)?

/** Public user command. **/
public class PublicUserCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class IntConverter(

override suspend fun parseOption(context: CommandContext, option: OptionValue<*>): Boolean {
val optionValue = (option as? OptionValue.IntOptionValue)?.value ?: return false
this.parsed = optionValue
this.parsed = optionValue.toInt()

return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import dev.kord.common.entity.ButtonStyle
import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.event.interaction.ButtonInteractionCreateEvent
import dev.kord.rest.builder.component.ActionRowBuilder
import dev.kord.rest.builder.message.create.EphemeralInteractionResponseCreateBuilder
import dev.kord.rest.builder.message.create.InteractionResponseCreateBuilder

public typealias InitialEphemeralButtonResponseBuilder =
(suspend EphemeralInteractionResponseCreateBuilder.(ButtonInteractionCreateEvent) -> Unit)?
(suspend InteractionResponseCreateBuilder.(ButtonInteractionCreateEvent) -> Unit)?

/** Class representing an ephemeral-only interaction button. **/
public open class EphemeralInteractionButton(
Expand Down Expand Up @@ -73,9 +73,9 @@ public open class EphemeralInteractionButton(
event.interaction.respondEphemeral { initialResponseBuilder!!(event) }
} else {
if (!deferredAck) {
event.interaction.acknowledgeEphemeralDeferredMessageUpdate()
} else {
event.interaction.acknowledgeEphemeral()
} else {
event.interaction.acknowledgeEphemeralDeferredMessageUpdate()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.behavior.interaction.respondPublic
import dev.kord.core.event.interaction.ButtonInteractionCreateEvent
import dev.kord.rest.builder.component.ActionRowBuilder
import dev.kord.rest.builder.message.create.PublicInteractionResponseCreateBuilder
import dev.kord.rest.builder.message.create.InteractionResponseCreateBuilder

public typealias InitialPublicButtonResponseBuilder =
(suspend PublicInteractionResponseCreateBuilder.(ButtonInteractionCreateEvent) -> Unit)?
(suspend InteractionResponseCreateBuilder.(ButtonInteractionCreateEvent) -> Unit)?

/** Class representing a public-only button component. **/
public open class PublicInteractionButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.scheduling.Task
import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.event.interaction.SelectMenuInteractionCreateEvent
import dev.kord.rest.builder.message.create.EphemeralInteractionResponseCreateBuilder
import dev.kord.rest.builder.message.create.InteractionResponseCreateBuilder

public typealias InitialEphemeralSelectMenuResponseBuilder =
(suspend EphemeralInteractionResponseCreateBuilder.(SelectMenuInteractionCreateEvent) -> Unit)?
(suspend InteractionResponseCreateBuilder.(SelectMenuInteractionCreateEvent) -> Unit)?

/** Class representing an ephemeral-only select (dropdown) menu. **/
public open class EphemeralSelectMenu(timeoutTask: Task?) : SelectMenu<EphemeralSelectMenuContext>(timeoutTask) {
Expand Down Expand Up @@ -59,9 +59,9 @@ public open class EphemeralSelectMenu(timeoutTask: Task?) : SelectMenu<Ephemeral
event.interaction.respondEphemeral { initialResponseBuilder!!(event) }
} else {
if (!deferredAck) {
event.interaction.acknowledgeEphemeralDeferredMessageUpdate()
} else {
event.interaction.acknowledgeEphemeral()
} else {
event.interaction.acknowledgeEphemeralDeferredMessageUpdate()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import com.kotlindiscord.kord.extensions.utils.scheduling.Task
import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.behavior.interaction.respondPublic
import dev.kord.core.event.interaction.SelectMenuInteractionCreateEvent
import dev.kord.rest.builder.message.create.PublicInteractionResponseCreateBuilder
import dev.kord.rest.builder.message.create.InteractionResponseCreateBuilder

public typealias InitialPublicSelectMenuResponseBuilder =
(suspend PublicInteractionResponseCreateBuilder.(SelectMenuInteractionCreateEvent) -> Unit)?
(suspend InteractionResponseCreateBuilder.(SelectMenuInteractionCreateEvent) -> Unit)?

/** Class representing a public-only select (dropdown) menu. **/
public open class PublicSelectMenu(timeoutTask: Task?) : SelectMenu<PublicSelectMenuContext>(timeoutTask) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package com.kotlindiscord.kord.extensions.events
import dev.kord.core.Kord
import dev.kord.core.event.Event
import org.koin.core.component.KoinComponent
import kotlin.coroutines.CoroutineContext

/**
* Base interface for events fired by Kord Extensions.
*/
public interface KordExEvent : Event, KoinComponent {
override val kord: Kord get() = getKoin().get()
override val shard: Int get() = -1
override val coroutineContext: CoroutineContext get() = kord.coroutineContext
}
Loading

0 comments on commit e93e957

Please sign in to comment.