diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-20 12:29:20 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-20 12:29:20 -0400 |
commit | 7048fb1d6d24a26d4e0fdadc2f75bd0717fa80f9 (patch) | |
tree | 3b66ea2934c577c0e827ba279cf32b514389236c /src | |
parent | bfb467c3bed23479673b82eba61c05d60acf42d7 (diff) | |
download | tanzanite-7048fb1d6d24a26d4e0fdadc2f75bd0717fa80f9.tar.gz tanzanite-7048fb1d6d24a26d4e0fdadc2f75bd0717fa80f9.tar.bz2 tanzanite-7048fb1d6d24a26d4e0fdadc2f75bd0717fa80f9.zip |
more pain
Diffstat (limited to 'src')
-rw-r--r-- | src/arguments/contentWithDuration.ts | 6 | ||||
-rw-r--r-- | src/arguments/discordEmoji.ts | 17 | ||||
-rw-r--r-- | src/arguments/duration.ts | 4 | ||||
-rw-r--r-- | src/arguments/snowflake.ts | 8 | ||||
-rw-r--r-- | src/commands/utilities/steal.ts | 60 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClient.ts | 6 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushCommand.ts | 11 | ||||
-rw-r--r-- | src/lib/utils/BushConstants.ts | 9 |
8 files changed, 84 insertions, 37 deletions
diff --git a/src/arguments/contentWithDuration.ts b/src/arguments/contentWithDuration.ts index 314b761..38b3fa4 100644 --- a/src/arguments/contentWithDuration.ts +++ b/src/arguments/contentWithDuration.ts @@ -1,8 +1,8 @@ -import { BushArgumentTypeCaster, BushMessage } from '@lib'; +import { BushArgumentTypeCaster } from '@lib'; export const contentWithDurationTypeCaster: BushArgumentTypeCaster = async ( - _message: BushMessage, - phrase: string + _, + phrase ): Promise<{ duration: number; contentWithoutTime: string | null }> => { return client.util.parseDuration(phrase); }; diff --git a/src/arguments/discordEmoji.ts b/src/arguments/discordEmoji.ts new file mode 100644 index 0000000..9884c98 --- /dev/null +++ b/src/arguments/discordEmoji.ts @@ -0,0 +1,17 @@ +import { Snowflake } from 'discord-api-types'; +import { BushArgumentTypeCaster } from '../lib'; + +export const discordEmojiTypeCaster: BushArgumentTypeCaster = ( + _, + phrase +): { name: string; id: Snowflake; animated: boolean } | null => { + console.log(phrase); + if (!phrase) return null; + const validEmoji = client.consts.regex.discordEmoji.test(phrase); + console.log(validEmoji); + if (!validEmoji) return null; + const emoji = phrase.replace(/[<>]/g, '').split(':'); + const animated = emoji[0] === 'a'; + console.log(emoji); + return { name: emoji[1], id: emoji[2], animated }; +}; diff --git a/src/arguments/duration.ts b/src/arguments/duration.ts index ce181e8..6e76034 100644 --- a/src/arguments/duration.ts +++ b/src/arguments/duration.ts @@ -1,5 +1,5 @@ -import { BushArgumentTypeCaster, BushMessage } from '@lib'; +import { BushArgumentTypeCaster } from '@lib'; -export const durationTypeCaster: BushArgumentTypeCaster = (_message: BushMessage, phrase): number => { +export const durationTypeCaster: BushArgumentTypeCaster = (_, phrase): number => { return client.util.parseDuration(phrase).duration; }; diff --git a/src/arguments/snowflake.ts b/src/arguments/snowflake.ts new file mode 100644 index 0000000..0e6136f --- /dev/null +++ b/src/arguments/snowflake.ts @@ -0,0 +1,8 @@ +import { Snowflake } from 'discord.js'; +import { BushArgumentTypeCaster } from '../lib'; + +export const snowflakeTypeCaster: BushArgumentTypeCaster = (_, phrase): Snowflake | null => { + if (!phrase) return null; + if (client.consts.regex.snowflake.test(phrase)) return phrase; + return null; +}; 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}.`); diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 3feae96..ee92ded 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -21,8 +21,10 @@ import { exit } from 'process'; import readline from 'readline'; import { Sequelize } from 'sequelize'; import { contentWithDurationTypeCaster } from '../../../arguments/contentWithDuration'; +import { discordEmojiTypeCaster } from '../../../arguments/discordEmoji'; import { durationTypeCaster } from '../../../arguments/duration'; import { permissionTypeCaster } from '../../../arguments/permission'; +import { snowflakeTypeCaster } from '../../../arguments/snowflake'; import { UpdateCacheTask } from '../../../tasks/updateCache'; import { ActivePunishment } from '../../models/ActivePunishment'; import { Global } from '../../models/Global'; @@ -250,7 +252,9 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re this.commandHandler.resolver.addTypes({ duration: durationTypeCaster, contentWithDuration: contentWithDurationTypeCaster, - permission: permissionTypeCaster + permission: permissionTypeCaster, + snowflake: snowflakeTypeCaster, + discordEmoji: discordEmojiTypeCaster }); // loads all the handlers const loaders = { diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index 0eaa5e0..7ecb679 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -6,7 +6,7 @@ import { BushClient } from './BushClient'; import { BushCommandHandler } from './BushCommandHandler'; import { BushSlashMessage } from './BushSlashMessage'; -export type BushArgumentType = +export type BaseBushArgumentType = | 'string' | 'lowercase' | 'uppercase' @@ -61,7 +61,12 @@ export type BushArgumentType = | 'listener' | 'duration' | 'contentWithDuration' - | 'permission'; + | 'permission' + | 'snowflake' + | 'discordEmoji'; + +export type BushArgumentType = BaseBushArgumentType | RegExp; + interface BaseBushArgumentOptions extends Omit<ArgumentOptions, 'type'> { id: string; description?: string; @@ -116,7 +121,7 @@ export interface BushArgumentOptions extends BaseBushArgumentOptions { * - `contentWithDuration` tries to parse duration in milliseconds and returns the remaining content with the duration * removed */ - type?: BushArgumentType; + type?: BushArgumentType | BaseBushArgumentType[]; } export interface CustomBushArgumentOptions extends BaseBushArgumentOptions { /** diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts index 68393c4..1d7f81e 100644 --- a/src/lib/utils/BushConstants.ts +++ b/src/lib/utils/BushConstants.ts @@ -21,6 +21,10 @@ interface bushColors { black: '#000000'; orange: '#E86100'; } + +('<:verifiedbot1:700325427998097449>'); +(''); + export class BushConstants { public static emojis = { success: '<:checkmark:837109864101707807>', @@ -99,6 +103,11 @@ export class BushConstants { } }; + public static regex = { + snowflake: /\d{15,21}/gim, + discordEmoji: /<a?:[a-zA-Z0-9_]+:\d{15,21}>/gim + }; + /** A bunch of mappings */ public static mappings = { guilds: { |