diff options
Diffstat (limited to 'src/commands/utilities')
-rw-r--r-- | src/commands/utilities/steal.ts | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/src/commands/utilities/steal.ts b/src/commands/utilities/steal.ts index 6298271..734aab5 100644 --- a/src/commands/utilities/steal.ts +++ b/src/commands/utilities/steal.ts @@ -1,5 +1,5 @@ import { BushCommand, BushMessage } from '@lib'; -import { Argument } from 'discord-akairo'; +import { Snowflake } from 'discord-api-types'; export default class StealCommand extends BushCommand { public constructor() { @@ -13,19 +13,17 @@ export default class StealCommand extends BushCommand { }, args: [ { - id: 'emoji', - customType: Argument.union( - /<a?:(?<emojiName>[a-zA-Z0-9_]+):(?<emojiID>\d{15,21})>/gim, //emoji - 'url', - /^(\d{15,21})$/gim //snowflake - ), + id: 'emojiOrName', + customType: util.arg.union('discordEmoji', 'snowflake', 'url'), prompt: { start: 'What emoji would you like to steal?', - retry: '{error} Pick a valid emoji.', + retry: '{error} Pick a valid emoji, emoji id, or image url.', optional: true } }, - { id: 'name', match: 'option', flag: '--name', default: 'stolen_emoji' } + { + id: 'name2' + } ], slash: false, channel: 'guild', @@ -35,33 +33,39 @@ export default class StealCommand extends BushCommand { } public override async exec( message: BushMessage, - args: { emoji?: URL | string | { emojiName?: string; emojiID: string }; name: string } + args?: { emojiOrName?: { name: string; id: Snowflake; animated: boolean } | Snowflake | URL | string; name: string } ): Promise<unknown> { - if ((!args || !args.emoji) && !message.attachments.size) + if ((!args || !args.emojiOrName) && !message.attachments.size) return await message.util.reply(`${util.emojis.error} You must provide an emoji to steal.`); - client.console.debug(args, 5); + console.log(args); + const image = - (args?.emoji as any)?.matches && (args?.emoji as any)?.emojiID - ? `https://cdn.discordapp.com/emojis/${(args.emoji as any).emojiID}` - : typeof args.emoji === 'string' - ? `https://cdn.discordapp.com/emojis/${args.emoji}` - : typeof message.attachments.size && message.attachments.first()?.contentType?.includes('image/') + message.attachments.size && message.attachments.first()?.contentType?.includes('image/') ? message.attachments.first()!.url - : args?.emoji instanceof URL - ? args.emoji.href + : args?.emojiOrName instanceof URL + ? args.emojiOrName.href + : typeof args?.emojiOrName === 'object' + ? `https://cdn.discordapp.com/emojis/${args.emojiOrName.id}` + : client.consts.regex.discordEmoji.test(args?.emojiOrName ?? '') + ? `https://cdn.discordapp.com/emojis/${args!.emojiOrName}` : undefined; if (!image) return await message.util.reply(`${util.emojis.error} You must provide an emoji to steal.`); + if (message.attachments.size && typeof args?.emojiOrName !== 'string') + return await message.util.reply(`${util.emojis.error} You cannot attach an image and provide an argument.`); - const creationSuccess = await message - .guild!.emojis.create( - image, - args.name === 'stolen emoji' && (args?.emoji as any)?.emojiName ? (args?.emoji as any)?.emojiName : args.name, - { - reason: `Stolen by ${message.author.tag} (${message.author.id})` - } - ) - .catch((e: Error) => e); + const emojiName = message.attachments.size + ? (args?.emojiOrName as string) ?? 'stolen_emoji' + : args?.emojiOrName instanceof URL + ? args?.name ?? 'stolen_emoji' + : typeof args?.emojiOrName === 'object' + ? args?.name ?? args.emojiOrName.name ?? 'stolen_emoji' + : 'stolen_emoji'; + + const creationSuccess = await message.guild!.emojis.create(image, emojiName, { + reason: `Stolen by ${message.author.tag} (${message.author.id})` + }); + // .catch((e: Error) => e); if (!(creationSuccess instanceof Error)) return await message.util.reply(`${util.emojis.success} You successfully stole ${creationSuccess}.`); |