Skip to content

Commit

Permalink
Fixed /emoji info not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
hechfx committed Apr 15, 2024
1 parent aea66d8 commit 0c3a7fd
Showing 1 changed file with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package net.perfectdreams.loritta.morenitta.interactions.vanilla.discord

import dev.minn.jda.ktx.messages.Embed
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.entities.emoji.CustomEmoji
import net.dv8tion.jda.api.interactions.components.buttons.Button
import net.perfectdreams.discordinteraktions.common.commands.slashCommand
import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.styled
import net.perfectdreams.loritta.cinnamon.emotes.Emotes
import net.perfectdreams.loritta.common.commands.CommandCategory
Expand Down Expand Up @@ -80,8 +78,11 @@ class EmojiCommand : SlashCommandDeclarationWrapper {
override suspend fun execute(context: UnleashedContext, args: SlashCommandArguments) {
val emoji = args[options.emoji]

if (emoji.isValidSnowflake()) {
val searchedEmoji = context.loritta.lorittaShards.getEmoteById(emoji)
val emojis = context.guild.emojis

if (emojis.any { it.asMention == emoji || it.name == emoji }) {
// Search the emoji by name or mention...
val searchedEmoji = emojis.first { it.asMention == emoji || it.name == emoji }

if (searchedEmoji != null) {
context.reply(false) {
Expand All @@ -94,34 +95,32 @@ class EmojiCommand : SlashCommandDeclarationWrapper {
)
)
}
} else {
context.reply(true) {
styled(
context.i18nContext.get(I18N_PREFIX.Info.EmojiNotFound(emoji)),
Emotes.LoriHm
)
}
return
}

val foundEmoji = context.guild.getEmojisByName(emoji, true).firstOrNull()
if (foundEmoji != null) {
return
} else if (emoji.isValidSnowflake()) {
// Search for the emoji by ID...
val searchedEmoji = context.loritta.lorittaShards.getEmoteById(emoji)

if (searchedEmoji != null) {
context.reply(false) {
embeds.plusAssign(createDiscordCustomEmojiInfoEmbed(context, foundEmoji))
embeds.plusAssign(createDiscordCustomEmojiInfoEmbed(context, searchedEmoji))

actionRow(
Button.link(
foundEmoji.imageUrl + "?size=2048",
searchedEmoji.imageUrl + "?size=2048",
context.i18nContext.get(I18N_PREFIX.Info.OpenEmojiInBrowser)
)
)
}
return
}

return
} else {
val isUnicodeEmoji = Constants.EMOJI_PATTERN.matcher(emoji).find()
// If it's not an emoji ID or mention... Then it can be a unicode emoji!
val isUnicode = Constants.EMOJI_PATTERN.matcher(emoji).find()

if (isUnicodeEmoji) {
if (isUnicode) {
val codePoints = emoji.codePoints().toList().map { LorittaUtils.toUnicode(it).substring(2) }

val result = codePoints.joinToString(separator = "-")
Expand Down Expand Up @@ -165,6 +164,16 @@ class EmojiCommand : SlashCommandDeclarationWrapper {
)
)
}

return
}

// If none of the options works... fail it.
context.fail(true) {
styled(
context.i18nContext.get(I18N_PREFIX.Info.EmojiNotFound(emoji)),
Emotes.LoriHm
)
}
}
}
Expand Down

0 comments on commit 0c3a7fd

Please sign in to comment.