From 1546da359646b89f13d17784eb7653a52ca61efd Mon Sep 17 00:00:00 2001 From: TymanWasTaken Date: Thu, 27 May 2021 14:58:21 -0600 Subject: Fix file naming --- src/commands/info/botInfo.ts | 66 +++++++++++++++++++ src/commands/info/botInfoCommand.ts | 66 ------------------- src/commands/info/help.ts | 108 +++++++++++++++++++++++++++++++ src/commands/info/helpCommand.ts | 108 ------------------------------- src/commands/info/ping.ts | 69 ++++++++++++++++++++ src/commands/info/pingCommand.ts | 69 -------------------- src/commands/info/pronouns.ts | 121 +++++++++++++++++++++++++++++++++++ src/commands/info/pronounsCommand.ts | 121 ----------------------------------- 8 files changed, 364 insertions(+), 364 deletions(-) create mode 100644 src/commands/info/botInfo.ts delete mode 100644 src/commands/info/botInfoCommand.ts create mode 100644 src/commands/info/help.ts delete mode 100644 src/commands/info/helpCommand.ts create mode 100644 src/commands/info/ping.ts delete mode 100644 src/commands/info/pingCommand.ts create mode 100644 src/commands/info/pronouns.ts delete mode 100644 src/commands/info/pronounsCommand.ts (limited to 'src/commands/info') diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts new file mode 100644 index 0000000..779b318 --- /dev/null +++ b/src/commands/info/botInfo.ts @@ -0,0 +1,66 @@ +import { MessageEmbed, Message, CommandInteraction } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { duration } from 'moment'; + +export default class BotInfoCommand extends BushCommand { + constructor() { + super('botinfo', { + aliases: ['botinfo'], + category: 'info', + description: { + content: 'Shows information about the bot', + usage: 'botinfo', + examples: ['botinfo'] + } + }); + } + + private async generateEmbed(): Promise { + const owners = (await this.client.util.mapIDs(this.client.ownerID)) + .map((u) => u.tag) + .join('\n'); + const currentCommit = ( + await this.client.util.shell('git rev-parse HEAD') + ).stdout.replace('\n', ''); + const repoUrl = ( + await this.client.util.shell('git remote get-url origin') + ).stdout.replace('\n', ''); + const embed = new MessageEmbed() + .setTitle('Bot Info:') + .addFields([ + { + name: 'Owners', + value: owners, + inline: true + }, + { + name: 'Uptime', + value: this.client.util.capitalize( + duration(this.client.uptime, 'milliseconds').humanize() + ) + }, + { + name: 'User count', + value: this.client.users.cache.size, + inline: true + }, + { + name: 'Current commit', + value: `[${currentCommit.substring( + 0, + 7 + )}](${repoUrl}/commit/${currentCommit})` + } + ]) + .setTimestamp(); + return embed; + } + + public async exec(message: Message): Promise { + await message.util.send(await this.generateEmbed()); + } + + public async execSlash(message: CommandInteraction): Promise { + await message.reply(await this.generateEmbed()); + } +} diff --git a/src/commands/info/botInfoCommand.ts b/src/commands/info/botInfoCommand.ts deleted file mode 100644 index 779b318..0000000 --- a/src/commands/info/botInfoCommand.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { MessageEmbed, Message, CommandInteraction } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { duration } from 'moment'; - -export default class BotInfoCommand extends BushCommand { - constructor() { - super('botinfo', { - aliases: ['botinfo'], - category: 'info', - description: { - content: 'Shows information about the bot', - usage: 'botinfo', - examples: ['botinfo'] - } - }); - } - - private async generateEmbed(): Promise { - const owners = (await this.client.util.mapIDs(this.client.ownerID)) - .map((u) => u.tag) - .join('\n'); - const currentCommit = ( - await this.client.util.shell('git rev-parse HEAD') - ).stdout.replace('\n', ''); - const repoUrl = ( - await this.client.util.shell('git remote get-url origin') - ).stdout.replace('\n', ''); - const embed = new MessageEmbed() - .setTitle('Bot Info:') - .addFields([ - { - name: 'Owners', - value: owners, - inline: true - }, - { - name: 'Uptime', - value: this.client.util.capitalize( - duration(this.client.uptime, 'milliseconds').humanize() - ) - }, - { - name: 'User count', - value: this.client.users.cache.size, - inline: true - }, - { - name: 'Current commit', - value: `[${currentCommit.substring( - 0, - 7 - )}](${repoUrl}/commit/${currentCommit})` - } - ]) - .setTimestamp(); - return embed; - } - - public async exec(message: Message): Promise { - await message.util.send(await this.generateEmbed()); - } - - public async execSlash(message: CommandInteraction): Promise { - await message.reply(await this.generateEmbed()); - } -} diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts new file mode 100644 index 0000000..3b5e538 --- /dev/null +++ b/src/commands/info/help.ts @@ -0,0 +1,108 @@ +import { Message, MessageEmbed } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { stripIndent } from 'common-tags'; +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction } from 'discord.js'; +import { SlashCommandOption } from '../../lib/extensions/Util'; + +export default class HelpCommand extends BushCommand { + constructor() { + super('help', { + aliases: ['help'], + category: 'info', + description: { + content: 'Shows the commands of the bot', + usage: 'help', + examples: ['help'] + }, + clientPermissions: ['EMBED_LINKS'], + args: [ + { + id: 'command', + type: 'commandAlias' + } + ], + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.STRING, + name: 'command', + description: 'The command to get help for', + required: false + } + ] + }); + } + + private generateEmbed(command?: BushCommand): MessageEmbed { + const prefix = this.handler.prefix; + if (!command) { + const embed = new MessageEmbed() + .addField( + 'Commands', + stripIndent`A list of available commands. + For additional info on a command, type \`${prefix}help \` + ` + ) + .setFooter( + `For more information about a command use "${this.client.config.prefix}help "` + ) + .setTimestamp(); + for (const category of this.handler.categories.values()) { + embed.addField( + `${category.id.replace(/(\b\w)/gi, (lc): string => + lc.toUpperCase() + )}`, + `${category + .filter((cmd): boolean => cmd.aliases.length > 0) + .map((cmd): string => `\`${cmd.aliases[0]}\``) + .join(' ')}` + ); + } + return embed; + } else { + const embed = new MessageEmbed() + .setColor([155, 200, 200]) + .setTitle( + `\`${command.description.usage ? command.description.usage : ''}\`` + ) + .addField( + 'Description', + `${command.description.content ? command.description.content : ''} ${ + command.ownerOnly ? '\n__Owner Only__' : '' + }` + ); + + if (command.aliases.length > 1) + embed.addField('Aliases', `\`${command.aliases.join('` `')}\``, true); + if (command.description.examples && command.description.examples.length) + embed.addField( + 'Examples', + `\`${command.description.examples.join('`\n`')}\``, + true + ); + return embed; + } + } + + public async exec( + message: Message, + { command }: { command: BushCommand } + ): Promise { + await message.util.send(this.generateEmbed(command)); + } + + public async execSlash( + message: CommandInteraction, + { command }: { command: SlashCommandOption } + ): Promise { + if (command) { + await message.reply( + this.generateEmbed( + this.handler.findCommand(command.value) as BushCommand + ) + ); + } else { + await message.reply(this.generateEmbed()); + } + } +} diff --git a/src/commands/info/helpCommand.ts b/src/commands/info/helpCommand.ts deleted file mode 100644 index 3b5e538..0000000 --- a/src/commands/info/helpCommand.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { Message, MessageEmbed } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { stripIndent } from 'common-tags'; -import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction } from 'discord.js'; -import { SlashCommandOption } from '../../lib/extensions/Util'; - -export default class HelpCommand extends BushCommand { - constructor() { - super('help', { - aliases: ['help'], - category: 'info', - description: { - content: 'Shows the commands of the bot', - usage: 'help', - examples: ['help'] - }, - clientPermissions: ['EMBED_LINKS'], - args: [ - { - id: 'command', - type: 'commandAlias' - } - ], - slashCommandOptions: [ - { - type: ApplicationCommandOptionType.STRING, - name: 'command', - description: 'The command to get help for', - required: false - } - ] - }); - } - - private generateEmbed(command?: BushCommand): MessageEmbed { - const prefix = this.handler.prefix; - if (!command) { - const embed = new MessageEmbed() - .addField( - 'Commands', - stripIndent`A list of available commands. - For additional info on a command, type \`${prefix}help \` - ` - ) - .setFooter( - `For more information about a command use "${this.client.config.prefix}help "` - ) - .setTimestamp(); - for (const category of this.handler.categories.values()) { - embed.addField( - `${category.id.replace(/(\b\w)/gi, (lc): string => - lc.toUpperCase() - )}`, - `${category - .filter((cmd): boolean => cmd.aliases.length > 0) - .map((cmd): string => `\`${cmd.aliases[0]}\``) - .join(' ')}` - ); - } - return embed; - } else { - const embed = new MessageEmbed() - .setColor([155, 200, 200]) - .setTitle( - `\`${command.description.usage ? command.description.usage : ''}\`` - ) - .addField( - 'Description', - `${command.description.content ? command.description.content : ''} ${ - command.ownerOnly ? '\n__Owner Only__' : '' - }` - ); - - if (command.aliases.length > 1) - embed.addField('Aliases', `\`${command.aliases.join('` `')}\``, true); - if (command.description.examples && command.description.examples.length) - embed.addField( - 'Examples', - `\`${command.description.examples.join('`\n`')}\``, - true - ); - return embed; - } - } - - public async exec( - message: Message, - { command }: { command: BushCommand } - ): Promise { - await message.util.send(this.generateEmbed(command)); - } - - public async execSlash( - message: CommandInteraction, - { command }: { command: SlashCommandOption } - ): Promise { - if (command) { - await message.reply( - this.generateEmbed( - this.handler.findCommand(command.value) as BushCommand - ) - ); - } else { - await message.reply(this.generateEmbed()); - } - } -} diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts new file mode 100644 index 0000000..e0bbfc7 --- /dev/null +++ b/src/commands/info/ping.ts @@ -0,0 +1,69 @@ +import { CommandInteraction } from 'discord.js'; +import { Message } from 'discord.js'; +import { MessageEmbed } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; + +export default class PingCommand extends BushCommand { + constructor() { + super('ping', { + aliases: ['ping'], + category: 'info', + description: { + content: 'Gets the latency of the bot', + usage: 'ping', + examples: ['ping'] + } + }); + } + + public async exec(message: Message): Promise { + const sentMessage = await message.util.send('Pong!'); + const timestamp: number = message.editedTimestamp + ? message.editedTimestamp + : message.createdTimestamp; + const botLatency = `\`\`\`\n ${Math.floor( + sentMessage.createdTimestamp - timestamp + )}ms \`\`\``; + const apiLatency = `\`\`\`\n ${Math.round( + message.client.ws.ping + )}ms \`\`\``; + const embed = new MessageEmbed() + .setTitle('Pong! 🏓') + .addField('Bot Latency', botLatency, true) + .addField('API Latency', apiLatency, true) + .setFooter( + message.author.username, + message.author.displayAvatarURL({ dynamic: true }) + ) + .setTimestamp(); + await sentMessage.edit({ + content: null, + embed + }); + } + + public async execSlash(message: CommandInteraction): Promise { + const timestamp1 = message.createdTimestamp; + await message.reply('Pong!'); + const timestamp2 = await message + .fetchReply() + .then((m) => (m as Message).createdTimestamp); + const botLatency = `\`\`\`\n ${Math.floor( + timestamp2 - timestamp1 + )}ms \`\`\``; + const apiLatency = `\`\`\`\n ${Math.round(this.client.ws.ping)}ms \`\`\``; + const embed = new MessageEmbed() + .setTitle('Pong! 🏓') + .addField('Bot Latency', botLatency, true) + .addField('API Latency', apiLatency, true) + .setFooter( + message.user.username, + message.user.displayAvatarURL({ dynamic: true }) + ) + .setTimestamp(); + await message.editReply({ + content: null, + embeds: [embed] + }); + } +} diff --git a/src/commands/info/pingCommand.ts b/src/commands/info/pingCommand.ts deleted file mode 100644 index e0bbfc7..0000000 --- a/src/commands/info/pingCommand.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { CommandInteraction } from 'discord.js'; -import { Message } from 'discord.js'; -import { MessageEmbed } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; - -export default class PingCommand extends BushCommand { - constructor() { - super('ping', { - aliases: ['ping'], - category: 'info', - description: { - content: 'Gets the latency of the bot', - usage: 'ping', - examples: ['ping'] - } - }); - } - - public async exec(message: Message): Promise { - const sentMessage = await message.util.send('Pong!'); - const timestamp: number = message.editedTimestamp - ? message.editedTimestamp - : message.createdTimestamp; - const botLatency = `\`\`\`\n ${Math.floor( - sentMessage.createdTimestamp - timestamp - )}ms \`\`\``; - const apiLatency = `\`\`\`\n ${Math.round( - message.client.ws.ping - )}ms \`\`\``; - const embed = new MessageEmbed() - .setTitle('Pong! 🏓') - .addField('Bot Latency', botLatency, true) - .addField('API Latency', apiLatency, true) - .setFooter( - message.author.username, - message.author.displayAvatarURL({ dynamic: true }) - ) - .setTimestamp(); - await sentMessage.edit({ - content: null, - embed - }); - } - - public async execSlash(message: CommandInteraction): Promise { - const timestamp1 = message.createdTimestamp; - await message.reply('Pong!'); - const timestamp2 = await message - .fetchReply() - .then((m) => (m as Message).createdTimestamp); - const botLatency = `\`\`\`\n ${Math.floor( - timestamp2 - timestamp1 - )}ms \`\`\``; - const apiLatency = `\`\`\`\n ${Math.round(this.client.ws.ping)}ms \`\`\``; - const embed = new MessageEmbed() - .setTitle('Pong! 🏓') - .addField('Bot Latency', botLatency, true) - .addField('API Latency', apiLatency, true) - .setFooter( - message.user.username, - message.user.displayAvatarURL({ dynamic: true }) - ) - .setTimestamp(); - await message.editReply({ - content: null, - embeds: [embed] - }); - } -} diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts new file mode 100644 index 0000000..2c1d5f2 --- /dev/null +++ b/src/commands/info/pronouns.ts @@ -0,0 +1,121 @@ +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { User, Message, MessageEmbed } from 'discord.js'; +import got, { HTTPError } from 'got'; +import { CommandInteraction } from 'discord.js'; +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { SlashCommandOption } from '../../lib/extensions/Util'; + +export const pronounMapping = { + unspecified: 'Unspecified', + hh: 'He/Him', + hi: 'He/It', + hs: 'He/She', + ht: 'He/They', + ih: 'It/Him', + ii: 'It/Its', + is: 'It/She', + it: 'It/They', + shh: 'She/He', + sh: 'She/Her', + si: 'She/It', + st: 'She/They', + th: 'They/He', + ti: 'They/It', + ts: 'They/She', + tt: 'They/Them', + any: 'Any pronouns', + other: 'Other pronouns', + ask: 'Ask me my pronouns', + avoid: 'Avoid pronouns, use my name' +}; +export type pronounsType = keyof typeof pronounMapping; + +export default class PronounsCommand extends BushCommand { + constructor() { + super('pronouns', { + aliases: ['pronouns', 'pronoun'], + category: 'info', + description: { + usage: 'pronouns ', + examples: ['pronouns IRONM00N'], + content: 'Finds the pronouns of a user using https://pronoundb.org.' + }, + args: [ + { + id: 'user', + type: 'user', + default: null + } + ], + clientPermissions: ['SEND_MESSAGES'], + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.USER, + name: 'user', + description: 'The user to get pronouns for', + required: false + } + ], + slashEmphemeral: true // I'll add dynamic checking to this later + }); + } + async sendResponse( + message: Message | CommandInteraction, + user: User, + author: boolean + ): Promise { + try { + const apiRes: { pronouns: pronounsType } = await got + .get( + `https://pronoundb.org/api/v1/lookup?platform=discord&id=${user.id}` + ) + .json(); + if (message instanceof Message) { + message.reply( + new MessageEmbed({ + title: `${author ? 'Your' : `${user.tag}'s`} pronouns:`, + description: pronounMapping[apiRes.pronouns], + footer: { + text: 'Data provided by https://pronoundb.org/' + } + }) + ); + } else { + message.reply({ + embeds: [ + new MessageEmbed({ + title: `${author ? 'Your' : `${user.tag}'s`} pronouns:`, + description: pronounMapping[apiRes.pronouns], + footer: { + text: 'Data provided by https://pronoundb.org/' + } + }) + ] + }); + } + } catch (e) { + if (e instanceof HTTPError && e.response.statusCode === 404) { + if (author) { + await message.reply( + 'You do not appear to have any pronouns set. Please go to https://pronoundb.org/ and set your pronouns.' + ); + } else { + await message.reply( + `${user.tag} does not appear to have any pronouns set. Please tell them to go to https://pronoundb.org/ and set their pronouns.` + ); + } + } else throw e; + } + } + async exec(message: Message, { user }: { user?: User }): Promise { + const u = user || message.author; + await this.sendResponse(message, u, u.id === message.author.id); + } + async execSlash( + message: CommandInteraction, + { user }: { user?: SlashCommandOption } + ): Promise { + const u = user?.user || message.user; + await this.sendResponse(message, u, u.id === message.user.id); + } +} diff --git a/src/commands/info/pronounsCommand.ts b/src/commands/info/pronounsCommand.ts deleted file mode 100644 index 2c1d5f2..0000000 --- a/src/commands/info/pronounsCommand.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { User, Message, MessageEmbed } from 'discord.js'; -import got, { HTTPError } from 'got'; -import { CommandInteraction } from 'discord.js'; -import { ApplicationCommandOptionType } from 'discord-api-types'; -import { SlashCommandOption } from '../../lib/extensions/Util'; - -export const pronounMapping = { - unspecified: 'Unspecified', - hh: 'He/Him', - hi: 'He/It', - hs: 'He/She', - ht: 'He/They', - ih: 'It/Him', - ii: 'It/Its', - is: 'It/She', - it: 'It/They', - shh: 'She/He', - sh: 'She/Her', - si: 'She/It', - st: 'She/They', - th: 'They/He', - ti: 'They/It', - ts: 'They/She', - tt: 'They/Them', - any: 'Any pronouns', - other: 'Other pronouns', - ask: 'Ask me my pronouns', - avoid: 'Avoid pronouns, use my name' -}; -export type pronounsType = keyof typeof pronounMapping; - -export default class PronounsCommand extends BushCommand { - constructor() { - super('pronouns', { - aliases: ['pronouns', 'pronoun'], - category: 'info', - description: { - usage: 'pronouns ', - examples: ['pronouns IRONM00N'], - content: 'Finds the pronouns of a user using https://pronoundb.org.' - }, - args: [ - { - id: 'user', - type: 'user', - default: null - } - ], - clientPermissions: ['SEND_MESSAGES'], - slashCommandOptions: [ - { - type: ApplicationCommandOptionType.USER, - name: 'user', - description: 'The user to get pronouns for', - required: false - } - ], - slashEmphemeral: true // I'll add dynamic checking to this later - }); - } - async sendResponse( - message: Message | CommandInteraction, - user: User, - author: boolean - ): Promise { - try { - const apiRes: { pronouns: pronounsType } = await got - .get( - `https://pronoundb.org/api/v1/lookup?platform=discord&id=${user.id}` - ) - .json(); - if (message instanceof Message) { - message.reply( - new MessageEmbed({ - title: `${author ? 'Your' : `${user.tag}'s`} pronouns:`, - description: pronounMapping[apiRes.pronouns], - footer: { - text: 'Data provided by https://pronoundb.org/' - } - }) - ); - } else { - message.reply({ - embeds: [ - new MessageEmbed({ - title: `${author ? 'Your' : `${user.tag}'s`} pronouns:`, - description: pronounMapping[apiRes.pronouns], - footer: { - text: 'Data provided by https://pronoundb.org/' - } - }) - ] - }); - } - } catch (e) { - if (e instanceof HTTPError && e.response.statusCode === 404) { - if (author) { - await message.reply( - 'You do not appear to have any pronouns set. Please go to https://pronoundb.org/ and set your pronouns.' - ); - } else { - await message.reply( - `${user.tag} does not appear to have any pronouns set. Please tell them to go to https://pronoundb.org/ and set their pronouns.` - ); - } - } else throw e; - } - } - async exec(message: Message, { user }: { user?: User }): Promise { - const u = user || message.author; - await this.sendResponse(message, u, u.id === message.author.id); - } - async execSlash( - message: CommandInteraction, - { user }: { user?: SlashCommandOption } - ): Promise { - const u = user?.user || message.user; - await this.sendResponse(message, u, u.id === message.user.id); - } -} -- cgit