Skip to content

Commit

Permalink
fix parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed Nov 2, 2023
1 parent 1e5e113 commit 19a1219
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/moe/nikky/RoleChooserConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ data class RoleMappingConfig(
val roleName: String,
) : Data {
suspend fun reactionEmoji(guildBehavior: GuildBehavior): ReactionEmoji {
if(emoji.startsWith("<") && emoji.endsWith(">")) {
val id = emoji.substringAfterLast(":").substringBefore("<")
if(emoji.startsWith('<') && emoji.contains(":") && emoji.endsWith(">")) {
val id = emoji.substringAfterLast(":").substringBefore(">")
return guildBehavior.emojis.first { it.id.toString() == id }
.let {
logger.traceF { "found emoji ${it.name}, turning into reaction emoji" }
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/moe/nikky/RoleManagementExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.toList
Expand Down Expand Up @@ -930,7 +931,13 @@ class RoleManagementExtension : Extension(), Klogging {
roleChoosers = oldConfig.roleChoosers.mapValues { (_, roleChooserConfig) ->
roleChooserConfig.copy(
roleMapping = roleChooserConfig.roleMapping.map { mapping ->
val emoji = guild.emojis.firstOrNull { it.name == mapping.emoji || it.id.toString() == mapping.emoji }

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,
Expand Down

0 comments on commit 19a1219

Please sign in to comment.