diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/info/pronouns.ts | 62 | ||||
-rw-r--r-- | src/commands/info/userInfo.ts | 5 | ||||
-rw-r--r-- | src/commands/leveling/leaderboard.ts | 2 | ||||
-rw-r--r-- | src/commands/moderation/ban.ts | 51 | ||||
-rw-r--r-- | src/commands/moderation/kick.ts | 5 | ||||
-rw-r--r-- | src/commands/moderation/modlog.ts | 9 | ||||
-rw-r--r-- | src/commands/moderation/mute.ts | 5 |
7 files changed, 62 insertions, 77 deletions
diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index ea20d41..77612da 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -1,32 +1,6 @@ import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; import { Snowflake } from 'discord-api-types'; import { MessageEmbed, User } from 'discord.js'; -import got, { HTTPError } from 'got'; - -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() { @@ -62,43 +36,31 @@ export default class PronounsCommand extends BushCommand { }); } override async exec(message: BushMessage | BushSlashMessage, args: { user?: User | Snowflake }): Promise<unknown> { - const user = - args?.user === undefined || args?.user === null - ? message.author - : typeof args.user === 'object' - ? args.user - : await client.users.fetch(`${args.user}`).catch(() => undefined); + const user = (await util.resolveNonCachedUser(args.user)) ?? message.author; - if (user === undefined) return message.util.reply(`${util.emojis.error} Invalid user.`); + if (!user) return message.util.reply(`${util.emojis.error} Invalid user.`); 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(); + + const pronouns = await util.getPronounsOf(user); + if (!pronouns) { + return await message.util.reply( + `${author ? 'You do' : `${user.tag} does`} not appear to have any pronouns set. Please ${ + author ? '' : 'tell them to' + } go to https://pronoundb.org/ and set ${author ? 'your' : 'their'} pronouns.` + ); + } else { return await message.util.reply({ embeds: [ new MessageEmbed({ title: `${author ? 'Your' : `${user.tag}'s`} pronouns:`, - description: pronounMapping[apiRes.pronouns], + description: pronouns, footer: { text: 'Data provided by https://pronoundb.org/' } }) ] }); - } catch (e) { - if (e instanceof HTTPError && e.response.statusCode === 404) { - if (author) { - return await message.util.reply( - 'You do not appear to have any pronouns set. Please go to https://pronoundb.org/ and set your pronouns.' - ); - } else { - return 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; } } } diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index ae204f7..9fddd67 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -96,6 +96,11 @@ export default class UserInfoCommand extends BushCommand { `**ID:** ${user.id}`, `**Created: **${createdAt} (${createdAtDelta} ago)` ]; + if (user.accentColor !== null) generalInfo.push(`**Accent Color:** ${user.hexAccentColor}`); + if (user.banner) generalInfo.push(`**Banner**: [link](${user.bannerURL({ dynamic: true, format: 'png' })})`); + const pronouns = await util.getPronounsOf(user); + if (pronouns) generalInfo.push(`**Pronouns:** ${pronouns}`); + userEmbed.addField('» General Info', generalInfo.join('\n')); // Server User Info diff --git a/src/commands/leveling/leaderboard.ts b/src/commands/leveling/leaderboard.ts index b8838b7..d29c15e 100644 --- a/src/commands/leveling/leaderboard.ts +++ b/src/commands/leveling/leaderboard.ts @@ -47,6 +47,6 @@ export default class LeaderboardCommand extends BushCommand { const embeds = chunked.map((c) => new MessageEmbed().setTitle(`${message.guild!.name}'s Leaderboard`).setDescription(c.join('\n')) ); - return await util.buttonPaginate(message, embeds, null, true, args?.page ?? undefined); + return await util.buttonPaginate(message, embeds, undefined, true, args?.page ?? undefined); } } diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index c33b39a..2c3e429 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -1,5 +1,5 @@ -import { AllowedMentions, BushCommand, BushGuildMember, BushMessage, BushSlashMessage } from '@lib'; -import { User } from 'discord.js'; +import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage } from '@lib'; +import { Snowflake, User } from 'discord.js'; export default class BanCommand extends BushCommand { public constructor() { @@ -14,7 +14,7 @@ export default class BanCommand extends BushCommand { args: [ { id: 'user', - type: 'user', + customType: util.arg.union('user', 'snowflake'), prompt: { start: 'What user would you like to ban?', retry: '{error} Choose a valid user to ban.' @@ -83,17 +83,19 @@ export default class BanCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, { - user, + user: _user, reason, days, force - }: { user: User; reason?: { duration: number; contentWithoutTime: string }; days?: number; force: boolean } + }: { user: User | Snowflake; reason?: { duration: number; contentWithoutTime: string }; days?: number; force: boolean } ): Promise<unknown> { if (!message.guild) return message.util.reply(`${util.emojis.error} This command cannot be used in dms.`); - const member = message.guild!.members.cache.get(user.id) as BushGuildMember; + const member = message.guild!.members.cache.get((_user as User)?.id); + const user = member?.user ?? (await util.resolveNonCachedUser(_user)); + if (!user) return message.util.reply(`${util.emojis.error} Invalid user.`); const useForce = force && message.author.isOwner(); if (!message.member) throw new Error(`message.member is null`); - const canModerateResponse = util.moderationPermissionCheck(message.member, member, 'ban', true, useForce); + const canModerateResponse = member ? util.moderationPermissionCheck(message.member, member, 'ban', true, useForce) : true; if (canModerateResponse !== true) { return message.util.reply(canModerateResponse); @@ -112,31 +114,40 @@ export default class BanCommand extends BushCommand { ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, reason) : reason.duration; } - const parsedReason = reason?.contentWithoutTime ?? ''; + const parsedReason = reason?.contentWithoutTime ?? null; - const responseCode = await member.bushBan({ - reason: parsedReason, - moderator: message.author, - duration: time! ?? 0, - deleteDays: days ?? 0 - }); + const responseCode = member + ? await member.bushBan({ + reason: parsedReason, + moderator: message.author, + duration: time! ?? 0, + deleteDays: days ?? 0 + }) + : await message.guild.ban({ + user, + reason: parsedReason, + moderator: message.author, + duration: time! ?? 0, + deleteDays: days ?? 0 + }); const responseMessage = () => { switch (responseCode) { case 'missing permissions': - return `${util.emojis.error} Could not ban **${member.user.tag}** because I do not have permissions`; + return `${util.emojis.error} Could not ban **${user.tag}** because I do not have permissions`; case 'error banning': - return `${util.emojis.error} An error occurred while trying to ban **${member.user.tag}**.`; + return `${util.emojis.error} An error occurred while trying to ban **${user.tag}**.`; case 'error creating ban entry': - return `${util.emojis.error} While banning **${member.user.tag}**, there was an error creating a ban entry, please report this to my developers.`; + return `${util.emojis.error} While banning **${user.tag}**, there was an error creating a ban entry, please report this to my developers.`; case 'error creating modlog entry': - return `${util.emojis.error} While banning **${member.user.tag}**, there was an error creating a modlog entry, please report this to my developers.`; + return `${util.emojis.error} While banning **${user.tag}**, there was an error creating a modlog entry, please report this to my developers.`; case 'failed to dm': - return `${util.emojis.warn} Banned **${member.user.tag}** however I could not send them a dm.`; + return `${util.emojis.warn} Banned **${user.tag}** however I could not send them a dm.`; case 'success': - return `${util.emojis.success} Successfully banned **${member.user.tag}**.`; + return `${util.emojis.success} Successfully banned **${user.tag}**.`; } }; + client.console.debug(responseCode); return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); } } diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index 2315712..341d83c 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -61,7 +61,10 @@ export default class KickCommand extends BushCommand { ): Promise<unknown> { const member = message.guild!.members.cache.get(user.id) as BushGuildMember; - if (!member) return await message.util.reply(`${util.emojis.error} You cannot kick members that are not in the server.`); + if (!member) + return await message.util.reply( + `${util.emojis.error} The user you selected is not in the server or is not a valid user.` + ); if (!message.member) throw new Error(`message.member is null`); const useForce = force && message.author.isOwner(); const canModerateResponse = util.moderationPermissionCheck(message.member, member, 'kick', true, useForce); diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index ef0a56e..fd53ea7 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -35,6 +35,7 @@ export default class ModlogCommand extends BushCommand { } #generateModlogInfo(log: ModLog): string { + const trim = (str: string): string => (str.endsWith('\n') ? str.substring(0, str.length - 1).trim() : str.trim()); const modLog = [ `**Case ID**: ${log.id}`, `**Type**: ${log.type.toLowerCase()}`, @@ -42,8 +43,8 @@ export default class ModlogCommand extends BushCommand { `**Moderator**: <@!${log.moderator}> (${log.moderator})` ]; if (log.duration) modLog.push(`**Duration**: ${util.humanizeDuration(log.duration)}`); - modLog.push(`**Reason**: ${log.reason ?? 'No Reason Specified.'}`); - if (log.evidence) modLog.push(`**Evidence:** ${log.evidence}`); + modLog.push(`**Reason**: ${trim(log.reason ?? 'No Reason Specified.')}`); + if (log.evidence) modLog.push(`**Evidence:** ${trim(log.evidence)}`); return modLog.join(`\n`); } @@ -70,11 +71,11 @@ export default class ModlogCommand extends BushCommand { (chunk) => new MessageEmbed({ title: `${foundUser.tag}'s Mod Logs`, - description: chunk.join('\n**―――――――――――――――――――――――――――**\n'), + description: chunk.join('\n━━━━━━━━━━━━━━━\n'), color: util.colors.default }) ); - return await util.buttonPaginate(message, embedPages, '', true); + return await util.buttonPaginate(message, embedPages, undefined, true); } else if (search) { const entry = await ModLog.findByPk(search as string); if (!entry) return message.util.send(`${util.emojis.error} That modlog does not exist.`); diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index 915302e..ea2ff41 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -61,7 +61,10 @@ export default class MuteCommand extends BushCommand { { user, reason, force }: { user: BushUser; reason?: { duration: number; contentWithoutTime: string }; force: boolean } ): Promise<unknown> { const member = message.guild!.members.cache.get(user.id); - if (!member) return await message.util.reply(`${util.emojis.error} You cannot kick members that are not in the server.`); + if (!member) + return await message.util.reply( + `${util.emojis.error} The user you selected is not in the server or is not a valid user.` + ); if (!message.member) throw new Error(`message.member is null`); const useForce = force && message.author.isOwner(); |