diff options
Diffstat (limited to 'src/commands/moderation')
-rw-r--r-- | src/commands/moderation/ban.ts | 45 | ||||
-rw-r--r-- | src/commands/moderation/kick.ts | 26 | ||||
-rw-r--r-- | src/commands/moderation/modlog.ts | 4 | ||||
-rw-r--r-- | src/commands/moderation/role.ts | 85 | ||||
-rw-r--r-- | src/commands/moderation/warn.ts | 5 |
5 files changed, 40 insertions, 125 deletions
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 05c26e0..e59a528 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -15,8 +15,7 @@ const durationAliases: Record<string, string[]> = { minutes: ['m', 'min', 'mins', 'minutes', 'minute'], months: ['mo', 'month', 'months'] }; -const durationRegex = - /(?:(\d+)(d(?:ays?)?|h(?:ours?|rs?)?|m(?:inutes?|ins?)?|mo(?:nths?)?|w(?:eeks?|ks?)?)(?: |$))/g; +const durationRegex = /(?:(\d+)(d(?:ays?)?|h(?:ours?|rs?)?|m(?:inutes?|ins?)?|mo(?:nths?)?|w(?:eeks?|ks?)?)(?: |$))/g; export default class BanCommand extends BushCommand { constructor() { @@ -71,12 +70,7 @@ export default class BanCommand extends BushCommand { ] }); } - async *genResponses( - message: Message | CommandInteraction, - user: User, - reason?: string, - time?: string - ): AsyncIterable<string> { + async *genResponses(message: Message | CommandInteraction, user: User, reason?: string, time?: string): AsyncIterable<string> { const duration = moment.duration(); let modlogEnry: Modlog; let banEntry: Ban; @@ -99,14 +93,9 @@ export default class BanCommand extends BushCommand { return; } for (const part of parsed) { - const translated = Object.keys(durationAliases).find((k) => - durationAliases[k].includes(part[2]) - ); + const translated = Object.keys(durationAliases).find((k) => durationAliases[k].includes(part[2])); translatedTime.push(part[1] + ' ' + translated); - duration.add( - Number(part[1]), - translated as 'weeks' | 'days' | 'hours' | 'months' | 'minutes' - ); + duration.add(Number(part[1]), translated as 'weeks' | 'days' | 'hours' | 'months' | 'minutes'); } modlogEnry = Modlog.build({ user: user.id, @@ -147,21 +136,17 @@ export default class BanCommand extends BushCommand { } try { await user.send( - `You were banned in ${message.guild.name} ${ - translatedTime.length >= 1 ? `for ${translatedTime.join(', ')}` : 'permanently' - } with reason \`${reason || 'No reason given'}\`` + `You were banned in ${message.guild.name} ${translatedTime.length >= 1 ? `for ${translatedTime.join(', ')}` : 'permanently'} with reason \`${ + reason || 'No reason given' + }\`` ); } catch (e) { yield 'Error sending message to user'; } await message.guild.members.ban(user, { - reason: `Banned by ${ - message instanceof CommandInteraction ? message.user.tag : message.author.tag - } with ${reason ? `reason ${reason}` : 'no reason'}` + reason: `Banned by ${message instanceof CommandInteraction ? message.user.tag : message.author.tag} with ${reason ? `reason ${reason}` : 'no reason'}` }); - yield `Banned <@!${user.id}> ${ - translatedTime.length >= 1 ? `for ${translatedTime.join(', ')}` : 'permanently' - } with reason \`${reason || 'No reason given'}\``; + yield `Banned <@!${user.id}> ${translatedTime.length >= 1 ? `for ${translatedTime.join(', ')}` : 'permanently'} with reason \`${reason || 'No reason given'}\``; } catch { yield 'Error banning :/'; await banEntry.destroy(); @@ -169,10 +154,7 @@ export default class BanCommand extends BushCommand { return; } } - async exec( - message: Message, - { user, reason, time }: { user: User; reason?: string; time?: string } - ): Promise<void> { + async exec(message: Message, { user, reason, time }: { user: User; reason?: string; time?: string }): Promise<void> { for await (const response of this.genResponses(message, user, reason, time)) { await message.util.send(response); } @@ -190,12 +172,7 @@ export default class BanCommand extends BushCommand { time: SlashCommandOption<string>; } ): Promise<void> { - for await (const response of this.genResponses( - message, - user.user, - reason?.value, - time?.value - )) { + for await (const response of this.genResponses(message, user.user, reason?.value, time?.value)) { await message.reply(response); } } diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index f3ee44c..182485a 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -46,11 +46,7 @@ export default class KickCommand extends BushCommand { }); } - private async *genResponses( - message: Message | CommandInteraction, - user: GuildMember, - reason?: string - ): AsyncIterable<string> { + private async *genResponses(message: Message | CommandInteraction, user: GuildMember, reason?: string): AsyncIterable<string> { let modlogEnry: Modlog; // Create guild entry so postgres doesn't get mad when I try and add a modlog entry await Guild.findOrCreate({ @@ -76,18 +72,12 @@ export default class KickCommand extends BushCommand { return; } try { - await user.send( - `You were kicked in ${message.guild.name} with reason \`${reason || 'No reason given'}\`` - ); + await user.send(`You were kicked in ${message.guild.name} with reason \`${reason || 'No reason given'}\``); } catch (e) { yield 'Error sending message to user'; } try { - await user.kick( - `Kicked by ${message instanceof Message ? message.author.tag : message.user.tag} with ${ - reason ? `reason ${reason}` : 'no reason' - }` - ); + await user.kick(`Kicked by ${message instanceof Message ? message.author.tag : message.user.tag} with ${reason ? `reason ${reason}` : 'no reason'}`); } catch { yield 'Error kicking :/'; await modlogEnry.destroy(); @@ -96,19 +86,13 @@ export default class KickCommand extends BushCommand { yield `Kicked <@!${user.id}> with reason \`${reason || 'No reason given'}\``; } - async exec( - message: Message, - { user, reason }: { user: GuildMember; reason?: string } - ): Promise<void> { + async exec(message: Message, { user, reason }: { user: GuildMember; reason?: string }): Promise<void> { for await (const response of this.genResponses(message, user, reason)) { await message.util.send(response); } } - async execSlash( - message: CommandInteraction, - { user, reason }: { user: GuildMember; reason?: string } - ): Promise<void> { + async execSlash(message: CommandInteraction, { user, reason }: { user: GuildMember; reason?: string }): Promise<void> { for await (const response of this.genResponses(message, user, reason)) { await message.reply(response); } diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index c4eb46a..806c00a 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -110,9 +110,7 @@ export default class ModlogCommand extends BushCommand { }, { name: 'Duration', - value: `${ - entry.duration ? moment.duration(entry.duration, 'milliseconds').humanize() : 'N/A' - }`, + value: `${entry.duration ? moment.duration(entry.duration, 'milliseconds').humanize() : 'N/A'}`, inline: true }, { diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index f03e0ad..0c7d7db 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -7,15 +7,7 @@ import { ApplicationCommandOptionType } from 'discord-api-types'; export default class RoleCommand extends BushCommand { private roleWhitelist: Record<string, string[]> = { 'Partner': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'], - 'Suggester': [ - '*', - 'Admin Perms', - 'Sr. Moderator', - 'Moderator', - 'Helper', - 'Trial Helper', - 'Contributor' - ], + 'Suggester': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator', 'Helper', 'Trial Helper', 'Contributor'], 'Level Locked': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'], 'No Files': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'], 'No Reactions': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'], @@ -81,59 +73,38 @@ export default class RoleCommand extends BushCommand { }); } - public async exec( - message: Message, - { user, role }: { user: GuildMember; role: Role } - ): Promise<unknown> { - if ( - !message.member.permissions.has('MANAGE_ROLES') && - !this.client.ownerID.includes(message.author.id) - ) { + public async exec(message: Message, { user, role }: { user: GuildMember; role: Role }): Promise<unknown> { + if (!message.member.permissions.has('MANAGE_ROLES') && !this.client.ownerID.includes(message.author.id)) { const mappedRole = this.client.util.moulberryBushRoleMap.find((m) => m.id === role.id); if (!mappedRole || !this.roleWhitelist[mappedRole.name]) { - return message.util.reply( - `<:error:837123021016924261> <@&${role.id}> is not whitelisted, and you do not have manage roles permission.`, - { - allowedMentions: AllowedMentions.none() - } - ); + return message.util.reply(`<:error:837123021016924261> <@&${role.id}> is not whitelisted, and you do not have manage roles permission.`, { + allowedMentions: AllowedMentions.none() + }); } const allowedRoles = this.roleWhitelist[mappedRole.name].map((r) => { return this.client.util.moulberryBushRoleMap.find((m) => m.name === r).id; }); if (!message.member.roles.cache.some((role) => allowedRoles.includes(role.id))) { - return message.util.reply( - `<:error:837123021016924261> <@&${role.id}> is whitelisted, but you do not have any of the roles required to manage it.`, - { - allowedMentions: AllowedMentions.none() - } - ); + return message.util.reply(`<:error:837123021016924261> <@&${role.id}> is whitelisted, but you do not have any of the roles required to manage it.`, { + allowedMentions: AllowedMentions.none() + }); } } if (!this.client.ownerID.includes(message.author.id)) { if (role.comparePositionTo(message.member.roles.highest) >= 0) { - return message.util.reply( - `<:error:837123021016924261> <@&${role.id}> is higher or equal to your highest role.`, - { - allowedMentions: AllowedMentions.none() - } - ); + return message.util.reply(`<:error:837123021016924261> <@&${role.id}> is higher or equal to your highest role.`, { + allowedMentions: AllowedMentions.none() + }); } if (role.comparePositionTo(message.guild.me.roles.highest) >= 0) { - return message.util.reply( - `<:error:837123021016924261> <@&${role.id}> is higher or equal to my highest role.`, - { - allowedMentions: AllowedMentions.none() - } - ); + return message.util.reply(`<:error:837123021016924261> <@&${role.id}> is higher or equal to my highest role.`, { + allowedMentions: AllowedMentions.none() + }); } if (role.managed) { - await message.util.reply( - `<:error:837123021016924261> <@&${role.id}> is managed by an integration and cannot be managed.`, - { - allowedMentions: AllowedMentions.none() - } - ); + await message.util.reply(`<:error:837123021016924261> <@&${role.id}> is managed by an integration and cannot be managed.`, { + allowedMentions: AllowedMentions.none() + }); } } // No checks if the user has MANAGE_ROLES @@ -141,28 +112,16 @@ export default class RoleCommand extends BushCommand { try { await user.roles.remove(role.id); } catch { - return message.util.reply( - `<:error:837123021016924261> Could not remove <@&${role.id}> from <@${user.id}>.`, - { allowedMentions: AllowedMentions.none() } - ); + return message.util.reply(`<:error:837123021016924261> Could not remove <@&${role.id}> from <@${user.id}>.`, { allowedMentions: AllowedMentions.none() }); } - return message.util.reply( - `<:checkmark:837109864101707807> Successfully removed <@&${role.id}> from <@${user.id}>!`, - { allowedMentions: AllowedMentions.none() } - ); + return message.util.reply(`<:checkmark:837109864101707807> Successfully removed <@&${role.id}> from <@${user.id}>!`, { allowedMentions: AllowedMentions.none() }); } else { try { await user.roles.add(role.id); } catch { - return message.util.reply( - `<:error:837123021016924261> Could not add <@&${role.id}> to <@${user.id}>.`, - { allowedMentions: AllowedMentions.none() } - ); + return message.util.reply(`<:error:837123021016924261> Could not add <@&${role.id}> to <@${user.id}>.`, { allowedMentions: AllowedMentions.none() }); } - return message.util.reply( - `<:checkmark:837109864101707807> Successfully added <@&${role.id}> to <@${user.id}>!`, - { allowedMentions: AllowedMentions.none() } - ); + return message.util.reply(`<:checkmark:837109864101707807> Successfully added <@&${role.id}> to <@${user.id}>!`, { allowedMentions: AllowedMentions.none() }); } } } diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index 5651830..3410d81 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -25,10 +25,7 @@ export default class WarnCommand extends BushCommand { } }); } - public async exec( - message: Message, - { member, reason }: { member: GuildMember; reason: string } - ): Promise<void> { + public async exec(message: Message, { member, reason }: { member: GuildMember; reason: string }): Promise<void> { // Create guild entry so postgres doesn't get mad when I try and add a modlog entry await Guild.findOrCreate({ where: { |