From 46bbadd71aa99bc657931971f9f5ad5659f0c17c Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Tue, 31 Aug 2021 21:17:27 -0400 Subject: refactoring and fixes --- .vscode/settings.json | 2 +- src/commands/info/snowflake.ts | 152 +++++++++++++++++++++++ src/commands/info/snowflakeInfo.ts | 152 ----------------------- src/commands/moderation/removeReactionEmoji.ts | 2 +- src/commands/moulberry-bush/moulHammerCommand.ts | 38 ++++++ src/listeners/commands/commandCooldown.ts | 27 ++++ src/listeners/commands/slashNotFound.ts | 15 +++ yarn.lock | 32 ++--- 8 files changed, 250 insertions(+), 170 deletions(-) create mode 100644 src/commands/info/snowflake.ts delete mode 100644 src/commands/info/snowflakeInfo.ts create mode 100644 src/commands/moulberry-bush/moulHammerCommand.ts create mode 100644 src/listeners/commands/commandCooldown.ts create mode 100644 src/listeners/commands/slashNotFound.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 3e23797..144c4ca 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -120,4 +120,4 @@ } ], "compile-hero.disable-compile-files-on-did-save-code": true -} +} \ No newline at end of file diff --git a/src/commands/info/snowflake.ts b/src/commands/info/snowflake.ts new file mode 100644 index 0000000..8d6129b --- /dev/null +++ b/src/commands/info/snowflake.ts @@ -0,0 +1,152 @@ +import { + CategoryChannel, + Channel, + DeconstructedSnowflake, + DMChannel, + Emoji, + Guild, + MessageEmbed, + NewsChannel, + Role, + Snowflake, + SnowflakeUtil, + StageChannel, + TextChannel, + User, + VoiceChannel +} from 'discord.js'; +import { BushCommand, BushMessage, BushSlashMessage } from '../../lib'; + +export default class SnowflakeCommand extends BushCommand { + public constructor() { + super('snowflake', { + aliases: ['snowflake', 'info', 'sf'], + category: 'info', + ratelimit: 4, + cooldown: 4000, + description: { + content: 'Provides information about the specified Snowflake.', + usage: 'snowflake ', + examples: ['snowflake 322862723090219008'] + }, + args: [ + { + id: 'snowflake', + type: 'snowflake', + prompt: { + start: 'Enter the snowflake you would like to get information about.', + retry: '{error} Choose a valid snowflake.', + optional: false + } + } + ], + clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], + slash: true, + slashOptions: [ + { + name: 'snowflake', + description: 'The snowflake you would like to get information about.', + type: 'STRING', + required: true + } + ] + }); + } + public override async exec(message: BushMessage | BushSlashMessage, args: { snowflake: Snowflake }): Promise { + const snowflake = `${args.snowflake}` as Snowflake; + const snowflakeEmbed = new MessageEmbed().setTitle('Unknown :snowflake:').setColor(util.colors.default); + + // Channel + if (client.channels.cache.has(snowflake)) { + const channel: Channel = client.channels.cache.get(snowflake)!; + const channelInfo = [`**Type:** ${channel.type}`]; + if (['dm', 'group'].includes(channel.type)) { + const _channel = channel as DMChannel; + channelInfo.push(`**Recipient:** ${_channel.recipient.tag} (${_channel.recipient.id})`); + snowflakeEmbed.setTitle(`:snowflake: DM with ${(channel as DMChannel).recipient.tag} \`[Channel]\``); + } else if ( + [ + 'GUILD_CATEGORY', + 'GUILD_NEWS', + 'GUILD_TEXT', + 'GUILD_VOICE', + 'GUILD_STORE', + 'GUILD_STAGE_VOICE', + 'GUILD_NEWS_THREAD', + 'GUILD_PUBLIC_THREAD', + 'GUILD_PRIVATE_THREAD' + ].includes(channel.type) + ) { + const _channel = channel as TextChannel | VoiceChannel | NewsChannel | StageChannel | CategoryChannel | StageChannel; + channelInfo.push( + `**Channel Name:** <#${_channel.id}> (${_channel.name})`, + `**Channel's Server:** ${_channel.guild.name} (${_channel.guild.id})` + ); + snowflakeEmbed.setTitle(`:snowflake: ${_channel.name} \`[Channel]\``); + } + snowflakeEmbed.addField('» Channel Info', channelInfo.join('\n')); + } + + // Guild + if (client.guilds.cache.has(snowflake)) { + const guild: Guild = client.guilds.cache.get(snowflake)!; + const guildInfo = [ + `**Name:** ${guild.name}`, + `**Owner:** ${client.users.cache.get(guild.ownerId)?.tag ?? '¯\\_(ツ)_/¯'} (${guild.ownerId})`, + `**Members:** ${guild.memberCount?.toLocaleString()}` + ]; + if (guild.icon) snowflakeEmbed.setThumbnail(guild.iconURL({ size: 2048, dynamic: true })!); + snowflakeEmbed.addField('» Server Info', guildInfo.join('\n')); + snowflakeEmbed.setTitle(`:snowflake: ${guild.name} \`[Server]\``); + } + + // User + const fetchedUser = await client.users.fetch(`${snowflake}`).catch(() => undefined); + if (client.users.cache.has(snowflake) || fetchedUser) { + const user: User = (client.users.cache.get(snowflake) ?? fetchedUser)!; + const userInfo = [`**Name:** <@${user.id}> (${user.tag})`]; + if (user.avatar) snowflakeEmbed.setThumbnail(user.avatarURL({ size: 2048, dynamic: true })!); + snowflakeEmbed.addField('» User Info', userInfo.join('\n')); + snowflakeEmbed.setTitle(`:snowflake: ${user.tag} \`[User]\``); + } + + // Emoji + if (client.emojis.cache.has(snowflake)) { + const emoji: Emoji = client.emojis.cache.get(snowflake)!; + const emojiInfo = [`**Name:** ${emoji.name}`, `**Animated:** ${emoji.animated}`]; + if (emoji.url) snowflakeEmbed.setThumbnail(emoji.url); + snowflakeEmbed.addField('» Emoji Info', emojiInfo.join('\n')); + snowflakeEmbed.setTitle(`:snowflake: ${emoji.name} \`[Emoji]\``); + } + + // Role + if (message.guild && message.guild.roles.cache.has(snowflake)) { + const role: Role = message.guild.roles.cache.get(snowflake)!; + const roleInfo = [ + `**Name:** <@&${role.id}> (${role.name})`, + `**Members:** ${role.members.size}`, + `**Hoisted:** ${role.hoist}`, + `**Managed:** ${role.managed}`, + `**Position:** ${role.position}`, + `**Hex Color:** ${role.hexColor}` + ]; + if (role.color) snowflakeEmbed.setColor(role.color); + snowflakeEmbed.addField('» Role Info', roleInfo.join('\n')); + snowflakeEmbed.setTitle(`:snowflake: ${role.name} \`[Role]\``); + } + + // SnowflakeInfo + const deconstructedSnowflake: DeconstructedSnowflake = SnowflakeUtil.deconstruct(snowflake); + const snowflakeInfo = [ + `**Timestamp:** ${deconstructedSnowflake.timestamp}`, + `**Created:** ${deconstructedSnowflake.date.toLocaleString()}`, + `**Worker ID:** ${deconstructedSnowflake.workerId}`, + `**Process ID:** ${deconstructedSnowflake.processId}`, + `**Increment:** ${deconstructedSnowflake.increment}` + // `**Binary:** ${deconstructedSnowflake.binary}` + ]; + snowflakeEmbed.addField('» Snowflake Info', snowflakeInfo.join('\n')); + + return await message.util.reply({ embeds: [snowflakeEmbed] }); + } +} diff --git a/src/commands/info/snowflakeInfo.ts b/src/commands/info/snowflakeInfo.ts deleted file mode 100644 index 603993a..0000000 --- a/src/commands/info/snowflakeInfo.ts +++ /dev/null @@ -1,152 +0,0 @@ -import { - CategoryChannel, - Channel, - DeconstructedSnowflake, - DMChannel, - Emoji, - Guild, - MessageEmbed, - NewsChannel, - Role, - Snowflake, - SnowflakeUtil, - StageChannel, - TextChannel, - User, - VoiceChannel -} from 'discord.js'; -import { BushCommand, BushMessage, BushSlashMessage } from '../../lib'; - -export default class SnowflakeInfoCommand extends BushCommand { - public constructor() { - super('snowflake', { - aliases: ['snowflake', 'info', 'sf'], - category: 'info', - ratelimit: 4, - cooldown: 4000, - description: { - content: 'Provides information about the specified Snowflake.', - usage: 'snowflake ', - examples: ['snowflake 322862723090219008'] - }, - args: [ - { - id: 'snowflake', - type: 'snowflake', - prompt: { - start: 'Enter the snowflake you would like to get information about.', - retry: '{error} Choose a valid snowflake.', - optional: false - } - } - ], - clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], - slash: true, - slashOptions: [ - { - name: 'snowflake', - description: 'The snowflake you would like to get information about.', - type: 'STRING', - required: true - } - ] - }); - } - public override async exec(message: BushMessage | BushSlashMessage, args: { snowflake: Snowflake }): Promise { - const snowflake = `${args.snowflake}` as Snowflake; - const snowflakeEmbed = new MessageEmbed().setTitle('Unknown :snowflake:').setColor(util.colors.default); - - // Channel - if (client.channels.cache.has(snowflake)) { - const channel: Channel = client.channels.cache.get(snowflake)!; - const channelInfo = [`**Type:** ${channel.type}`]; - if (['dm', 'group'].includes(channel.type)) { - const _channel = channel as DMChannel; - channelInfo.push(`**Recipient:** ${_channel.recipient.tag} (${_channel.recipient.id})`); - snowflakeEmbed.setTitle(`:snowflake: DM with ${(channel as DMChannel).recipient.tag} \`[Channel]\``); - } else if ( - [ - 'GUILD_CATEGORY', - 'GUILD_NEWS', - 'GUILD_TEXT', - 'GUILD_VOICE', - 'GUILD_STORE', - 'GUILD_STAGE_VOICE', - 'GUILD_NEWS_THREAD', - 'GUILD_PUBLIC_THREAD', - 'GUILD_PRIVATE_THREAD' - ].includes(channel.type) - ) { - const _channel = channel as TextChannel | VoiceChannel | NewsChannel | StageChannel | CategoryChannel | StageChannel; - channelInfo.push( - `**Channel Name:** <#${_channel.id}> (${_channel.name})`, - `**Channel's Server:** ${_channel.guild.name} (${_channel.guild.id})` - ); - snowflakeEmbed.setTitle(`:snowflake: ${_channel.name} \`[Channel]\``); - } - snowflakeEmbed.addField('» Channel Info', channelInfo.join('\n')); - } - - // Guild - if (client.guilds.cache.has(snowflake)) { - const guild: Guild = client.guilds.cache.get(snowflake)!; - const guildInfo = [ - `**Name:** ${guild.name}`, - `**Owner:** ${client.users.cache.get(guild.ownerId)?.tag ?? '¯\\_(ツ)_/¯'} (${guild.ownerId})`, - `**Members:** ${guild.memberCount?.toLocaleString()}` - ]; - if (guild.icon) snowflakeEmbed.setThumbnail(guild.iconURL({ size: 2048, dynamic: true })!); - snowflakeEmbed.addField('» Server Info', guildInfo.join('\n')); - snowflakeEmbed.setTitle(`:snowflake: ${guild.name} \`[Server]\``); - } - - // User - const fetchedUser = await client.users.fetch(`${snowflake}`).catch(() => undefined); - if (client.users.cache.has(snowflake) || fetchedUser) { - const user: User = (client.users.cache.get(snowflake) ?? fetchedUser)!; - const userInfo = [`**Name:** <@${user.id}> (${user.tag})`]; - if (user.avatar) snowflakeEmbed.setThumbnail(user.avatarURL({ size: 2048, dynamic: true })!); - snowflakeEmbed.addField('» User Info', userInfo.join('\n')); - snowflakeEmbed.setTitle(`:snowflake: ${user.tag} \`[User]\``); - } - - // Emoji - if (client.emojis.cache.has(snowflake)) { - const emoji: Emoji = client.emojis.cache.get(snowflake)!; - const emojiInfo = [`**Name:** ${emoji.name}`, `**Animated:** ${emoji.animated}`]; - if (emoji.url) snowflakeEmbed.setThumbnail(emoji.url); - snowflakeEmbed.addField('» Emoji Info', emojiInfo.join('\n')); - snowflakeEmbed.setTitle(`:snowflake: ${emoji.name} \`[Emoji]\``); - } - - // Role - if (message.guild && message.guild.roles.cache.has(snowflake)) { - const role: Role = message.guild.roles.cache.get(snowflake)!; - const roleInfo = [ - `**Name:** <@&${role.id}> (${role.name})`, - `**Members:** ${role.members.size}`, - `**Hoisted:** ${role.hoist}`, - `**Managed:** ${role.managed}`, - `**Position:** ${role.position}`, - `**Hex Color:** ${role.hexColor}` - ]; - if (role.color) snowflakeEmbed.setColor(role.color); - snowflakeEmbed.addField('» Role Info', roleInfo.join('\n')); - snowflakeEmbed.setTitle(`:snowflake: ${role.name} \`[Role]\``); - } - - // SnowflakeInfo - const deconstructedSnowflake: DeconstructedSnowflake = SnowflakeUtil.deconstruct(snowflake); - const snowflakeInfo = [ - `**Timestamp:** ${deconstructedSnowflake.timestamp}`, - `**Created:** ${deconstructedSnowflake.date.toLocaleString()}`, - `**Worker ID:** ${deconstructedSnowflake.workerId}`, - `**Process ID:** ${deconstructedSnowflake.processId}`, - `**Increment:** ${deconstructedSnowflake.increment}` - // `**Binary:** ${deconstructedSnowflake.binary}` - ]; - snowflakeEmbed.addField('» Snowflake Info', snowflakeInfo.join('\n')); - - return await message.util.reply({ embeds: [snowflakeEmbed] }); - } -} diff --git a/src/commands/moderation/removeReactionEmoji.ts b/src/commands/moderation/removeReactionEmoji.ts index 34073e6..d4c0cb6 100644 --- a/src/commands/moderation/removeReactionEmoji.ts +++ b/src/commands/moderation/removeReactionEmoji.ts @@ -3,7 +3,7 @@ import { Emoji, Snowflake } from 'discord.js'; export default class RemoveReactionEmojiCommand extends BushCommand { public constructor() { - super('removereactionemoji', { + super('removeReactionEmoji', { aliases: ['removereactionemoji', 'rre'], category: 'moderation', description: { diff --git a/src/commands/moulberry-bush/moulHammerCommand.ts b/src/commands/moulberry-bush/moulHammerCommand.ts new file mode 100644 index 0000000..bc60372 --- /dev/null +++ b/src/commands/moulberry-bush/moulHammerCommand.ts @@ -0,0 +1,38 @@ +import { MessageEmbed, User } from 'discord.js'; +import { BushCommand, BushMessage } from '../../lib'; + +export default class MoulHammerCommand extends BushCommand { + public constructor() { + super('moulHammer', { + aliases: ['moulhammer'], + category: "Moulberry's Bush", + description: { + content: 'A command to moul hammer members.', + usage: 'moulHammer ', + examples: ['moulHammer @IRONM00N'] + }, + clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES'], + args: [ + { + id: 'user', + type: 'user', + prompt: { + start: 'What user would you like to moul hammer?', + retry: '{error} Choose a valid user to moul hammer' + } + } + ], + restrictedGuilds: ['516977525906341928'] + }); + } + + public override async exec(message: BushMessage, { user }: { user: User }): Promise { + await message.delete(); + const embed = new MessageEmbed() + .setTitle('L') + .setDescription(`${user.username} got moul'ed <:wideberry1:756223352598691942><:wideberry2:756223336832303154>`) + .setColor(this.client.util.colors.purple); + await message.util.send({ embeds: [embed] }); + } +} diff --git a/src/listeners/commands/commandCooldown.ts b/src/listeners/commands/commandCooldown.ts new file mode 100644 index 0000000..5cb3fa9 --- /dev/null +++ b/src/listeners/commands/commandCooldown.ts @@ -0,0 +1,27 @@ +import { Message } from 'discord.js'; +import { BushCommandHandlerEvents, BushListener } from '../../lib'; + +export default class CommandCooldownListener extends BushListener { + public constructor() { + super('commandCooldown', { + emitter: 'commandHandler', + event: 'cooldown', + category: 'commands' + }); + } + + public override async exec(...[message, command, remaining]: BushCommandHandlerEvents['cooldown']): Promise { + void client.console.info( + 'commandCooldown', + `<<${message.author.tag}>> tried to run <<${ + command ?? message.util!.parsed?.command + }>> but it is on cooldown for <<${Math.round(remaining / 1000)}>> seconds.` + ); + message.util!.isSlash + ? message.util?.reply({ + content: `⏳ This command is on cooldown for ${Math.round(remaining / 1000)} seconds.`, + ephemeral: true + }) + : await (message as Message).react('⏳').catch(() => null); + } +} diff --git a/src/listeners/commands/slashNotFound.ts b/src/listeners/commands/slashNotFound.ts new file mode 100644 index 0000000..118d549 --- /dev/null +++ b/src/listeners/commands/slashNotFound.ts @@ -0,0 +1,15 @@ +import { BushCommandHandlerEvents, BushListener } from '../../lib'; + +export default class SlashNotFoundListener extends BushListener { + public constructor() { + super('slashNotFound', { + emitter: 'commandHandler', + event: 'slashNotFound', + category: 'commands' + }); + } + + public override async exec(...[interaction]: BushCommandHandlerEvents['slashNotFound']): Promise { + void client.console.info('slashNotFound', `<<${interaction?.commandName}>> could not be found.`); + } +} diff --git a/yarn.lock b/yarn.lock index 061b369..0b76ce8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -359,16 +359,16 @@ __metadata: linkType: hard "@types/node@npm:*": - version: 16.7.8 - resolution: "@types/node@npm:16.7.8" - checksum: 060ea222ce8f3eb05bd86a7785ca5807503a50602dd805c5be997a5ae684fa6224c9ad8890bcc5551c05d14a8bcd735f94567691342d197f5f7f7f893ed0d46b + version: 16.7.10 + resolution: "@types/node@npm:16.7.10" + checksum: 0518803caa1a14f4070e770a280eda1c4b4581a425cbda481cdd54b1f34a7ea497ff067fd23b90e3d4f4fdcfba15c1316182875e9cf9f5b2e880de1e595de053 languageName: node linkType: hard "@types/node@npm:^14.14.22": - version: 14.17.12 - resolution: "@types/node@npm:14.17.12" - checksum: 7efbce3781a0ea5d7a39bca3c5ed9c4e4d99fed3483fb2a89670aeb049cd9d25f1ddecd8fb58420fd92de371278721ddd6e3ad95c4f55992592f1ac5d1dedf98 + version: 14.17.14 + resolution: "@types/node@npm:14.17.14" + checksum: 66ed675a324fdddc4f693f1b240c0d81a9f53e1c68f7de8b84d02d65c0b447f9fa30d318481d04e1502f68dd37091b5cadc59633b57246582ad25e3fa835cd7d languageName: node linkType: hard @@ -1001,9 +1001,9 @@ __metadata: linkType: hard "core-util-is@npm:~1.0.0": - version: 1.0.2 - resolution: "core-util-is@npm:1.0.2" - checksum: 7a4c925b497a2c91421e25bf76d6d8190f0b2359a9200dbeed136e63b2931d6294d3b1893eda378883ed363cd950f44a12a401384c609839ea616befb7927dab + version: 1.0.3 + resolution: "core-util-is@npm:1.0.3" + checksum: 9de8597363a8e9b9952491ebe18167e3b36e7707569eed0ebf14f8bba773611376466ae34575bca8cfe3c767890c859c74056084738f09d4e4a6f902b2ad7d99 languageName: node linkType: hard @@ -1117,12 +1117,12 @@ discord-akairo-message-util@NotEnoughUpdates/discord-akairo-message-util: discord-akairo@NotEnoughUpdates/discord-akairo: version: 8.2.2 - resolution: "discord-akairo@https://github.com/NotEnoughUpdates/discord-akairo.git#commit=8da50867c05265aa01fbc08fd510af4c81f64651" + resolution: "discord-akairo@https://github.com/NotEnoughUpdates/discord-akairo.git#commit=11b02374dfe1f2f9c0487f2bb8e4f9fbf7c148a4" dependencies: discord-akairo-message-util: NotEnoughUpdates/discord-akairo-message-util lodash: ^4.17.21 source-map-support: ^0.5.19 - checksum: c96a613e59726a25a65c8a15e24850447d1c43da7ab52e4a88c1eee55b3a981a98a41f2c41e6e3fad7a3865566f4345f92211d6d4b4198059e88fe9e2c247203 + checksum: 2edc0da34e5d8804ea92a6f2a0bd566738ae931ef3583bb475204bba1e6a218ec72b27d144c2f7132963504748d2679c39d9deff0f0005dace946cc9473d83bb languageName: node linkType: hard @@ -1142,7 +1142,7 @@ discord-akairo@NotEnoughUpdates/discord-akairo: discord.js@NotEnoughUpdates/discord.js: version: 13.2.0-dev - resolution: "discord.js@https://github.com/NotEnoughUpdates/discord.js.git#commit=adfd990b6de491c01adb414b231a7a5f3c62042e" + resolution: "discord.js@https://github.com/NotEnoughUpdates/discord.js.git#commit=b3c676e3286dd3ce39f63231216d2e480e28b567" dependencies: "@discordjs/builders": ^0.5.0 "@discordjs/collection": ^0.2.1 @@ -1152,7 +1152,7 @@ discord.js@NotEnoughUpdates/discord.js: discord-api-types: ^0.22.0 node-fetch: ^2.6.1 ws: ^7.5.1 - checksum: 5bb831df1083ed06ce59fd1500158981f6697d15194b46840d133e1ee32659291c497bb7bddcdabe1f0ce9cf5129febd07f2956039f842e21efa7a8c7bba25e4 + checksum: 730499fb8c30f648343abdda44d12767819da80a55deb9358942ef9a63280fe354c2b2a638cef9bd5ac946e5efc2f87f29b3a03e6f43d150a3618b252aef445e languageName: node linkType: hard @@ -2154,8 +2154,8 @@ discord.js@NotEnoughUpdates/discord.js: linkType: hard "minipass-fetch@npm:^1.3.2": - version: 1.3.4 - resolution: "minipass-fetch@npm:1.3.4" + version: 1.4.1 + resolution: "minipass-fetch@npm:1.4.1" dependencies: encoding: ^0.1.12 minipass: ^3.1.0 @@ -2164,7 +2164,7 @@ discord.js@NotEnoughUpdates/discord.js: dependenciesMeta: encoding: optional: true - checksum: 67cb59d30ba646d652a250e08833bb54463ef1fead6eea5b835a53e3f6b32410356b81948ba7be7634cbb1ab37ba497d3e1ddf203b9f0d0d7637728075f67124 + checksum: ec93697bdb62129c4e6c0104138e681e30efef8c15d9429dd172f776f83898471bc76521b539ff913248cc2aa6d2b37b652c993504a51cc53282563640f29216 languageName: node linkType: hard -- cgit