aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moderation
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-10-03 22:57:40 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-10-03 22:57:40 -0400
commit612ed820a0600ec11ed642005377cd7f5a8a8b77 (patch)
tree6bca4e7268fd0063ff53cf64fa44df62a23dba50 /src/commands/moderation
parented98ff7e2679f362f2657e77a6cf8dd3ce9b3d43 (diff)
downloadtanzanite-612ed820a0600ec11ed642005377cd7f5a8a8b77.tar.gz
tanzanite-612ed820a0600ec11ed642005377cd7f5a8a8b77.tar.bz2
tanzanite-612ed820a0600ec11ed642005377cd7f5a8a8b77.zip
wip
Diffstat (limited to 'src/commands/moderation')
-rw-r--r--src/commands/moderation/ban.ts4
-rw-r--r--src/commands/moderation/block.ts2
-rw-r--r--src/commands/moderation/evidence.ts2
-rw-r--r--src/commands/moderation/kick.ts2
-rw-r--r--src/commands/moderation/modlog.ts60
-rw-r--r--src/commands/moderation/mute.ts2
-rw-r--r--src/commands/moderation/myLogs.ts12
-rw-r--r--src/commands/moderation/role.ts2
-rw-r--r--src/commands/moderation/slowmode.ts6
-rw-r--r--src/commands/moderation/timeout.ts8
-rw-r--r--src/commands/moderation/unblock.ts8
-rw-r--r--src/commands/moderation/unmute.ts8
-rw-r--r--src/commands/moderation/untimeout.ts8
-rw-r--r--src/commands/moderation/warn.ts2
14 files changed, 85 insertions, 41 deletions
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts
index aee8805..ae77cde 100644
--- a/src/commands/moderation/ban.ts
+++ b/src/commands/moderation/ban.ts
@@ -96,7 +96,9 @@ export default class BanCommand extends BotCommand {
if (!user) return message.util.reply(`${emojis.error} Invalid user.`);
const useForce = args.force && message.author.isOwner();
- const canModerateResponse = member ? await Moderation.permissionCheck(message.member, member, 'ban', true, useForce) : true;
+ const canModerateResponse = member
+ ? await Moderation.permissionCheck(message.member, member, Moderation.Action.Ban, true, useForce)
+ : true;
if (canModerateResponse !== true) {
return await message.util.reply(canModerateResponse);
diff --git a/src/commands/moderation/block.ts b/src/commands/moderation/block.ts
index a5ad31d..da1dec8 100644
--- a/src/commands/moderation/block.ts
+++ b/src/commands/moderation/block.ts
@@ -83,7 +83,7 @@ export default class BlockCommand extends BotCommand {
return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`);
const useForce = args.force && message.author.isOwner();
- const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'block', true, useForce);
+ const canModerateResponse = await Moderation.permissionCheck(message.member, member, Moderation.Action.Block, true, useForce);
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
diff --git a/src/commands/moderation/evidence.ts b/src/commands/moderation/evidence.ts
index 9a5e70f..b7c020a 100644
--- a/src/commands/moderation/evidence.ts
+++ b/src/commands/moderation/evidence.ts
@@ -10,8 +10,8 @@ import {
type CommandMessage,
type SlashMessage
} from '#lib';
+import { Argument, ArgumentGeneratorReturn } from '@notenoughupdates/discord-akairo';
import assert from 'assert/strict';
-import { Argument, ArgumentGeneratorReturn } from 'discord-akairo';
import { ApplicationCommandOptionType, type Message } from 'discord.js';
export default class EvidenceCommand extends BotCommand {
diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts
index 82ddce4..d757e91 100644
--- a/src/commands/moderation/kick.ts
+++ b/src/commands/moderation/kick.ts
@@ -70,7 +70,7 @@ export default class KickCommand extends BotCommand {
if (!member)
return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`);
const useForce = force && message.author.isOwner();
- const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'kick', true, useForce);
+ const canModerateResponse = await Moderation.permissionCheck(message.member, member, Moderation.Action.Kick, true, useForce);
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts
index dcab9ef..649e44f 100644
--- a/src/commands/moderation/modlog.ts
+++ b/src/commands/moderation/modlog.ts
@@ -12,12 +12,11 @@ import {
type CommandMessage,
type SlashMessage
} from '#lib';
+import { embedField } from '#lib/common/tags.js';
import assert from 'assert/strict';
import { ApplicationCommandOptionType, escapeMarkdown, User } from 'discord.js';
export default class ModlogCommand extends BotCommand {
- public static separator = '\n━━━━━━━━━━━━━━━\n';
-
public constructor() {
super('modlog', {
aliases: ['modlog', 'modlogs'],
@@ -62,44 +61,63 @@ export default class ModlogCommand extends BotCommand {
const logs = await ModLog.findAll({
where: {
guild: message.guild.id,
- user: foundUser.id
+ user: foundUser.id,
+ pseudo: false
},
order: [['createdAt', 'ASC']]
});
- const niceLogs = logs
- .filter((log) => !log.pseudo && !(!hidden && log.hidden))
- .map((log) => ModlogCommand.generateModlogInfo(log, false, false));
- if (niceLogs.length < 1) return message.util.reply(`${emojis.error} **${foundUser.tag}** does not have any modlogs.`);
+ const niceLogs = logs.filter((log) => !log.hidden || hidden).map((log) => generateModlogInfo(log, false, false));
+
+ if (niceLogs.length < 1) {
+ return message.util.reply(`${emojis.error} **${foundUser.tag}** does not have any modlogs.`);
+ }
+
const chunked: string[][] = chunk(niceLogs, 4);
const embedPages = chunked.map((chunk) => ({
title: `${foundUser.tag}'s Modlogs`,
- description: chunk.join(ModlogCommand.separator),
+ description: chunk.join(modlogSeparator),
color: colors.default
}));
return await ButtonPaginator.send(message, embedPages, undefined, true);
} else if (search) {
const entry = await ModLog.findByPk(search as string);
- if (!entry || entry.pseudo || (entry.hidden && !hidden))
+
+ if (!entry || entry.pseudo || (entry.hidden && !hidden)) {
return message.util.send(`${emojis.error} That modlog does not exist.`);
- if (entry.guild !== message.guild.id) return message.util.reply(`${emojis.error} This modlog is from another server.`);
+ }
+
+ if (entry.guild !== message.guild.id) {
+ return message.util.reply(`${emojis.error} This modlog is from another server.`);
+ }
+
const embed = {
title: `Case ${entry.id}`,
- description: ModlogCommand.generateModlogInfo(entry, true, false),
+ description: generateModlogInfo(entry, true, false),
color: colors.default
};
return await ButtonPaginator.send(message, [embed]);
}
}
+}
- public static generateModlogInfo(log: ModLog, showUser: boolean, userFacing: boolean): string {
- const trim = (str: string): string => (str.endsWith('\n') ? str.substring(0, str.length - 1).trim() : str.trim());
- const modLog = [`**Case ID:** ${escapeMarkdown(log.id)}`, `**Type:** ${log.type.toLowerCase()}`];
- if (showUser) modLog.push(`**User:** <@!${log.user}>`);
- if (!userFacing) modLog.push(`**Moderator:** <@!${log.moderator}>`);
- if (log.duration) modLog.push(`**Duration:** ${humanizeDuration(log.duration)}`);
- modLog.push(`**Reason:** ${trim(log.reason ?? 'No Reason Specified.')}`);
- modLog.push(`**Date:** ${timestamp(log.createdAt)}`);
- if (log.evidence && !userFacing) modLog.push(`**Evidence:** ${trim(log.evidence)}`);
- return modLog.join(`\n`);
+export const modlogSeparator = '\n━━━━━━━━━━━━━━━\n';
+
+const trim = (str: string): string => {
+ if (str.endsWith('\n')) {
+ return str.substring(0, str.length - 1).trim();
+ } else {
+ return str.trim();
}
+};
+
+export function generateModlogInfo(log: ModLog, showUser: boolean, userFacing: boolean): string {
+ return embedField`
+ Case ID ${escapeMarkdown(log.id)}
+ Type ${log.type.toLowerCase()}
+ User ${showUser && `<@!${log.user}>`}
+ Moderator ${!userFacing && `<@!${log.moderator}>`}
+ Duration ${log.duration && humanizeDuration(log.duration)}
+ Reason ${trim(log.reason ?? 'No Reason Specified.')}
+ Date ${timestamp(log.createdAt)}
+ Evidence ${log.evidence && !userFacing && trim(log.evidence)}`;
}
diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts
index 9ffaf8d..a64dc99 100644
--- a/src/commands/moderation/mute.ts
+++ b/src/commands/moderation/mute.ts
@@ -78,7 +78,7 @@ export default class MuteCommand extends BotCommand {
return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`);
const useForce = args.force && message.author.isOwner();
- const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'mute', true, useForce);
+ const canModerateResponse = await Moderation.permissionCheck(message.member, member, Moderation.Action.Mute, true, useForce);
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
diff --git a/src/commands/moderation/myLogs.ts b/src/commands/moderation/myLogs.ts
index 8faca8c..e3f5f10 100644
--- a/src/commands/moderation/myLogs.ts
+++ b/src/commands/moderation/myLogs.ts
@@ -12,7 +12,7 @@ import {
import { ApplicationCommandOptionType } from 'discord.js';
import { input, sanitizeInputForDiscord } from '../../../lib/utils/Format.js';
-import ModlogCommand from './modlog.js';
+import { generateModlogInfo, modlogSeparator } from './modlog.js';
export default class MyLogsCommand extends BotCommand {
public constructor() {
super('myLogs', {
@@ -50,14 +50,14 @@ export default class MyLogsCommand extends BotCommand {
const logs = await ModLog.findAll({
where: {
guild: guild.id,
- user: message.author.id
+ user: message.author.id,
+ pseudo: false,
+ hidden: false
},
order: [['createdAt', 'ASC']]
});
- const niceLogs = logs
- .filter((log) => !log.pseudo && !log.hidden)
- .map((log) => ModlogCommand.generateModlogInfo(log, false, true));
+ const niceLogs = logs.map((log) => generateModlogInfo(log, false, true));
if (niceLogs.length < 1) return message.util.reply(`${emojis.error} You don't have any modlogs in ${input(guild.name)}.`);
@@ -65,7 +65,7 @@ export default class MyLogsCommand extends BotCommand {
const embedPages = chunked.map((chunk) => ({
title: `Your Modlogs in ${sanitizeInputForDiscord(guild.name)}`,
- description: chunk.join(ModlogCommand.separator),
+ description: chunk.join(modlogSeparator),
color: colors.default
}));
diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts
index 565f214..a664aa4 100644
--- a/src/commands/moderation/role.ts
+++ b/src/commands/moderation/role.ts
@@ -12,8 +12,8 @@ import {
type OptArgType,
type SlashMessage
} from '#lib';
+import { type ArgumentGeneratorReturn } from '@notenoughupdates/discord-akairo';
import assert from 'assert/strict';
-import { type ArgumentGeneratorReturn } from 'discord-akairo';
import { ApplicationCommandOptionType, PermissionFlagsBits, type Snowflake } from 'discord.js';
export default class RoleCommand extends BotCommand {
diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts
index 82d0264..1256d1f 100644
--- a/src/commands/moderation/slowmode.ts
+++ b/src/commands/moderation/slowmode.ts
@@ -1,6 +1,6 @@
import { Arg, BotCommand, emojis, format, humanizeDuration, type CommandMessage, type OptArgType, type SlashMessage } from '#lib';
+import { Argument } from '@notenoughupdates/discord-akairo';
import assert from 'assert/strict';
-import { Argument } from 'discord-akairo';
import { ApplicationCommandOptionType, ChannelType } from 'discord.js';
export default class SlowmodeCommand extends BotCommand {
@@ -30,7 +30,7 @@ export default class SlowmodeCommand extends BotCommand {
retry: '{error} Choose a valid channel.',
optional: true,
slashType: ApplicationCommandOptionType.Channel,
- channelTypes: [ChannelType.GuildText, ChannelType.GuildPrivateThread, ChannelType.GuildPublicThread]
+ channelTypes: [ChannelType.GuildText, ChannelType.PrivateThread, ChannelType.PublicThread]
}
],
slash: true,
@@ -55,7 +55,7 @@ export default class SlowmodeCommand extends BotCommand {
if (
args.channel.type !== ChannelType.GuildText &&
- args.channel.type !== ChannelType.GuildNews &&
+ args.channel.type !== ChannelType.GuildAnnouncement &&
args.channel.type !== ChannelType.GuildVoice &&
!args.channel.isThread()
)
diff --git a/src/commands/moderation/timeout.ts b/src/commands/moderation/timeout.ts
index 7bb02f7..db6ab56 100644
--- a/src/commands/moderation/timeout.ts
+++ b/src/commands/moderation/timeout.ts
@@ -73,7 +73,13 @@ export default class TimeoutCommand extends BotCommand {
return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`);
const useForce = args.force && message.author.isOwner();
- const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'timeout', true, useForce);
+ const canModerateResponse = await Moderation.permissionCheck(
+ message.member,
+ member,
+ Moderation.Action.Timeout,
+ true,
+ useForce
+ );
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
diff --git a/src/commands/moderation/unblock.ts b/src/commands/moderation/unblock.ts
index 4838392..4fdfc28 100644
--- a/src/commands/moderation/unblock.ts
+++ b/src/commands/moderation/unblock.ts
@@ -75,7 +75,13 @@ export default class UnblockCommand extends BotCommand {
return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`);
const useForce = args.force && message.author.isOwner();
- const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'unblock', true, useForce);
+ const canModerateResponse = await Moderation.permissionCheck(
+ message.member,
+ member,
+ Moderation.Action.Unblock,
+ true,
+ useForce
+ );
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts
index a4d348d..c8fccc8 100644
--- a/src/commands/moderation/unmute.ts
+++ b/src/commands/moderation/unmute.ts
@@ -66,7 +66,13 @@ export default class UnmuteCommand extends BotCommand {
const member = message.guild.members.cache.get(user.id)!;
const useForce = force && message.author.isOwner();
- const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'unmute', true, useForce);
+ const canModerateResponse = await Moderation.permissionCheck(
+ message.member,
+ member,
+ Moderation.Action.Unmute,
+ true,
+ useForce
+ );
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
diff --git a/src/commands/moderation/untimeout.ts b/src/commands/moderation/untimeout.ts
index 3775c65..64364e5 100644
--- a/src/commands/moderation/untimeout.ts
+++ b/src/commands/moderation/untimeout.ts
@@ -73,7 +73,13 @@ export default class UntimeoutCommand extends BotCommand {
if (!member.isCommunicationDisabled()) return message.util.reply(`${emojis.error} That user is not timed out.`);
const useForce = args.force && message.author.isOwner();
- const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'timeout', true, useForce);
+ const canModerateResponse = await Moderation.permissionCheck(
+ message.member,
+ member,
+ Moderation.Action.Untimeout,
+ true,
+ useForce
+ );
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts
index 4bc7f13..a7ed814 100644
--- a/src/commands/moderation/warn.ts
+++ b/src/commands/moderation/warn.ts
@@ -69,7 +69,7 @@ export default class WarnCommand extends BotCommand {
const member = message.guild.members.cache.get(user.id);
if (!member) return message.util.reply(`${emojis.error} I cannot warn users that are not in the server.`);
const useForce = force && message.author.isOwner();
- const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'warn', true, useForce);
+ const canModerateResponse = await Moderation.permissionCheck(message.member, member, Moderation.Action.Warn, true, useForce);
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);