From a9b0902a017d80bb7c2775dc657b03b7fb673252 Mon Sep 17 00:00:00 2001 From: Almeida Date: Mon, 10 May 2021 12:23:57 +0100 Subject: [PATCH] added support for emoji ids on emojiinfo command --- .../plugins/Utility/commands/EmojiInfoCmd.ts | 8 +++---- .../src/plugins/Utility/commands/InfoCmd.ts | 22 +++++++------------ .../Utility/functions/getCustomEmojiId.ts | 6 +++++ 3 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 backend/src/plugins/Utility/functions/getCustomEmojiId.ts diff --git a/backend/src/plugins/Utility/commands/EmojiInfoCmd.ts b/backend/src/plugins/Utility/commands/EmojiInfoCmd.ts index 3f7d094b..b863b344 100644 --- a/backend/src/plugins/Utility/commands/EmojiInfoCmd.ts +++ b/backend/src/plugins/Utility/commands/EmojiInfoCmd.ts @@ -1,7 +1,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage } from "../../../pluginUtils"; -import { customEmojiRegex } from "../../../utils"; import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed"; +import { getCustomEmojiId } from "../functions/getCustomEmojiId"; import { utilityCmd } from "../types"; export const EmojiInfoCmd = utilityCmd({ @@ -15,13 +15,13 @@ export const EmojiInfoCmd = utilityCmd({ }, async run({ message, args, pluginData }) { - const emojiIdMatch = args.emoji.match(customEmojiRegex); - if (!emojiIdMatch?.[2]) { + const emojiId = getCustomEmojiId(args.emoji); + if (!emojiId) { sendErrorMessage(pluginData, message.channel, "Emoji not found"); return; } - const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]); + const embed = await getEmojiInfoEmbed(pluginData, emojiId); if (!embed) { sendErrorMessage(pluginData, message.channel, "Emoji not found"); return; diff --git a/backend/src/plugins/Utility/commands/InfoCmd.ts b/backend/src/plugins/Utility/commands/InfoCmd.ts index 9c4b55d3..5dcf3456 100644 --- a/backend/src/plugins/Utility/commands/InfoCmd.ts +++ b/backend/src/plugins/Utility/commands/InfoCmd.ts @@ -2,26 +2,20 @@ import { Snowflake } from "discord.js"; import { getChannelId, getRoleId } from "knub/dist/utils"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage } from "../../../pluginUtils"; -import { - customEmojiRegex, - isValidSnowflake, - noop, - parseInviteCodeInput, - resolveInvite, - resolveUser, -} from "../../../utils"; +import { isValidSnowflake, noop, parseInviteCodeInput, resolveInvite, resolveUser } from "../../../utils"; +import { getUserInfoEmbed } from "../functions/getUserInfoEmbed"; import { canReadChannel } from "../../../utils/canReadChannel"; import { resolveMessageTarget } from "../../../utils/resolveMessageTarget"; import { getChannelInfoEmbed } from "../functions/getChannelInfoEmbed"; -import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed"; import { getGuildPreview } from "../functions/getGuildPreview"; import { getInviteInfoEmbed } from "../functions/getInviteInfoEmbed"; import { getMessageInfoEmbed } from "../functions/getMessageInfoEmbed"; import { getRoleInfoEmbed } from "../functions/getRoleInfoEmbed"; +import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed"; +import { getCustomEmojiId } from "../functions/getCustomEmojiId"; +import { utilityCmd } from "../types"; import { getServerInfoEmbed } from "../functions/getServerInfoEmbed"; import { getSnowflakeInfoEmbed } from "../functions/getSnowflakeInfoEmbed"; -import { getUserInfoEmbed } from "../functions/getUserInfoEmbed"; -import { utilityCmd } from "../types"; export const InfoCmd = utilityCmd({ trigger: "info", @@ -139,9 +133,9 @@ export const InfoCmd = utilityCmd({ // 8. Emoji if (userCfg.can_emojiinfo) { - const emojiIdMatch = value.match(customEmojiRegex); - if (emojiIdMatch?.[2]) { - const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]); + const emojiId = getCustomEmojiId(value); + if (emojiId) { + const embed = await getEmojiInfoEmbed(pluginData, emojiId); if (embed) { message.channel.send({ embeds: [embed] }); return; diff --git a/backend/src/plugins/Utility/functions/getCustomEmojiId.ts b/backend/src/plugins/Utility/functions/getCustomEmojiId.ts new file mode 100644 index 00000000..3fdce097 --- /dev/null +++ b/backend/src/plugins/Utility/functions/getCustomEmojiId.ts @@ -0,0 +1,6 @@ +const customEmojiRegex = /(?:?/i; + +export function getCustomEmojiId(str: string): string | null { + const emojiIdMatch = str.match(customEmojiRegex); + return emojiIdMatch?.[1] ?? null; +}