Skip to content

Commit

Permalink
add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed Nov 2, 2023
1 parent 75b2827 commit 5246941
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/main/kotlin/moe/nikky/RoleChooserConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ data class RoleMappingConfig(
) : Data {
suspend fun reactionEmoji(guildBehavior: GuildBehavior): ReactionEmoji {
return guildBehavior.emojis.firstOrNull { it.mention == reaction }
?.let { ReactionEmoji.from(it) }
?: ReactionEmoji.Unicode(reaction)
?.let {
logger.traceF { "found emoji ${it.name}, turning into reaction emoji" }
ReactionEmoji.from(it)
}
?: run {
logger.traceF { "creating unicode emoji from '$reaction'" }
ReactionEmoji.Unicode(reaction)
}
}
suspend fun getRole(guildBehavior: GuildBehavior): Role {
return guildBehavior.getRole(role)
Expand Down
12 changes: 7 additions & 5 deletions src/main/kotlin/moe/nikky/RoleManagementExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ 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)
Expand All @@ -526,7 +528,7 @@ class RoleManagementExtension : Extension(), Klogging {
.filter { member ->
role.id !in member.roleIds
}.collect { member ->
logger.info { "adding '${role.name}' to '${member.effectiveName}'" }
logger.infoF { "adding '${role.name}' to '${member.effectiveName}'" }
member.addRole(role.id)
}
}
Expand Down Expand Up @@ -558,10 +560,10 @@ class RoleManagementExtension : Extension(), Klogging {
channel as? TextChannel ?: relayError("${channel.mention} is not a Text Channel")
}

val reaction = arguments.reaction
if(reaction is ReactionEmoji.Custom && reaction.isAnimated) {
relayError("animated emojis are not supported")
}
// val reaction = arguments.reaction
// if(reaction is ReactionEmoji.Custom && reaction.isAnimated) {
// relayError("animated emojis are not supported")
// }

val configUnit = guild.config()
val (key, roleChooserConfig) = configUnit.get()?.find(arguments.section, channel.id)
Expand Down

0 comments on commit 5246941

Please sign in to comment.