Skip to content

Commit

Permalink
Fix messages with duplicate emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
fjaros committed Jan 2, 2021
1 parent 87095ed commit d50a182
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/scala/wowchat/discord/MessageResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import wowchat.common.{WowChatConfig, WowExpansion}
import wowchat.game.GameResources

import scala.collection.JavaConverters._
import scala.collection.mutable

object MessageResolver {

Expand Down Expand Up @@ -148,11 +149,18 @@ class MessageResolver(jda: JDA) {
emote.getName.toLowerCase -> emote.getId
}).toMap

val alreadyResolved = mutable.Set.empty[String]
regex.findAllIn(message).foldLeft(message) {
case (result, possibleEmoji) =>
emojiMap.get(possibleEmoji.toLowerCase).fold(result)(id => {
result.replace(s":$possibleEmoji:", s"<:$possibleEmoji:$id>")
})
val lPossibleEmoji = possibleEmoji.toLowerCase
if (alreadyResolved(lPossibleEmoji)) {
result
} else {
emojiMap.get(lPossibleEmoji).fold(result)(id => {
alreadyResolved += lPossibleEmoji
result.replace(s":$possibleEmoji:", s"<:$possibleEmoji:$id>")
})
}
}
}
}
Expand Down

0 comments on commit d50a182

Please sign in to comment.