aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moderation
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-10-21 23:35:13 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-10-21 23:35:13 -0400
commit44521f4560dc8b0bab055685437d8fa65a34377f (patch)
tree4750c8cf696a2489964edc409e640f6792ed92b6 /src/commands/moderation
parenta8b3f2d258d6ef19aeff2c9d60d6b08a91277b2b (diff)
downloadtanzanite-44521f4560dc8b0bab055685437d8fa65a34377f.tar.gz
tanzanite-44521f4560dc8b0bab055685437d8fa65a34377f.tar.bz2
tanzanite-44521f4560dc8b0bab055685437d8fa65a34377f.zip
misc
Diffstat (limited to 'src/commands/moderation')
-rw-r--r--src/commands/moderation/ban.ts18
-rw-r--r--src/commands/moderation/hideCase.ts6
-rw-r--r--src/commands/moderation/kick.ts11
-rw-r--r--src/commands/moderation/modlog.ts2
-rw-r--r--src/commands/moderation/mute.ts61
-rw-r--r--src/commands/moderation/role.ts23
-rw-r--r--src/commands/moderation/slowmode.ts2
-rw-r--r--src/commands/moderation/unban.ts13
-rw-r--r--src/commands/moderation/unmute.ts28
-rw-r--r--src/commands/moderation/warn.ts31
10 files changed, 90 insertions, 105 deletions
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts
index b3d97d2..74b1b54 100644
--- a/src/commands/moderation/ban.ts
+++ b/src/commands/moderation/ban.ts
@@ -118,10 +118,7 @@ export default class BanCommand extends BushCommand {
let time: number;
if (reason) {
- time =
- typeof reason === 'string'
- ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, reason)
- : reason.duration;
+ time = typeof reason === 'string' ? await util.arg.cast('duration', message, reason) : reason.duration;
}
const parsedReason = reason?.contentWithoutTime ?? null;
@@ -141,19 +138,20 @@ export default class BanCommand extends BushCommand {
});
const responseMessage = () => {
+ const victim = util.format.bold(user.tag);
switch (responseCode) {
case 'missing permissions':
- return `${util.emojis.error} Could not ban **${user.tag}** because I do not have permissions`;
+ return `${util.emojis.error} Could not ban ${victim} because I am missing the **Ban Members** permission.`;
case 'error banning':
- return `${util.emojis.error} An error occurred while trying to ban **${user.tag}**.`;
+ return `${util.emojis.error} An error occurred while trying to ban ${victim}.`;
case 'error creating ban entry':
- return `${util.emojis.error} While banning **${user.tag}**, there was an error creating a ban entry, please report this to my developers.`;
+ return `${util.emojis.error} While banning ${victim}, 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 **${user.tag}**, there was an error creating a modlog entry, please report this to my developers.`;
+ return `${util.emojis.error} While banning ${victim}, there was an error creating a modlog entry, please report this to my developers.`;
case 'failed to dm':
- return `${util.emojis.warn} Banned **${user.tag}** however I could not send them a dm.`;
+ return `${util.emojis.warn} Banned ${victim} however I could not send them a dm.`;
case 'success':
- return `${util.emojis.success} Successfully banned **${user.tag}**.`;
+ return `${util.emojis.success} Successfully banned ${victim}.`;
}
};
return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() });
diff --git a/src/commands/moderation/hideCase.ts b/src/commands/moderation/hideCase.ts
index 38cfe31..981a8bc 100644
--- a/src/commands/moderation/hideCase.ts
+++ b/src/commands/moderation/hideCase.ts
@@ -20,8 +20,6 @@ export default class HideCaseCommand extends BushCommand {
}
}
],
- clientPermissions: (m) => util.clientSendAndPermCheck(m),
- userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']),
slash: true,
slashOptions: [
{
@@ -31,6 +29,8 @@ export default class HideCaseCommand extends BushCommand {
required: true
}
],
+ clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']),
channel: 'guild'
});
}
@@ -39,8 +39,6 @@ export default class HideCaseCommand extends BushCommand {
message: BushMessage | BushSlashMessage,
{ case_id: caseID }: { case_id: string }
): Promise<unknown> {
- if (message.author.id === '496409778822709251')
- return await message.util.reply(`${util.emojis.error} This command is Bestower proof.`);
const entry = await ModLog.findByPk(caseID);
if (!entry || entry.pseudo) return message.util.send(`${util.emojis.error} Invalid entry.`);
if (entry.guild !== message.guild!.id)
diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts
index 9bd5658..3238217 100644
--- a/src/commands/moderation/kick.ts
+++ b/src/commands/moderation/kick.ts
@@ -80,17 +80,18 @@ export default class KickCommand extends BushCommand {
});
const responseMessage = () => {
+ const victim = util.format.bold(member.user.tag);
switch (responseCode) {
case 'missing permissions':
- return `${util.emojis.error} Could not kick **${member.user.tag}** because I am missing the \`Kick Members\` permission.`;
+ return `${util.emojis.error} Could not kick ${victim} because I am missing the \`Kick Members\` permission.`;
case 'error kicking':
- return `${util.emojis.error} An error occurred while trying to kick **${member.user.tag}**.`;
+ return `${util.emojis.error} An error occurred while trying to kick ${victim}.`;
case 'error creating modlog entry':
- return `${util.emojis.error} While muting **${member.user.tag}**, there was an error creating a modlog entry, please report this to my developers.`;
+ return `${util.emojis.error} While muting ${victim}, there was an error creating a modlog entry, please report this to my developers.`;
case 'failed to dm':
- return `${util.emojis.warn} Kicked **${member.user.tag}** however I could not send them a dm.`;
+ return `${util.emojis.warn} Kicked ${victim} however I could not send them a dm.`;
case 'success':
- return `${util.emojis.success} Successfully kicked **${member.user.tag}**.`;
+ return `${util.emojis.success} Successfully kicked ${victim}.`;
}
};
return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() });
diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts
index eb37681..4abaa6f 100644
--- a/src/commands/moderation/modlog.ts
+++ b/src/commands/moderation/modlog.ts
@@ -50,7 +50,7 @@ export default class ModlogCommand extends BushCommand {
#generateModlogInfo(log: ModLog, showUser: boolean): string {
const trim = (str: string): string => (str.endsWith('\n') ? str.substring(0, str.length - 1).trim() : str.trim());
- const modLog = [`**Case ID**: ${util.discord.escapeItalic(log.id)}`, `**Type**: ${log.type.toLowerCase()}`];
+ const modLog = [`**Case ID**: ${util.discord.escapeMarkdown(log.id)}`, `**Type**: ${log.type.toLowerCase()}`];
if (showUser) modLog.push(`**User**: <@!${log.user}>`);
modLog.push(`**Moderator**: <@!${log.moderator}>`);
if (log.duration) modLog.push(`**Duration**: ${util.humanizeDuration(log.duration)}`);
diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts
index 03ecf2a..00631ba 100644
--- a/src/commands/moderation/mute.ts
+++ b/src/commands/moderation/mute.ts
@@ -30,11 +30,7 @@ export default class MuteCommand extends BushCommand {
optional: true
}
},
- {
- id: 'force',
- flag: '--force',
- match: 'flag'
- }
+ { id: 'force', flag: '--force', match: 'flag' }
],
slash: true,
slashOptions: [
@@ -59,66 +55,67 @@ export default class MuteCommand extends BushCommand {
public override async exec(
message: BushMessage | BushSlashMessage,
- {
- user,
- reason,
- force
- }: { user: BushUser; reason?: { duration: number | null; contentWithoutTime: string }; force: boolean }
+ args: { user: BushUser; reason?: { duration: number | null; contentWithoutTime: string } | string; force: boolean }
): Promise<unknown> {
- if (reason?.duration === null) reason.duration = 0;
- const member = await message.guild!.members.fetch(user.id).catch(() => null);
+ const reason: { duration: number | null; contentWithoutTime: string } = args.reason
+ ? typeof args.reason === 'string'
+ ? await util.arg.cast('contentWithDuration', message, args.reason)
+ : args.reason
+ : { duration: null, contentWithoutTime: '' };
+
+ if (reason.duration === null) reason.duration = 0;
+ const member = await message.guild!.members.fetch(args.user.id).catch(() => null);
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 useForce = args.force && message.author.isOwner();
const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'mute', true, useForce);
- const victimBoldTag = `**${member.user.tag}**`;
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
}
- let time: number;
- if (reason) {
- time =
- typeof reason === 'string'
- ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, reason)
- : reason.duration;
- }
+ const time = reason
+ ? typeof reason === 'string'
+ ? ((await util.arg.cast('duration', message, reason)) as number)
+ : reason.duration
+ : undefined;
+
const parsedReason = reason?.contentWithoutTime ?? '';
const responseCode = await member.mute({
reason: parsedReason,
moderator: message.member,
- duration: time! ?? 0
+ duration: time ?? 0
});
- const responseMessage = async () => {
- const prefix = await message.guild!.getSetting('prefix');
+ const responseMessage = () => {
+ const prefix = util.prefix(message);
+ const victim = util.format.bold(member.user.tag);
switch (responseCode) {
case 'missing permissions':
- return `${util.emojis.error} Could not mute ${victimBoldTag} because I am missing the **Manage Roles** permission.`;
+ return `${util.emojis.error} Could not mute ${victim} because I am missing the **Manage Roles** permission.`;
case 'no mute role':
- return `${util.emojis.error} Could not mute ${victimBoldTag}, you must set a mute role with \`${prefix}config muteRole\`.`;
+ return `${util.emojis.error} Could not mute ${victim}, you must set a mute role with \`${prefix}config muteRole\`.`;
case 'invalid mute role':
- return `${util.emojis.error} Could not mute ${victimBoldTag} because the current mute role no longer exists. Please set a new mute role with \`${prefix}config muteRole\`.`;
+ return `${util.emojis.error} Could not mute ${victim} because the current mute role no longer exists. Please set a new mute role with \`${prefix}config muteRole\`.`;
case 'mute role not manageable':
- return `${util.emojis.error} Could not mute ${victimBoldTag} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix}config muteRole\`.`;
+ return `${util.emojis.error} Could not mute ${victim} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix}config muteRole\`.`;
case 'error giving mute role':
- return `${util.emojis.error} Could not mute ${victimBoldTag}, there was an error assigning them the mute role.`;
+ return `${util.emojis.error} Could not mute ${victim}, there was an error assigning them the mute role.`;
case 'error creating modlog entry':
return `${util.emojis.error} There was an error creating a modlog entry, please report this to my developers.`;
case 'error creating mute entry':
return `${util.emojis.error} There was an error creating a punishment entry, please report this to my developers.`;
case 'failed to dm':
- return `${util.emojis.warn} Muted **${member.user.tag}** however I could not send them a dm.`;
+ return `${util.emojis.warn} Muted ${victim} however I could not send them a dm.`;
case 'success':
- return `${util.emojis.success} Successfully muted **${member.user.tag}**.`;
+ return `${util.emojis.success} Successfully muted ${victim}.`;
}
};
- return await message.util.reply({ content: await responseMessage(), allowedMentions: AllowedMentions.none() });
+ return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() });
}
}
diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts
index fe34d75..d6a85af 100644
--- a/src/commands/moderation/role.ts
+++ b/src/commands/moderation/role.ts
@@ -18,14 +18,8 @@ export default class RoleCommand extends BushCommand {
description: 'Would you like to add or remove a role?',
type: 'STRING',
choices: [
- {
- name: 'add',
- value: 'add'
- },
- {
- name: 'remove',
- value: 'remove'
- }
+ { name: 'add', value: 'add' },
+ { name: 'remove', value: 'remove' }
],
required: true
},
@@ -97,7 +91,7 @@ export default class RoleCommand extends BushCommand {
message: BushMessage | BushSlashMessage,
{
action,
- user,
+ user: member,
role,
duration
}: { action: 'add' | 'remove'; user: BushGuildMember; role: BushRole; duration?: number | null }
@@ -114,7 +108,7 @@ export default class RoleCommand extends BushCommand {
const a = mappings.roleMap[i];
if (a.id == role.id) mappedRole = a;
}
- if (!mappedRole! || !mappings.roleWhitelist[mappedRole.name as keyof typeof mappings.roleWhitelist]) {
+ if (!mappedRole! || !Reflect.has(mappings.roleWhitelist, mappedRole.name)) {
return await message.util.reply({
content: `${util.emojis.error} <@&${role.id}> is not whitelisted, and you do not have manage roles permission.`,
allowedMentions: AllowedMentions.none()
@@ -138,10 +132,11 @@ export default class RoleCommand extends BushCommand {
const responseCode =
action === 'add'
- ? await user.addRole({ moderator: message.member!, addToModlog: shouldLog, role, duration })
- : await user.removeRole({ moderator: message.member!, addToModlog: shouldLog, role, duration });
+ ? await member.addRole({ moderator: message.member!, addToModlog: shouldLog, role, duration })
+ : await member.removeRole({ moderator: message.member!, addToModlog: shouldLog, role, duration });
const responseMessage = () => {
+ const victim = util.format.bold(member.user.tag);
switch (responseCode) {
case 'user hierarchy':
return `${util.emojis.error} <@&${role.id}> is higher or equal to your highest role.`;
@@ -158,11 +153,11 @@ export default class RoleCommand extends BushCommand {
case 'error adding role' || 'error removing role':
return `${util.emojis.error} An error occurred while trying to ${action} <@&${role.id}> ${
action === 'add' ? 'to' : 'from'
- } **${user.user.tag}**.`;
+ } ${victim}.`;
case 'success':
return `${util.emojis.success} Successfully ${action === 'add' ? 'added' : 'removed'} <@&${role.id}> ${
action === 'add' ? 'to' : 'from'
- } **${user.user.tag}**${duration ? ` for ${util.humanizeDuration(duration)}` : ''}.`;
+ } ${victim}${duration ? ` for ${util.humanizeDuration(duration)}` : ''}.`;
}
};
diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts
index d90f122..75d795c 100644
--- a/src/commands/moderation/slowmode.ts
+++ b/src/commands/moderation/slowmode.ts
@@ -65,7 +65,7 @@ export default class SlowModeCommand extends BushCommand {
if (length) {
length =
typeof length === 'string' && !['off', 'none', 'disable'].includes(length)
- ? await util.arg.cast('duration', client.commandHandler.resolver, message as BushMessage, length)
+ ? await util.arg.cast('duration', message, length)
: length;
}
diff --git a/src/commands/moderation/unban.ts b/src/commands/moderation/unban.ts
index 61e27cf..9d52dd2 100644
--- a/src/commands/moderation/unban.ts
+++ b/src/commands/moderation/unban.ts
@@ -61,19 +61,20 @@ export default class UnbanCommand extends BushCommand {
});
const responseMessage = () => {
+ const victim = util.format.bold(user.tag);
switch (responseCode) {
case 'missing permissions':
- return `${util.emojis.error} Could not unban **${user.tag}** because I do not have permissions`;
+ return `${util.emojis.error} Could not unban ${victim} because I am missing the **Ban Members** permission.`;
case 'error unbanning':
- return `${util.emojis.error} An error occurred while trying to unban **${user.tag}**.`;
+ return `${util.emojis.error} An error occurred while trying to unban ${victim}.`;
case 'error removing ban entry':
- return `${util.emojis.error} While unbanning **${user.tag}**, there was an error removing their ban entry, please report this to my developers.`;
+ return `${util.emojis.error} While unbanning ${victim}, there was an error removing their ban entry, please report this to my developers.`;
case 'error creating modlog entry':
- return `${util.emojis.error} While unbanning **${user.tag}**, there was an error creating a modlog entry, please report this to my developers.`;
+ return `${util.emojis.error} While unbanning ${victim}, there was an error creating a modlog entry, please report this to my developers.`;
case 'user not banned':
- return `${util.emojis.warn} **${user.tag}** is not banned but I tried to unban them anyways.`;
+ return `${util.emojis.warn} ${victim} is not banned but I tried to unban them anyways.`;
case 'success':
- return `${util.emojis.success} Successfully unbanned **${user.tag}**.`;
+ return `${util.emojis.success} Successfully unbanned ${victim}.`;
}
};
return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() });
diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts
index e430b83..f9335c4 100644
--- a/src/commands/moderation/unmute.ts
+++ b/src/commands/moderation/unmute.ts
@@ -67,11 +67,8 @@ export default class UnmuteCommand extends BushCommand {
if (!message.member) throw new Error(`message.member is null`);
const useForce = force && message.author.isOwner();
-
const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'unmute', true, useForce);
- const victimBoldTag = `**${member.user.tag}**`;
-
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
}
@@ -81,29 +78,30 @@ export default class UnmuteCommand extends BushCommand {
moderator: message.member
});
- const responseMessage = async () => {
- const prefix = await message.guild!.getSetting('prefix');
+ const responseMessage = () => {
+ const prefix = util.prefix(message);
+ const victim = util.format.bold(member.user.tag);
switch (responseCode) {
case 'missing permissions':
- return `${error} Could not unmute ${victimBoldTag} because I am missing the \`Manage Roles\` permission.`;
+ return `${error} Could not unmute ${victim} because I am missing the **Manage Roles** permission.`;
case 'no mute role':
- return `${error} Could not unmute ${victimBoldTag}, you must set a mute role with \`${prefix}muterole\`.`;
+ return `${error} Could not unmute ${victim}, you must set a mute role with \`${prefix}config muteRole\`.`;
case 'invalid mute role':
- return `${error} Could not unmute ${victimBoldTag} because the current mute role no longer exists. Please set a new mute role with \`${prefix}muterole\`.`;
+ return `${error} Could not unmute ${victim} because the current mute role no longer exists. Please set a new mute role with \`${prefix}config muteRole\`.`;
case 'mute role not manageable':
- return `${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 \`${prefix}muterole\`.`;
+ return `${error} Could not unmute ${victim} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix}config muteRole\`.`;
case 'error removing mute role':
- return `${error} Could not unmute ${victimBoldTag}, there was an error removing their mute role.`;
+ return `${error} Could not unmute ${victim}, there was an error removing their mute role.`;
case 'error creating modlog entry':
- return `${error} While muting ${victimBoldTag}, there was an error creating a modlog entry, please report this to my developers.`;
+ return `${error} While muting ${victim}, there was an error creating a modlog entry, please report this to my developers.`;
case 'error removing mute entry':
- return `${error} While muting ${victimBoldTag}, there was an error removing their mute entry, please report this to my developers.`;
+ return `${error} While muting ${victim}, there was an error removing their mute entry, please report this to my developers.`;
case 'failed to dm':
- return `${util.emojis.warn} unmuted **${member.user.tag}** however I could not send them a dm.`;
+ return `${util.emojis.warn} unmuted ${victim} however I could not send them a dm.`;
case 'success':
- return `${util.emojis.success} Successfully unmuted **${member.user.tag}**.`;
+ return `${util.emojis.success} Successfully unmuted ${victim}.`;
}
};
- return await message.util.reply({ content: await responseMessage(), allowedMentions: AllowedMentions.none() });
+ return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() });
}
}
diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts
index 6ae8442..c67466b 100644
--- a/src/commands/moderation/warn.ts
+++ b/src/commands/moderation/warn.ts
@@ -1,4 +1,4 @@
-import { BushCommand, BushGuildMember, BushMessage, BushSlashMessage, BushUser } from '@lib';
+import { AllowedMentions, BushCommand, BushGuildMember, BushMessage, BushSlashMessage, BushUser } from '@lib';
import { Moderation } from '../../lib/common/Moderation';
export default class WarnCommand extends BushCommand {
@@ -65,7 +65,6 @@ export default class WarnCommand extends BushCommand {
const useForce = force && message.author.isOwner();
if (!message.member) throw new Error(`message.member is null`);
const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'warn', true, useForce);
- const victimBoldTag = `**${member.user.tag}**`;
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
@@ -76,21 +75,19 @@ export default class WarnCommand extends BushCommand {
moderator: message.member
});
- switch (response) {
- case 'error creating modlog entry':
- return message.util.reply(
- `${util.emojis.error} While warning ${victimBoldTag}, there was an error creating a modlog entry, please report this to my developers.`
- );
- case 'failed to dm':
- return message.util.reply(
- `${util.emojis.warn} **${member.user.tag}** has been warned for the ${util.ordinal(
+ const responseMessage = () => {
+ const victim = util.format.bold(member.user.tag);
+ switch (response) {
+ case 'error creating modlog entry':
+ return `${util.emojis.error} While warning ${victim}, there was an error creating a modlog entry, please report this to my developers.`;
+ case 'failed to dm':
+ return `${util.emojis.warn} ${victim} has been warned for the ${util.ordinal(
caseNum ?? 0
- )} time, however I could not send them a dm.`
- );
- case 'success':
- return message.util.reply(
- `${util.emojis.success} Successfully warned **${member.user.tag}** for the ${util.ordinal(caseNum ?? 0)} time.`
- );
- }
+ )} time, however I could not send them a dm.`;
+ case 'success':
+ return `${util.emojis.success} Successfully warned ${victim} for the ${util.ordinal(caseNum ?? 0)} time.`;
+ }
+ };
+ return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() });
}
}