aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moderation
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/moderation')
-rw-r--r--src/commands/moderation/ban.ts84
-rw-r--r--src/commands/moderation/kick.ts40
-rw-r--r--src/commands/moderation/modlog.ts26
-rw-r--r--src/commands/moderation/role.ts112
-rw-r--r--src/commands/moderation/warn.ts22
5 files changed, 73 insertions, 211 deletions
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts
index 556dd6b..e59a528 100644
--- a/src/commands/moderation/ban.ts
+++ b/src/commands/moderation/ban.ts
@@ -1,6 +1,6 @@
import { User } from 'discord.js';
import { Guild } from '../../lib/models';
-import { BotCommand } from '../../lib/extensions/BotCommand';
+import { BushCommand } from '../../lib/extensions/BushCommand';
import { Ban, Modlog, ModlogType } from '../../lib/models';
import moment from 'moment';
import { Message } from 'discord.js';
@@ -15,13 +15,13 @@ 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 PrefixCommand extends BotCommand {
+export default class BanCommand extends BushCommand {
constructor() {
super('ban', {
aliases: ['ban'],
+ category: 'moderation',
args: [
{
id: 'user',
@@ -44,13 +44,9 @@ export default class PrefixCommand extends BotCommand {
clientPermissions: ['BAN_MEMBERS'],
userPermissions: ['BAN_MEMBERS'],
description: {
- content:
- 'Ban a member and log it in modlogs (with optional time to unban)',
+ content: 'Ban a member and log it in modlogs (with optional time to unban)',
usage: 'ban <member> <reason> [--time]',
- examples: [
- 'ban @Tyman being cool',
- 'ban @Tyman being cool --time 7days'
- ]
+ examples: ['ban @Tyman being cool', 'ban @Tyman being cool --time 7days']
},
slashCommandOptions: [
{
@@ -68,19 +64,13 @@ export default class PrefixCommand extends BotCommand {
{
type: ApplicationCommandOptionType.STRING,
name: 'time',
- description:
- 'The time the user should be banned for (default permanent)',
+ description: 'The time the user should be banned for (default permanent)',
required: false
}
]
});
}
- 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;
@@ -103,14 +93,9 @@ export default class PrefixCommand extends BotCommand {
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,
@@ -118,10 +103,7 @@ export default class PrefixCommand extends BotCommand {
reason,
type: ModlogType.TEMPBAN,
duration: duration.asMilliseconds(),
- moderator:
- message instanceof CommandInteraction
- ? message.user.id
- : message.author.id
+ moderator: message instanceof CommandInteraction ? message.user.id : message.author.id
});
banEntry = Ban.build({
user: user.id,
@@ -136,10 +118,7 @@ export default class PrefixCommand extends BotCommand {
guild: message.guild.id,
reason,
type: ModlogType.BAN,
- moderator:
- message instanceof CommandInteraction
- ? message.user.id
- : message.author.id
+ moderator: message instanceof CommandInteraction ? message.user.id : message.author.id
});
banEntry = Ban.build({
user: user.id,
@@ -157,27 +136,17 @@ export default class PrefixCommand extends BotCommand {
}
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();
@@ -185,16 +154,8 @@ export default class PrefixCommand extends BotCommand {
return;
}
}
- 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
- )) {
+ 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);
}
}
@@ -211,12 +172,7 @@ export default class PrefixCommand extends BotCommand {
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 f31047e..182485a 100644
--- a/src/commands/moderation/kick.ts
+++ b/src/commands/moderation/kick.ts
@@ -1,13 +1,14 @@
-import { BotCommand } from '../../lib/extensions/BotCommand';
+import { BushCommand } from '../../lib/extensions/BushCommand';
import { Guild, Modlog, ModlogType } from '../../lib/models';
import { GuildMember, Message } from 'discord.js';
import { ApplicationCommandOptionType } from 'discord-api-types';
import { CommandInteraction } from 'discord.js';
-export default class KickCommand extends BotCommand {
+export default class KickCommand extends BushCommand {
constructor() {
super('kick', {
aliases: ['kick'],
+ category: 'moderation',
args: [
{
id: 'user',
@@ -45,11 +46,7 @@ export default class KickCommand extends BotCommand {
});
}
- 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({
@@ -64,8 +61,7 @@ export default class KickCommand extends BotCommand {
modlogEnry = Modlog.build({
user: user.id,
guild: message.guild.id,
- moderator:
- message instanceof Message ? message.author.id : message.user.id,
+ moderator: message instanceof Message ? message.author.id : message.user.id,
type: ModlogType.KICK,
reason
});
@@ -76,43 +72,27 @@ export default class KickCommand extends BotCommand {
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();
return;
}
- yield `Kicked <@!${user.id}> with reason \`${
- reason || 'No reason given'
- }\``;
+ 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 320c6b4..806c00a 100644
--- a/src/commands/moderation/modlog.ts
+++ b/src/commands/moderation/modlog.ts
@@ -1,4 +1,4 @@
-import { BotCommand } from '../../lib/extensions/BotCommand';
+import { BushCommand } from '../../lib/extensions/BushCommand';
import { Message } from 'discord.js';
import { Modlog } from '../../lib/models';
import { MessageEmbed } from 'discord.js';
@@ -6,10 +6,11 @@ import moment from 'moment';
import { stripIndent } from 'common-tags';
import { Argument } from 'discord-akairo';
-export default class ModlogCommand extends BotCommand {
+export default class ModlogCommand extends BushCommand {
constructor() {
super('modlog', {
aliases: ['modlog', 'modlogs'],
+ category: 'moderation',
args: [
{
id: 'search',
@@ -52,10 +53,7 @@ export default class ModlogCommand extends BotCommand {
return { search, page };
}
}
- async exec(
- message: Message,
- { search, page }: { search: string; page: number }
- ): Promise<void> {
+ async exec(message: Message, { search, page }: { search: string; page: number }): Promise<void> {
const foundUser = await this.client.util.resolveUserAsync(search);
if (foundUser) {
const logs = await Modlog.findAll({
@@ -72,11 +70,7 @@ export default class ModlogCommand extends BotCommand {
Type: ${log.type.toLowerCase()}
User: <@!${log.user}> (${log.user})
Moderator: <@!${log.moderator}> (${log.moderator})
- Duration: ${
- log.duration
- ? moment.duration(log.duration, 'milliseconds').humanize()
- : 'N/A'
- }
+ Duration: ${log.duration ? moment.duration(log.duration, 'milliseconds').humanize() : 'N/A'}
Reason: ${log.reason || 'None given'}
${this.client.util.ordinal(logs.indexOf(log) + 1)} action
`);
@@ -86,9 +80,7 @@ export default class ModlogCommand extends BotCommand {
(e, i) =>
new MessageEmbed({
title: `Modlogs page ${i + 1}`,
- description: e.join(
- '\n-------------------------------------------------------\n'
- ),
+ description: e.join('\n-------------------------------------------------------\n'),
footer: {
text: `Page ${i + 1}/${chunked.length}`
}
@@ -118,11 +110,7 @@ export default class ModlogCommand extends BotCommand {
},
{
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 2a67e5b..0c7d7db 100644
--- a/src/commands/moderation/role.ts
+++ b/src/commands/moderation/role.ts
@@ -1,34 +1,20 @@
/* eslint-disable @typescript-eslint/no-empty-function */
-import { BotCommand } from '../../lib/extensions/BotCommand';
+import { BushCommand } from '../../lib/extensions/BushCommand';
import AllowedMentions from '../../lib/utils/AllowedMentions';
import { Message, Role, GuildMember } from 'discord.js';
import { ApplicationCommandOptionType } from 'discord-api-types';
-export default class RoleCommand extends BotCommand {
+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'],
'No Links': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'],
'No Bots': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'],
'No VC': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'],
- 'No Giveaways': [
- '*',
- 'Admin Perms',
- 'Sr. Moderator',
- 'Moderator',
- 'Helper'
- ],
+ 'No Giveaways': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator', 'Helper'],
'No Support': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'],
'Giveaway Donor': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'],
'Giveaway (200m)': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'],
@@ -42,7 +28,7 @@ export default class RoleCommand extends BotCommand {
constructor() {
super('role', {
aliases: ['role', 'addrole', 'removerole'],
- category: "Moulberry's Bush",
+ category: 'moderation',
description: {
content: "Manages users' roles.",
usage: 'role <add|remove> <user> <role>',
@@ -87,66 +73,38 @@ export default class RoleCommand extends BotCommand {
});
}
- 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
- );
+ 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;
+ 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()
- }
- );
+ 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()
+ });
}
}
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
@@ -154,28 +112,16 @@ export default class RoleCommand extends BotCommand {
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 41e0032..3410d81 100644
--- a/src/commands/moderation/warn.ts
+++ b/src/commands/moderation/warn.ts
@@ -1,11 +1,12 @@
import { GuildMember, Message } from 'discord.js';
-import { BotCommand } from '../../lib/extensions/BotCommand';
+import { BushCommand } from '../../lib/extensions/BushCommand';
import { Guild, Modlog, ModlogType } from '../../lib/models';
-export default class WarnCommand extends BotCommand {
+export default class WarnCommand extends BushCommand {
public constructor() {
super('warn', {
aliases: ['warn'],
+ category: 'moderation',
userPermissions: ['MANAGE_MESSAGES'],
args: [
{
@@ -24,10 +25,7 @@ export default class WarnCommand extends BotCommand {
}
});
}
- 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: {
@@ -47,21 +45,15 @@ export default class WarnCommand extends BotCommand {
});
await entry.save();
} catch (e) {
- await message.util.send(
- 'Error saving to database, please contact the developers'
- );
+ await message.util.send('Error saving to database, please contact the developers');
return;
}
try {
- await member.send(
- `You were warned in ${message.guild.name} for reason "${reason}".`
- );
+ await member.send(`You were warned in ${message.guild.name} for reason "${reason}".`);
} catch (e) {
await message.util.send('Error messaging user, warning still saved.');
return;
}
- await message.util.send(
- `${member.user.tag} was warned for reason "${reason}".`
- );
+ await message.util.send(`${member.user.tag} was warned for reason "${reason}".`);
}
}