aboutsummaryrefslogtreecommitdiff
path: root/src/commands/info/pronouns.ts
diff options
context:
space:
mode:
authorTymanWasTaken <32660892+tymanwastaken@users.noreply.github.com>2021-05-26 10:53:16 -0600
committerTymanWasTaken <32660892+tymanwastaken@users.noreply.github.com>2021-05-26 10:53:16 -0600
commit53d8d5e551e9a239fd4c48c7dca4e1f6fb8d81e9 (patch)
tree15896b71e22fd7d1d002364c969bf14a00a29af0 /src/commands/info/pronouns.ts
parent9c345bf5f62eeb3f9f7246d8259e0978a18c7bc0 (diff)
downloadtanzanite-53d8d5e551e9a239fd4c48c7dca4e1f6fb8d81e9.tar.gz
tanzanite-53d8d5e551e9a239fd4c48c7dca4e1f6fb8d81e9.tar.bz2
tanzanite-53d8d5e551e9a239fd4c48c7dca4e1f6fb8d81e9.zip
pronouns command and use guild slash commands for testing not global
Diffstat (limited to 'src/commands/info/pronouns.ts')
-rw-r--r--src/commands/info/pronouns.ts106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts
new file mode 100644
index 0000000..07d210f
--- /dev/null
+++ b/src/commands/info/pronouns.ts
@@ -0,0 +1,106 @@
+import { BotCommand } from '../../lib/extensions/BotCommand';
+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 BotCommand {
+ constructor() {
+ super('pronouns', {
+ aliases: ['pronouns', 'pronoun'],
+ category: 'utilities',
+ description: {
+ usage: 'pronouns <user>',
+ 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<void> {
+ 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<void> {
+ const u = user || message.author;
+ await this.sendResponse(message, u, u.id === message.author.id)
+ }
+ async execSlash(message: CommandInteraction, { user }: { user?: SlashCommandOption<void> }): Promise<void> {
+ const u = user?.user || message.user
+ await this.sendResponse(message, u, u.id === message.user.id)
+ }
+} \ No newline at end of file