From b29a217f76483e000bd9d75d30250d11a0a88c4d Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 19 Aug 2021 12:03:21 -0400 Subject: added steal command, revamped error handling and other stuff --- src/commands/info/invite.ts | 34 ---------------------------- src/commands/info/links.ts | 45 ++++++++++++++++++++++++++++++++++++++ src/commands/info/pronouns.ts | 14 +++++++++--- src/commands/info/snowflakeInfo.ts | 11 +++++----- src/commands/info/userInfo.ts | 19 +++++++++++++++- 5 files changed, 80 insertions(+), 43 deletions(-) delete mode 100644 src/commands/info/invite.ts create mode 100644 src/commands/info/links.ts (limited to 'src/commands/info') diff --git a/src/commands/info/invite.ts b/src/commands/info/invite.ts deleted file mode 100644 index 615e767..0000000 --- a/src/commands/info/invite.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; -import { MessageActionRow, MessageButton } from 'discord.js'; - -export default class InviteCommand extends BushCommand { - public constructor() { - super('invite', { - aliases: ['invite'], - category: 'info', - description: { - content: 'Sends the bot invite link.', - usage: 'invite', - examples: ['invite'] - }, - ratelimit: 4, - cooldown: 4000, - clientPermissions: ['SEND_MESSAGES'], - slash: true - }); - } - - public override async exec(message: BushMessage | BushSlashMessage): Promise { - if (client.config.isDevelopment) return await message.util.reply(`${util.emojis.error} The dev bot cannot be invited.`); - const ButtonRow = new MessageActionRow().addComponents( - new MessageButton({ - style: 'LINK', - label: 'Invite Me', - url: `https://discord.com/api/oauth2/authorize?client_id=${ - client.user!.id - }&permissions=2147483647&scope=bot%20applications.commands` - }) - ); - return await message.util.reply({ content: 'You can invite me here:', components: [ButtonRow] }); - } -} diff --git a/src/commands/info/links.ts b/src/commands/info/links.ts new file mode 100644 index 0000000..29152d9 --- /dev/null +++ b/src/commands/info/links.ts @@ -0,0 +1,45 @@ +import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; +import { MessageActionRow, MessageButton } from 'discord.js'; +import packageDotJSON from '../../../package.json'; + +export default class LinksCommand extends BushCommand { + public constructor() { + super('links', { + aliases: ['links', 'invite', 'support'], + category: 'info', + description: { + content: 'Sends bot links', + usage: 'links', + examples: ['links'] + }, + ratelimit: 4, + cooldown: 4000, + clientPermissions: ['SEND_MESSAGES'], + slash: true + }); + } + + public override async exec(message: BushMessage | BushSlashMessage): Promise { + if (client.config.isDevelopment) return await message.util.reply(`${util.emojis.error} The dev bot cannot be invited.`); + const ButtonRow = new MessageActionRow().addComponents( + new MessageButton({ + style: 'LINK', + label: 'Invite Me', + url: `https://discord.com/api/oauth2/authorize?client_id=${ + client.user!.id + }&permissions=2147483647&scope=bot%20applications.commands` + }), + new MessageButton({ + style: 'LINK', + label: 'Support Server', + url: client.config.supportGuild.invite + }), + new MessageButton({ + style: 'LINK', + label: 'GitHub', + url: packageDotJSON.repository + }) + ); + return await message.util.reply({ content: '\u200B', components: [ButtonRow] }); + } +} diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index c7eac7f..96040c0 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -40,7 +40,7 @@ export default class PronounsCommand extends BushCommand { args: [ { id: 'user', - type: 'user', + customType: util.arg.union('user', 'bigint'), prompt: { start: 'Who would you like to view the pronouns of?', retry: '{error} Choose a valid user to view the pronouns of.', @@ -60,8 +60,16 @@ export default class PronounsCommand extends BushCommand { slash: true }); } - override async exec(message: BushMessage | BushSlashMessage, args: { user?: User }): Promise { - const user = args.user ?? message.author; + override async exec(message: BushMessage | BushSlashMessage, args: { user?: User | string }): Promise { + const user = + args?.user === undefined || args?.user === null + ? message.author + : typeof args.user === 'object' + ? args.user + : await client.users.fetch(`${args.user}`).catch(() => undefined); + + if (user === undefined) return message.util.reply(`${util.emojis.error} Invalid user.`); + const author = user.id === message.author.id; try { const apiRes: { pronouns: pronounsType } = await got diff --git a/src/commands/info/snowflakeInfo.ts b/src/commands/info/snowflakeInfo.ts index c4d71da..02c8d39 100644 --- a/src/commands/info/snowflakeInfo.ts +++ b/src/commands/info/snowflakeInfo.ts @@ -88,7 +88,7 @@ export default class SnowflakeInfoCommand extends BushCommand { } // Guild - else if (client.guilds.cache.has(snowflake)) { + if (client.guilds.cache.has(snowflake)) { const guild: Guild = client.guilds.cache.get(snowflake)!; const guildInfo = [ `**Name:** ${guild.name}`, @@ -101,8 +101,9 @@ export default class SnowflakeInfoCommand extends BushCommand { } // User - else if (client.users.cache.has(snowflake)) { - const user: User = client.users.cache.get(snowflake)!; + 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')); @@ -110,7 +111,7 @@ export default class SnowflakeInfoCommand extends BushCommand { } // Emoji - else if (client.emojis.cache.has(snowflake)) { + 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); @@ -119,7 +120,7 @@ export default class SnowflakeInfoCommand extends BushCommand { } // Role - else if (message.guild && message.guild.roles.cache.has(snowflake)) { + 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})`, diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 9ec5552..7b8d7d8 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -1,7 +1,6 @@ import { BushCommand, BushMessage, BushSlashMessage, BushUser } from '@lib'; import { MessageEmbed } from 'discord.js'; -// TODO: Re-Implement Status Emojis // TODO: Add bot information export default class UserInfoCommand extends BushCommand { public constructor() { @@ -141,6 +140,24 @@ export default class UserInfoCommand extends BushCommand { presenceInfo.push(`**Activit${activitiesNames.length - 1 ? 'ies' : 'y'}:** ${util.oxford(activitiesNames, 'and', '')}`); if (customStatus && customStatus.length) presenceInfo.push(`**Custom Status:** ${customStatus}`); userEmbed.addField('» Presence', presenceInfo.join('\n')); + + enum statusEmojis { + online = '787550449435803658', + idle = '787550520956551218', + dnd = '787550487633330176', + offline = '787550565382750239', + invisible = '787550565382750239' + } + userEmbed.setFooter(user.tag, client.emojis.cache.get(statusEmojis[member?.presence.status])?.url ?? undefined); + } + + // roles + if (member?.roles.cache.size && member?.roles.cache.size - 1) { + const roles = member?.roles.cache + .filter((role) => role.name !== '@everyone') + .sort((role1, role2) => role2.position - role1.position) + .map((role) => `${role}`); + userEmbed.addField(`» Role${roles.length - 1 ? 's' : ''} [${roles.length}]`, roles.join(', ')); } // Important Perms -- cgit