diff --git a/src/main/kotlin/moe/nikky/RoleChooserConfig.kt b/src/main/kotlin/moe/nikky/RoleChooserConfig.kt index 6d8dfd2..c1e4058 100644 --- a/src/main/kotlin/moe/nikky/RoleChooserConfig.kt +++ b/src/main/kotlin/moe/nikky/RoleChooserConfig.kt @@ -76,7 +76,7 @@ data class RoleMappingConfig( val id = emoji.substringAfterLast(":").substringBefore(">") return guildBehavior.emojis.first { it.id.toString() == id } .let { - logger.traceF { "found emoji ${it.name}, turning into reaction emoji" } +// logger.traceF { "found emoji ${it.name}, turning into reaction emoji" } ReactionEmoji.from(it) } } @@ -85,11 +85,11 @@ data class RoleMappingConfig( return guildEmoji ?.let { - logger.traceF { "found emoji ${it.name}, turning into reaction emoji" } +// logger.traceF { "found emoji ${it.name}, turning into reaction emoji" } ReactionEmoji.from(it) } ?: run { - logger.traceF { "creating unicode emoji from '$emoji'" } +// logger.traceF { "creating unicode emoji from '$emoji'" } ReactionEmoji.Unicode(emoji) } } @@ -97,22 +97,3 @@ data class RoleMappingConfig( return guildBehavior.getRole(role) } } - - -@Serializable -data class RoleChooserConfigOld( - val section: String, - @SerialComment("channel") - val channelId: Snowflake, - @SerialComment("message") - val messageId: Snowflake, - val roleMapping: List, -) : Data - - -@Serializable -data class RoleMappingConfigOld( - val reaction: String, - val role: Snowflake, - val roleName: String, -) : Data \ No newline at end of file diff --git a/src/main/kotlin/moe/nikky/RoleManagementExtension.kt b/src/main/kotlin/moe/nikky/RoleManagementExtension.kt index 1c26707..0c64ad9 100644 --- a/src/main/kotlin/moe/nikky/RoleManagementExtension.kt +++ b/src/main/kotlin/moe/nikky/RoleManagementExtension.kt @@ -519,9 +519,7 @@ class RoleManagementExtension : Extension(), Klogging { } try { roleMapping.forEach { entry -> - logger.traceF { "parse emoji" } val reactionEmoji: ReactionEmoji = entry.reactionEmoji(guild) - logger.traceF { "get role ${entry.role}" } val role = entry.getRole(guild) logger.traceF { "adding reaction $reactionEmoji for role ${role.name}" } message.addReaction(reactionEmoji) @@ -877,98 +875,48 @@ class RoleManagementExtension : Extension(), Klogging { } suspend fun migrateConfig(guild: GuildBehavior) { - try { - val oldConfig = StorageUnit( - storageType = StorageType.Config, - namespace = name, - identifier = "role-management", - dataType = RoleManagementConfigOld::class - ).withGuild(guild).get() ?: return - - val newData = RoleManagementConfig( - roleChoosers = oldConfig.roleChoosers.mapValues { (_, roleChooserConfig) -> - RoleChooserConfig( - section = roleChooserConfig.section, - channelId = roleChooserConfig.channelId, - messageId = roleChooserConfig.messageId, - roleMapping = roleChooserConfig.roleMapping.map { mapping -> - val emoji = - guild.emojis.firstOrNull { it.mention == mapping.reaction } - if(emoji != null) { - RoleMappingConfig( - emoji = emoji.id.toString(), - emojiName = emoji.name, - role = mapping.role, - roleName = mapping.roleName - ) - } else { - RoleMappingConfig( - emoji = mapping.reaction, - emojiName = mapping.reaction, - role = mapping.role, - roleName = mapping.roleName - ) - } - } - ) - } - ) - guild.config().save(newData) - return - } catch (e: Exception) { - - } - - try { - val oldConfig = StorageUnit( - storageType = StorageType.Config, - namespace = name, - identifier = "role-management", - dataType = RoleManagementConfig::class - ).withGuild(guild).get() ?: return - - val newData = RoleManagementConfig( - roleChoosers = oldConfig.roleChoosers.mapValues { (_, roleChooserConfig) -> - roleChooserConfig.copy( - roleMapping = roleChooserConfig.roleMapping.map { mapping -> - - val emoji = if(mapping.emoji.startsWith("<") && mapping.emoji.endsWith(">")) { - val id = mapping.emoji.substringAfterLast(":").substringBefore(">") - guild.emojis.firstOrNull { it.id.toString() == id } - } else { - guild.emojis.firstOrNull { it.name == mapping.emoji || it.id.toString() == mapping.emoji } - } - if(emoji != null) { - mapping.copy( - emojiName = emoji.name, - emoji = emoji.id.toString(), - ) - } else { - mapping.copy( - emojiName = mapping.emoji - ) - } - } - ) - } - ) - guild.config().save(newData) - return - } catch (e: Exception) { - - } +// try { +// val oldConfig = StorageUnit( +// storageType = StorageType.Config, +// namespace = name, +// identifier = "role-management", +// dataType = RoleManagementConfig::class +// ).withGuild(guild).get() ?: return +// +// val newData = RoleManagementConfig( +// roleChoosers = oldConfig.roleChoosers.mapValues { (_, roleChooserConfig) -> +// roleChooserConfig.copy( +// roleMapping = roleChooserConfig.roleMapping.map { mapping -> +// +// val emoji = if(mapping.emoji.startsWith("<") && mapping.emoji.endsWith(">")) { +// val id = mapping.emoji.substringAfterLast(":").substringBefore(">") +// guild.emojis.firstOrNull { it.id.toString() == id } +// } else { +// guild.emojis.firstOrNull { it.name == mapping.emoji || it.id.toString() == mapping.emoji } +// } +// if(emoji != null) { +// mapping.copy( +// emojiName = emoji.name, +// emoji = emoji.id.toString(), +// ) +// } else { +// mapping.copy( +// emojiName = mapping.emoji +// ) +// } +// } +// ) +// } +// ) +// guild.config().save(newData) +// return +// } catch (e: Exception) { +// +// } } } -@Serializable -data class RoleManagementConfigOld( - val roleChoosers: Map = emptyMap(), -) : Data -{ - -} - @Serializable data class RoleManagementConfig( val roleChoosers: Map = emptyMap(),