Merge pull request #212 from almeidx/feat/emojiinfo-snowflakes
Added support for snowflakes on EmojiInfoCmd
This commit is contained in:
commit
501820b805
3 changed files with 18 additions and 18 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
const customEmojiRegex = /(?:<a?:[a-z0-9_]{2,32}:)?([1-9]\d+)>?/i;
|
||||
|
||||
export function getCustomEmojiId(str: string): string | null {
|
||||
const emojiIdMatch = str.match(customEmojiRegex);
|
||||
return emojiIdMatch?.[1] ?? null;
|
||||
}
|
Loading…
Add table
Reference in a new issue