aboutsummaryrefslogtreecommitdiff
path: root/src/commands/info/pronouns.ts
blob: 241dce39900fe0dac415483d4bdfb6a083c94c52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { Message, MessageEmbed, User } from 'discord.js';
import got, { HTTPError } from 'got';
import { BushCommand, BushSlashMessage } from '../../lib';

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 {
	public constructor() {
		super('pronouns', {
			aliases: ['pronouns', 'pronoun'],
			category: 'info',
			description: {
				usage: 'pronouns <user>',
				examples: ['pronouns IRONM00N'],
				content: 'Finds the pronouns of a user using https://pronoundb.org.'
			},
			args: [
				{
					id: 'user',
					type: 'user',
					prompt: {
						start: 'Who would you like to view the pronouns of?',
						retry: '{error} Choose a valid user to view the pronouns of.',
						optional: true
					}
				}
			],
			clientPermissions: ['SEND_MESSAGES'],
			slashOptions: [
				{
					type: 'USER',
					name: 'user',
					description: 'The user to get pronouns for',
					required: false
				}
			],
			slash: true
		});
	}
	async exec(message: Message | BushSlashMessage, args: { user?: User }): Promise<void> {
		const user = args.user || message.author;
		const author = user.id === message.author.id;
		try {
			const apiRes: { pronouns: pronounsType } = await got
				.get(`https://pronoundb.org/api/v1/lookup?platform=discord&id=${user.id}`)
				.json();
			message.util.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.util.reply(
						'You do not appear to have any pronouns set. Please go to https://pronoundb.org/ and set your pronouns.'
					);
				} else {
					await message.util.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;
		}
	}
}