diff options
author | TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> | 2021-05-11 10:47:03 -0600 |
---|---|---|
committer | TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> | 2021-05-11 10:47:03 -0600 |
commit | 2ef1219194811e5732b6234bd98c531e1eb77dc5 (patch) | |
tree | 431d7fd81a9076907a89e8dd2eb6bddba0030583 | |
parent | 062e6c37c396456caa25c9aa84083800600128d1 (diff) | |
download | tanzanite-2ef1219194811e5732b6234bd98c531e1eb77dc5.tar.gz tanzanite-2ef1219194811e5732b6234bd98c531e1eb77dc5.tar.bz2 tanzanite-2ef1219194811e5732b6234bd98c531e1eb77dc5.zip |
add capeperms command
-rw-r--r-- | src/commands/moulberry-bush/capeperms.ts | 111 | ||||
-rw-r--r-- | src/lib/extensions/Util.ts | 30 |
2 files changed, 141 insertions, 0 deletions
diff --git a/src/commands/moulberry-bush/capeperms.ts b/src/commands/moulberry-bush/capeperms.ts new file mode 100644 index 0000000..0588696 --- /dev/null +++ b/src/commands/moulberry-bush/capeperms.ts @@ -0,0 +1,111 @@ +import { Message } from 'discord.js'; +import got from 'got'; +import { BotCommand } from '../../lib/extensions/BotCommand'; + +interface Capeperms { + success: boolean; + perms: User[]; +} +interface User { + _id: string; + perms: string[]; +} + +export default class CapePermsCommand extends BotCommand { + private nameMap = { + patreon1: 'Patreon Tier 1', + patreon2: 'Patreon Tier 2', + fade: 'Fade', + contrib: 'Contributor', + nullzee: 'Nullzee', + gravy: 'ThatGravyBoat', + space: 'Space', + mcworld: 'Minecraft World', + lava: 'Lava', + packshq: 'PacksHQ', + mbstaff: "Moulberry's Bush staff", + thebakery: "Biscuit's Bakery", + negative: 'Negative', + void: 'Void', + ironmoon: 'IRONM00N', + krusty: 'Krusty', + furf: 'FurfSky Reborn', + soldier: 'Soldier', + dsm: "Danker's Skyblock Mod", + zera: 'Zera', + tunnel: 'Tunnel', + alexxoffi: 'Alexxoffi', + parallax: 'Parallax', + jakethybro: 'Jakethybro', + planets: 'Planets' + }; + public constructor() { + super('capeperms', { + aliases: ['capeperms', 'capeperm'], + category: "Moulberry's Bush", + description: { + content: 'A command to see what capes someone has access to.', + usage: 'capeperms <user>', + examples: ['capeperms IRONM00N'] + }, + args: [ + { + id: 'user', + type: 'string', + prompt: { + start: 'Who would you like to see the cape permissions of?', + retry: + '<:error:837123021016924261> Choose someone to see the capes their available capes.', + optional: false + } + } + ], + clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], + channel: 'guild' + }); + } + public async exec( + message: Message, + { user }: { user: string } + ): Promise<Message> { + let capeperms: Capeperms, uuid: string; + try { + uuid = await this.client.util.mcUUID(user); + } catch (e) { + return message.util.reply( + `<:error:837123021016924261> \`${user}\` doesn't appear to be a valid username.` + ); + } + + try { + capeperms = await got + .get('http://moulberry.codes/permscapes.json') + .json(); + } catch (error) { + capeperms = null; + } + if (capeperms == null) { + return message.util.reply( + `<:error:837123021016924261> There was an error finding cape perms for \`${user}\`.` + ); + } else { + if (capeperms?.perms) { + const foundUser = capeperms.perms.find((u) => u._id === uuid); + if (foundUser == null) + return message.util.reply( + `<:error:837123021016924261> \`${user}\` does not appear to have any capes.` + ); + const userPerm: string[] = foundUser.perms; + const embed = this.client.util + .createEmbed(this.client.util.colors.default) + .setTitle(`${user}'s Capes`) + .setDescription(userPerm.join('\n')); + await message.util.reply(embed); + } else { + return message.util.reply( + `<:error:837123021016924261> There was an error finding cape perms for ${user}.` + ); + } + } + } +} diff --git a/src/lib/extensions/Util.ts b/src/lib/extensions/Util.ts index 4942bb8..771876b 100644 --- a/src/lib/extensions/Util.ts +++ b/src/lib/extensions/Util.ts @@ -12,6 +12,29 @@ interface hastebinRes { key: string; } +export interface uuidRes { + uuid: string; + username: string; + username_history?: + | { + username: string; + }[] + | null; + textures: { + custom: boolean; + slim: boolean; + skin: { + url: string; + data: string; + }; + raw: { + value: string; + signature: string; + }; + }; + created_at: string; +} + export class Util extends ClientUtil { /** * The client of this ClientUtil @@ -241,4 +264,11 @@ export class Util extends ClientUtil { if (color) embed = embed.setColor(color); return embed; } + + public async mcUUID(username: string): Promise<string> { + const apiRes = (await got + .get(`https://api.ashcon.app/mojang/v2/user/${username}`) + .json()) as uuidRes; + return apiRes.uuid; + } } |