Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed Nov 8, 2024
1 parent d525e60 commit 88fb0e8
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 209 deletions.
21 changes: 11 additions & 10 deletions src/main/kotlin/moe/nikky/BotInfoExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import dev.kordex.core.extensions.ephemeralSlashCommand
import dev.kord.common.entity.Permission
import dev.kord.common.entity.Permissions
import dev.kord.rest.builder.message.embed
import dev.kordex.core.i18n.toKey
import io.klogging.Klogging
import io.ktor.http.*
import kotlinx.coroutines.flow.count
Expand Down Expand Up @@ -50,21 +51,21 @@ class BotInfoExtension : Extension(), Klogging {

inner class SetAdminRoleArgs : Arguments() {
val role by role {
name = "role"
description = "admin role"
name = "role".toKey()
description = "admin role".toKey()
}
}

override suspend fun setup() {
val self = kord.getSelf()

ephemeralSlashCommand {
name = "bot"
description = "${self.username} related commands"
name = "bot".toKey()
description = "${self.username} related commands".toKey()

ephemeralSubCommand() {
name = "show-config"
description = "shows the current configuration of (${self.username} ${self.mention})"
name = "show-config".toKey()
description = "shows the current configuration of (${self.username} ${self.mention})".toKey()
allowInDms = false

check {
Expand Down Expand Up @@ -110,8 +111,8 @@ class BotInfoExtension : Extension(), Klogging {
}

ephemeralSubCommand {
name = "invite"
description = "get invite url"
name = "invite".toKey()
description = "get invite url".toKey()

action {
withLogContextOptionalGuild(event, guild) { guild ->
Expand All @@ -124,8 +125,8 @@ class BotInfoExtension : Extension(), Klogging {
}

ephemeralSubCommand {
name = "stats"
description = "shows some numbers about (${self.username} ${self.mention})"
name = "stats".toKey()
description = "shows some numbers about (${self.username} ${self.mention})".toKey()
action {
val roleManagement: RoleManagementExtension? = getKoin().getOrNull()
val twitch: TwitchExtension? = getKoin().getOrNull()
Expand Down
19 changes: 10 additions & 9 deletions src/main/kotlin/moe/nikky/ConfigurationExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import dev.kord.core.behavior.GuildBehavior
import dev.kord.core.entity.Role
import dev.kord.core.event.Event
import dev.kord.core.event.interaction.InteractionCreateEvent
import dev.kordex.core.i18n.toKey
import io.github.xn32.json5k.SerialComment
import io.klogging.Klogging
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -54,22 +55,22 @@ class ConfigurationExtension : Extension(), Klogging {

inner class SetAdminRoleArgs : Arguments() {
val role by role {
name = "role"
description = "admin role"
name = "role".toKey()
description = "admin role".toKey()
}
}

override suspend fun setup() {
val self = kord.getSelf()
ephemeralSlashCommand {
name = "config"
name = "config".toKey()
// description = "${self.username} related commands"
description = "self.username related commands"
description = "self.username related commands".toKey()
allowInDms = false

ephemeralSubCommand(::SetAdminRoleArgs) {
name = "adminset"
description = "sets the admin role"
name = "adminset".toKey()
description = "sets the admin role".toKey()

check {
hasPermission(Permission.Administrator)
Expand All @@ -90,8 +91,8 @@ class ConfigurationExtension : Extension(), Klogging {
}

ephemeralSubCommand {
name = "adminunset"
description = "clears admin role"
name = "adminunset".toKey()
description = "clears admin role".toKey()
check {
hasPermission(Permission.Administrator)
}
Expand All @@ -115,7 +116,7 @@ class ConfigurationExtension : Extension(), Klogging {
}

suspend fun CheckContext<Event>.requiresBotControl(locale: Locale) {
val guild = guildFor(event)?.asGuildOrNull() ?: relayError("cannot load guild")
val guild = guildFor(event)?.asGuildOrNull() ?: relayError("cannot load guild".toKey())
val configUnit = guild.config()
val guildConfig = configUnit.get()
val adminRole = guildConfig?.adminRole(guild)
Expand Down
9 changes: 5 additions & 4 deletions src/main/kotlin/moe/nikky/DiceExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import dev.kordex.core.commands.Arguments
import dev.kordex.core.commands.converters.impl.string
import dev.kordex.core.extensions.Extension
import dev.kordex.core.extensions.publicSlashCommand
import dev.kordex.core.i18n.toKey
import io.klogging.Klogging

class DiceExtension() : Extension(), Klogging {
override val name: String = "dice"
override suspend fun setup() {
publicSlashCommand(::DiceArgs) {
name = "dice"
description = "rolls dice"
name = "dice".toKey()
description = "rolls dice".toKey()
allowInDms = true

action {
Expand Down Expand Up @@ -45,8 +46,8 @@ class DiceExtension() : Extension(), Klogging {

inner class DiceArgs : Arguments() {
val notation by string {
name = "notation"
description = "dices to roll"
name = "notation".toKey()
description = "dices to roll".toKey()
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/moe/nikky/KloggingExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dev.kord.core.entity.Guild
import dev.kord.core.entity.channel.GuildChannel
import dev.kord.core.event.Event
import dev.kord.core.event.interaction.InteractionCreateEvent
import dev.kordex.core.i18n.toKey
import io.klogging.context.logContext
import io.klogging.events.LogEvent
import io.klogging.logger
Expand Down Expand Up @@ -141,7 +142,7 @@ suspend fun <E : Event, T> Extension.withLogContext(
guildBehavior: GuildBehavior?,
block: suspend CoroutineScope.(Guild) -> T,
): T {
val guild = guildBehavior?.asGuild() ?: relayError("cannot load guild")
val guild = guildBehavior?.asGuild() ?: relayError("cannot load guild".toKey())
val items = mutableListOf<Pair<String, String?>>()
if (event is InteractionCreateEvent) {
items += "channel" to (event.interaction.channel.asChannel() as? GuildChannel)?.name
Expand Down
27 changes: 14 additions & 13 deletions src/main/kotlin/moe/nikky/LocalTimeExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.GuildBehavior
import dev.kord.core.entity.User
import dev.kord.rest.builder.message.embed
import dev.kordex.core.i18n.toKey
import io.klogging.Klogging
import io.ktor.client.request.forms.*
import io.ktor.utils.io.*
Expand Down Expand Up @@ -60,12 +61,12 @@ class LocalTimeExtension : Extension(), Klogging {
override suspend fun setup() {

ephemeralSlashCommand(::TimezoneArgs) {
name = "timezone"
description = "list or set timezones"
name = "timezone".toKey()
description = "list or set timezones".toKey()

ephemeralSubCommand(::TimezoneArgs) {
name = "set"
description = "update your timezone"
name = "set".toKey()
description = "update your timezone".toKey()

action {
withLogContext(event, guild) { guild ->
Expand Down Expand Up @@ -118,8 +119,8 @@ class LocalTimeExtension : Extension(), Klogging {
}

ephemeralSubCommand() {
name = "list"
description = "sends a list of valid timezones"
name = "list".toKey()
description = "sends a list of valid timezones".toKey()

action {
withLogContext(event, guild) { guild ->
Expand All @@ -144,7 +145,7 @@ class LocalTimeExtension : Extension(), Klogging {
}

ephemeralUserCommand {
name = "Local Time"
name = "Local Time".toKey()

action {
withLogContext(event, guild) { guild ->
Expand All @@ -162,8 +163,8 @@ class LocalTimeExtension : Extension(), Klogging {
}
}
ephemeralSlashCommand(::TimezoneTargetArgs) {
name = "LocalTime"
description = "get the local time for a user"
name = "LocalTime".toKey()
description = "get the local time for a user".toKey()

action {
withLogContext(event, guild) { guild ->
Expand Down Expand Up @@ -224,8 +225,8 @@ class LocalTimeExtension : Extension(), Klogging {

inner class TimezoneArgs : Arguments() {
val timezoneId by string {
name = "timezone"
description = "time zone id"
name = "timezone".toKey()
description = "time zone id".toKey()

autoComplete { event ->
val now = Clock.System.now()
Expand All @@ -248,8 +249,8 @@ class LocalTimeExtension : Extension(), Klogging {

inner class TimezoneTargetArgs : Arguments() {
val user by user {
name = "user"
description = "user to get local time for"
name = "user".toKey()
description = "user to get local time for".toKey()
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/moe/nikky/RoleChooserConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import dev.kord.core.entity.ReactionEmoji
import dev.kord.core.entity.Role
import dev.kord.core.entity.channel.TextChannel
import dev.kord.rest.request.KtorRequestException
import dev.kordex.core.i18n.toKey
import io.github.xn32.json5k.SerialComment
import io.klogging.context.logContext
import io.klogging.logger
Expand Down Expand Up @@ -44,7 +45,7 @@ data class RoleChooserConfig(
logContext("guild" to guildBehavior.name)
) {
guildBehavior.getChannelOfOrNull<TextChannel>(channelId)
?: relayError("channel $channelId in '${guildBehavior.name}' could not be loaded as TextChannel")
?: relayError("channel $channelId in '${guildBehavior.name}' could not be loaded as TextChannel".toKey())
}
}

Expand All @@ -56,7 +57,7 @@ data class RoleChooserConfig(
channel(guildBehavior).getMessageOrNull(messageId)
} catch (e: KtorRequestException) {
logger.errorF { e.message }
relayError("cannot access message $messageId")
relayError("cannot access message $messageId".toKey())
}
}
}
Expand Down
Loading

0 comments on commit 88fb0e8

Please sign in to comment.