aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moderation
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-13 15:04:42 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-13 15:04:42 -0400
commitcdb8b0297f806cb3147b3759b0fd234bffbcc3f9 (patch)
tree665c8d746e1ec7dee5755edbc7a8e6be7f77c26d /src/commands/moderation
parent528a4c2bde37ca7d1ded38af31f4a482d492d894 (diff)
downloadtanzanite-cdb8b0297f806cb3147b3759b0fd234bffbcc3f9.tar.gz
tanzanite-cdb8b0297f806cb3147b3759b0fd234bffbcc3f9.tar.bz2
tanzanite-cdb8b0297f806cb3147b3759b0fd234bffbcc3f9.zip
added unmute and unban command
Diffstat (limited to 'src/commands/moderation')
-rw-r--r--src/commands/moderation/_unban.ts0
-rw-r--r--src/commands/moderation/_unmute.ts0
-rw-r--r--src/commands/moderation/ban.ts204
-rw-r--r--src/commands/moderation/kick.ts29
-rw-r--r--src/commands/moderation/mute.ts6
-rw-r--r--src/commands/moderation/role.ts12
-rw-r--r--src/commands/moderation/unban.ts85
-rw-r--r--src/commands/moderation/unmute.ts109
-rw-r--r--src/commands/moderation/warn.ts6
9 files changed, 321 insertions, 130 deletions
diff --git a/src/commands/moderation/_unban.ts b/src/commands/moderation/_unban.ts
deleted file mode 100644
index e69de29..0000000
--- a/src/commands/moderation/_unban.ts
+++ /dev/null
diff --git a/src/commands/moderation/_unmute.ts b/src/commands/moderation/_unmute.ts
deleted file mode 100644
index e69de29..0000000
--- a/src/commands/moderation/_unmute.ts
+++ /dev/null
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts
index be7a51f..d713a15 100644
--- a/src/commands/moderation/ban.ts
+++ b/src/commands/moderation/ban.ts
@@ -1,4 +1,5 @@
-import { BushCommand, BushMessage, BushSlashMessage } from '@lib';
+import { BushCommand, BushGuildMember, BushMessage, BushSlashMessage } from '@lib';
+import { Argument } from 'discord-akairo';
import { User } from 'discord.js';
export default class BanCommand extends BushCommand {
@@ -6,6 +7,11 @@ export default class BanCommand extends BushCommand {
super('ban', {
aliases: ['ban'],
category: 'moderation',
+ description: {
+ content: 'Ban a member from the server.',
+ usage: 'ban <member> <reason> [--delete ]',
+ examples: ['ban 322862723090219008 1 day commands in #general --delete 7']
+ },
args: [
{
id: 'user',
@@ -20,137 +26,109 @@ export default class BanCommand extends BushCommand {
type: 'contentWithDuration',
match: 'restContent',
prompt: {
- start: 'Why would you like to ban this user?',
- retry: '{error} Choose a ban reason.',
+ start: 'Why should this user be banned and for how long?',
+ retry: '{error} Choose a valid ban reason and duration.',
optional: true
}
+ },
+ {
+ id: 'days',
+ flag: '--days',
+ match: 'option',
+ type: Argument.range('integer', 0, 7, true),
+ default: 0
}
],
- clientPermissions: ['BAN_MEMBERS'],
- userPermissions: ['BAN_MEMBERS'],
- description: {
- content: 'Ban a member from the server.',
- usage: 'ban <member> <reason> [--time]',
- examples: ['ban @user bad --time 69d']
- },
+ slash: true,
slashOptions: [
{
- type: 'USER',
name: 'user',
- description: 'Who would you like to ban?',
+ description: 'What user would you like to ban?',
+ type: 'USER',
required: true
},
{
- type: 'STRING',
name: 'reason',
- description: 'Why are they getting banned?',
+ description: 'Why should this user be banned and for how long?',
+ type: 'STRING',
required: false
+ },
+ {
+ name: 'days',
+ description: "How many days of the user's messages would you like to delete?",
+ type: 'INTEGER',
+ required: false,
+ choices: [
+ { name: '0', value: 0 },
+ { name: '1', value: 1 },
+ { name: '2', value: 2 },
+ { name: '3', value: 3 },
+ { name: '4', value: 4 },
+ { name: '5', value: 5 },
+ { name: '6', value: 6 },
+ { name: '7', value: 7 }
+ ]
}
],
- slash: true
+ channel: 'guild',
+ clientPermissions: ['BAN_MEMBERS'],
+ userPermissions: ['BAN_MEMBERS']
});
}
- // async *genResponses(
- // message: Message | CommandInteraction,
- // user: User,
- // reason?: string,
- // time?: number
- // ): AsyncIterable<string> {
- // const duration = moment.duration();
- // let modLogEntry: ModLog;
- // let banEntry: Ban;
- // // const translatedTime: string[] = [];
- // // Create guild entry so postgres doesn't get mad when I try and add a modlog entry
- // await Guild.findOrCreate({
- // where: {
- // id: message.guild.id
- // },
- // defaults: {
- // id: message.guild.id
- // }
- // });
- // try {
- // if (time) {
- // duration.add(time);
- // /* const parsed = [...time.matchAll(durationRegex)];
- // if (parsed.length < 1) {
- // yield `${this.client.util.emojis.error} Invalid time.`;
- // return;
- // }
- // for (const part of parsed) {
- // 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');
- // } */
- // modLogEntry = ModLog.build({
- // user: user.id,
- // guild: message.guild.id,
- // reason,
- // type: ModLogType.TEMP_BAN,
- // duration: duration.asMilliseconds(),
- // moderator: message instanceof CommandInteraction ? message.user.id : message.author.id
- // });
- // banEntry = Ban.build({
- // user: user.id,
- // guild: message.guild.id,
- // reason,
- // expires: new Date(new Date().getTime() + duration.asMilliseconds()),
- // modlog: modLogEntry.id
- // });
- // } else {
- // modLogEntry = ModLog.build({
- // user: user.id,
- // guild: message.guild.id,
- // reason,
- // type: ModLogType.BAN,
- // moderator: message instanceof CommandInteraction ? message.user.id : message.author.id
- // });
- // banEntry = Ban.build({
- // user: user.id,
- // guild: message.guild.id,
- // reason,
- // modlog: modLogEntry.id
- // });
- // }
- // await modLogEntry.save();
- // await banEntry.save();
-
- // try {
- // await user.send(
- // `You were banned in ${message.guild.name} ${duration ? duration.humanize() : 'permanently'} with reason \`${
- // reason || 'No reason given'
- // }\``
- // );
- // } catch {
- // yield `${this.client.util.emojis.warn} Unable to dm 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'
- // }`
- // });
- // yield `${this.client.util.emojis.success} Banned <@!${user.id}> ${
- // duration ? duration.humanize() : 'permanently'
- // } with reason \`${reason || 'No reason given'}\``;
- // } catch {
- // yield `${this.client.util.emojis.error} Error banning :/`;
- // await banEntry.destroy();
- // await modLogEntry.destroy();
- // return;
- // }
- // }
async exec(
message: BushMessage | BushSlashMessage,
- { user, reason, time }: { user: User; reason?: string; time?: number | string }
+ { user, reason, days }: { user: User; reason?: { duration: number; contentWithoutTime: string }; days?: number }
): Promise<unknown> {
- return message.util.reply(`${this.client.util.emojis.error} This command is not finished.`);
+ const member = message.guild.members.cache.get(user.id) as BushGuildMember;
+ const canModerateResponse = this.client.util.moderationPermissionCheck(message.member, member, 'ban');
+
+ if (canModerateResponse !== true) {
+ return message.util.reply(canModerateResponse);
+ }
+
+ if (!Number.isInteger(days) || days < 0 || days > 7) {
+ return message.util.reply(`${this.client.util.emojis.error} The delete days must be an integer between 0 and 7.`);
+ }
+
+ let time: number;
+ if (reason) {
+ time =
+ typeof reason === 'string'
+ ? await Argument.cast('duration', this.client.commandHandler.resolver, message as BushMessage, reason)
+ : reason.duration;
+ }
+ const parsedReason = reason.contentWithoutTime;
+
+ const response = await member.bushBan({
+ reason: parsedReason,
+ moderator: message.author,
+ duration: time,
+ deleteDays: days ?? 0
+ });
- // if (typeof time === 'string') {
- // time = (await Argument.cast('duration', this.client.commandHandler.resolver, message, time)) as number;
- // //// time = this.client.commandHandler.resolver.type('duration')
- // }
- // for await (const response of this.genResponses(message, user, reason, time)) {
- // await message.util.send(response);
- // }
+ switch (response) {
+ case 'missing permissions':
+ return message.util.reply(
+ `${this.client.util.emojis.error} Could not ban **${member.user.tag}** because I do not have permissions`
+ );
+ case 'error banning':
+ return message.util.reply(
+ `${this.client.util.emojis.error} An error occurred while trying to ban **${member.user.tag}**.`
+ );
+ case 'error creating ban entry':
+ return message.util.reply(
+ `${this.client.util.emojis.error} While banning **${member.user.tag}**, there was an error creating a ban entry, please report this to my developers.`
+ );
+ case 'error creating modlog entry':
+ return message.util.reply(
+ `${this.client.util.emojis.error} While banning **${member.user.tag}**, there was an error creating a modlog entry, please report this to my developers.`
+ );
+ case 'failed to dm':
+ return message.util.reply(
+ `${this.client.util.emojis.warn} Banned **${member.user.tag}** however I could not send them a dm.`
+ );
+ case 'success':
+ return message.util.reply(`${this.client.util.emojis.success} Successfully banned **${member.user.tag}**.`);
+ }
}
}
diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts
index f960488..d70bbfb 100644
--- a/src/commands/moderation/kick.ts
+++ b/src/commands/moderation/kick.ts
@@ -22,7 +22,7 @@ export default class KickCommand extends BushCommand {
{
id: 'reason',
type: 'string',
- match: 'restContent',
+ match: 'rest',
prompt: {
start: 'Why should this user be kicked?',
retry: '{error} Choose a valid kick reason.',
@@ -33,15 +33,15 @@ export default class KickCommand extends BushCommand {
slash: true,
slashOptions: [
{
- type: 'USER',
name: 'user',
description: 'What user would you like to kick?',
+ type: 'USER',
required: true
},
{
- type: 'STRING',
name: 'reason',
description: 'Why should this user be kicked?',
+ type: 'STRING',
required: false
}
],
@@ -55,7 +55,7 @@ export default class KickCommand extends BushCommand {
const canModerateResponse = this.client.util.moderationPermissionCheck(message.member, member, 'kick');
// const victimBoldTag = `**${member.user.tag}**`;
- if (typeof canModerateResponse !== 'boolean') {
+ if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
}
@@ -63,5 +63,26 @@ export default class KickCommand extends BushCommand {
reason,
moderator: message.author
});
+
+ switch (response) {
+ case 'missing permissions':
+ return message.util.reply(
+ `${this.client.util.emojis.error} Could not kick **${member.user.tag}** because I am missing the \`Kick Members\` permission.`
+ );
+ case 'error kicking':
+ return message.util.reply(
+ `${this.client.util.emojis.error} An error occurred while trying to kick **${member.user.tag}**.`
+ );
+ case 'error creating modlog entry':
+ return message.util.reply(
+ `${this.client.util.emojis.error} While muting **${member.user.tag}**, there was an error creating a modlog entry, please report this to my developers.`
+ );
+ case 'failed to dm':
+ return message.util.reply(
+ `${this.client.util.emojis.warn} Kicked **${member.user.tag}** however I could not send them a dm.`
+ );
+ case 'success':
+ return message.util.reply(`${this.client.util.emojis.success} Successfully kicked **${member.user.tag}**.`);
+ }
}
}
diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts
index 26ccb21..0eae547 100644
--- a/src/commands/moderation/mute.ts
+++ b/src/commands/moderation/mute.ts
@@ -34,15 +34,15 @@ export default class MuteCommand extends BushCommand {
slash: true,
slashOptions: [
{
- type: 'USER',
name: 'user',
description: 'What user would you like to mute?',
+ type: 'USER',
required: true
},
{
- type: 'STRING',
name: 'reason',
description: 'Why should this user be muted and for how long?',
+ type: 'STRING',
required: false
}
],
@@ -60,7 +60,7 @@ export default class MuteCommand extends BushCommand {
const canModerateResponse = this.client.util.moderationPermissionCheck(message.member, member, 'mute');
const victimBoldTag = `**${member.user.tag}**`;
- if (typeof canModerateResponse !== 'boolean') {
+ if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
}
diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts
index 33f474e..29913d5 100644
--- a/src/commands/moderation/role.ts
+++ b/src/commands/moderation/role.ts
@@ -4,7 +4,7 @@ import { AllowedMentions, BushCommand, BushGuildMember, BushMessage, BushRole, B
export default class RoleCommand extends BushCommand {
public constructor() {
super('role', {
- aliases: ['role', 'addrole', 'removerole'],
+ aliases: ['role'],
category: 'moderation',
description: {
content: "Manages users' roles.",
@@ -69,7 +69,6 @@ export default class RoleCommand extends BushCommand {
start: `What user do you want to ${action} the role ${action2}?`,
retry: `{error} Choose a valid user to ${action} the role ${action2}.`
}
- //unordered: true
};
const role = yield {
id: 'role',
@@ -87,7 +86,7 @@ export default class RoleCommand extends BushCommand {
message: BushMessage | BushSlashMessage,
{ action, user, role }: { action: 'add' | 'remove'; user: BushGuildMember; role: BushRole }
): Promise<unknown> {
- if (!message.member.permissions.has('MANAGE_ROLES') && !this.client.ownerID.includes(message.author.id)) {
+ if (!message.member.permissions.has('MANAGE_ROLES') && !message.author.isOwner()) {
const mappings = this.client.consts.mappings;
let mappedRole: { name: string; id: string };
for (let i = 0; i < mappings.roleMap.length; i++) {
@@ -112,8 +111,7 @@ export default class RoleCommand extends BushCommand {
allowedMentions: AllowedMentions.none()
});
}
- }
- if (!this.client.ownerID.includes(message.author.id)) {
+ } else if (!message.author.isOwner()) {
if (role.comparePositionTo(message.member.roles.highest) >= 0) {
return await message.util.reply({
content: `${this.client.util.emojis.error} <@&${role.id}> is higher or equal to your highest role.`,
@@ -127,7 +125,7 @@ export default class RoleCommand extends BushCommand {
});
}
if (role.managed) {
- await await message.util.reply({
+ return await message.util.reply({
content: `${this.client.util.emojis.error} <@&${role.id}> is managed by an integration and cannot be managed.`,
allowedMentions: AllowedMentions.none()
});
@@ -138,7 +136,7 @@ export default class RoleCommand extends BushCommand {
const success = await user.roles.remove(role.id).catch(() => {});
if (success) {
return await message.util.reply({
- content: `${this.client.util.emojis.success}Successfully removed <@&${role.id}> from <@${user.id}>!`,
+ content: `${this.client.util.emojis.success} Successfully removed <@&${role.id}> from <@${user.id}>!`,
allowedMentions: AllowedMentions.none()
});
} else {
diff --git a/src/commands/moderation/unban.ts b/src/commands/moderation/unban.ts
new file mode 100644
index 0000000..4f52666
--- /dev/null
+++ b/src/commands/moderation/unban.ts
@@ -0,0 +1,85 @@
+import { BushCommand, BushMessage, BushSlashMessage } from '@lib';
+import { User } from 'discord.js';
+
+export default class UnbanCommand extends BushCommand {
+ public constructor() {
+ super('unban', {
+ aliases: ['unban'],
+ category: 'moderation',
+ description: {
+ content: 'Unban a member from the server.',
+ usage: 'unban <member> <reason> [--delete ]',
+ examples: ['unban 322862723090219008 I changed my mind, commands are allowed in #general']
+ },
+ args: [
+ {
+ id: 'user',
+ type: 'user',
+ prompt: {
+ start: 'What user would you like to unban?',
+ retry: '{error} Choose a valid user to unban.'
+ }
+ },
+ {
+ id: 'reason',
+ type: 'string',
+ match: 'restContent',
+ prompt: {
+ start: 'Why should this user be unbanned?',
+ retry: '{error} Choose a valid unban reason.',
+ optional: true
+ }
+ }
+ ],
+ slash: true,
+ slashOptions: [
+ {
+ name: 'user',
+ description: 'What user would you like to unban?',
+ type: 'USER',
+ required: true
+ },
+ {
+ name: 'reason',
+ description: 'Why should this user be unbanned?',
+ type: 'STRING',
+ required: false
+ }
+ ],
+ channel: 'guild',
+ clientPermissions: ['BAN_MEMBERS'],
+ userPermissions: ['BAN_MEMBERS']
+ });
+ }
+ async exec(message: BushMessage | BushSlashMessage, { user, reason }: { user: User; reason?: string }): Promise<unknown> {
+ if (!(user instanceof User)) {
+ user = this.client.util.resolveUser(user, this.client.users.cache);
+ }
+ const response = await message.guild.unban({
+ user,
+ moderator: message.author,
+ reason
+ });
+
+ switch (response) {
+ case 'missing permissions':
+ return message.util.reply(
+ `${this.client.util.emojis.error} Could not unban **${user.tag}** because I do not have permissions`
+ );
+ case 'error unbanning':
+ return message.util.reply(`${this.client.util.emojis.error} An error occurred while trying to unban **${user.tag}**.`);
+ case 'error removing ban entry':
+ return message.util.reply(
+ `${this.client.util.emojis.error} While unbanning **${user.tag}**, there was an error removing their ban entry, please report this to my developers.`
+ );
+ case 'error creating modlog entry':
+ return message.util.reply(
+ `${this.client.util.emojis.error} While unbanning **${user.tag}**, there was an error creating a modlog entry, please report this to my developers.`
+ );
+ case 'user not banned':
+ return message.util.reply(`${this.client.util.emojis.warn} **${user.tag}** but I tried to unban them anyways.`);
+ case 'success':
+ return message.util.reply(`${this.client.util.emojis.success} Successfully unbanned **${user.tag}**.`);
+ }
+ }
+}
diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts
new file mode 100644
index 0000000..4030fb7
--- /dev/null
+++ b/src/commands/moderation/unmute.ts
@@ -0,0 +1,109 @@
+import { BushCommand, BushGuildMember, BushMessage, BushSlashMessage, BushUser } from '@lib';
+
+export default class UnmuteCommand extends BushCommand {
+ public constructor() {
+ super('unmute', {
+ aliases: ['unmute'],
+ category: 'moderation',
+ description: {
+ content: 'unmute a user.',
+ usage: 'unmute <member> [reason] [duration]',
+ examples: ['unmute 322862723090219008 1 day commands in #general']
+ },
+ args: [
+ {
+ id: 'user',
+ type: 'user',
+ prompt: {
+ start: 'What user would you like to unmute?',
+ retry: '{error} Choose a valid user to unmute.'
+ }
+ },
+ {
+ id: 'reason',
+ type: 'string',
+ match: 'rest',
+ prompt: {
+ start: 'Why should this user be unmuted?',
+ retry: '{error} Choose a valid unmute reason.',
+ optional: true
+ }
+ }
+ ],
+ slash: true,
+ slashOptions: [
+ {
+ name: 'user',
+ description: 'What user would you like to unmute?',
+ type: 'USER',
+ required: true
+ },
+ {
+ name: 'reason',
+ description: 'Why should this user be unmuted?',
+ type: 'STRING',
+ required: false
+ }
+ ],
+ channel: 'guild',
+ clientPermissions: ['SEND_MESSAGES', 'MANAGE_ROLES'],
+ userPermissions: ['MANAGE_MESSAGES']
+ });
+ }
+ async exec(message: BushMessage | BushSlashMessage, { user, reason }: { user: BushUser; reason?: string }): Promise<unknown> {
+ const error = this.client.util.emojis.error;
+ const member = message.guild.members.cache.get(user.id) as BushGuildMember;
+ const canModerateResponse = this.client.util.moderationPermissionCheck(message.member, member, 'unmute');
+ const victimBoldTag = `**${member.user.tag}**`;
+
+ if (canModerateResponse !== true) {
+ return message.util.reply(canModerateResponse);
+ }
+
+ const response = await member.unmute({
+ reason,
+ moderator: message.author
+ });
+
+ switch (response) {
+ case 'missing permissions':
+ return message.util.reply(
+ `${error} Could not unmute ${victimBoldTag} because I am missing the \`Manage Roles\` permission.`
+ );
+ case 'no mute role':
+ return message.util.reply(
+ `${error} Could not unmute ${victimBoldTag}, you must set a mute role with \`${message.guild.getSetting(
+ 'prefix'
+ )}muterole\`.`
+ );
+ case 'invalid mute role':
+ return message.util.reply(
+ `${error} Could not unmute ${victimBoldTag} because the current mute role no longer exists. Please set a new mute role with \`${message.guild.getSetting(
+ 'prefix'
+ )}muterole\`.`
+ );
+ case 'mute role not manageable':
+ return message.util.reply(
+ `${error} Could not unmute ${victimBoldTag} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${message.guild.getSetting(
+ 'prefix'
+ )}muterole\`.`
+ );
+ case 'error removing mute role':
+ return message.util.reply(`${error} Could not unmute ${victimBoldTag}, there was an error removing their mute role.`);
+ case 'error creating modlog entry':
+ return message.util.reply(
+ `${error} While muting ${victimBoldTag}, there was an error creating a modlog entry, please report this to my developers.`
+ );
+ case 'error removing mute entry':
+ return message.util.reply(
+ `${error} While muting ${victimBoldTag}, there was an error removing their mute entry, please report this to my developers.`
+ );
+ case 'failed to dm':
+ return message.util.reply(
+ `${this.client.util.emojis.warn} unmuted **${member.user.tag}** however I could not send them a dm.`
+ );
+ case 'success':
+ return message.util.reply(`${this.client.util.emojis.success} Successfully unmuted **${member.user.tag}**.`);
+ }
+ }
+}
diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts
index 5d679ab..3d353ca 100644
--- a/src/commands/moderation/warn.ts
+++ b/src/commands/moderation/warn.ts
@@ -33,15 +33,15 @@ export default class WarnCommand extends BushCommand {
slash: true,
slashOptions: [
{
- type: 'USER',
name: 'user',
description: 'What user would you like to warn?',
+ type: 'USER',
required: true
},
{
- type: 'STRING',
name: 'reason',
description: 'Why should this user be warned?',
+ type: 'STRING',
required: false
}
],
@@ -58,7 +58,7 @@ export default class WarnCommand extends BushCommand {
const canModerateResponse = this.client.util.moderationPermissionCheck(message.member, member, 'warn');
const victimBoldTag = `**${member.user.tag}**`;
- if (typeof canModerateResponse !== 'boolean') {
+ if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
}