diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/moderation/modlog.ts | 15 | ||||
-rw-r--r-- | src/commands/moderation/myLogs.ts | 74 |
2 files changed, 81 insertions, 8 deletions
diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index 4671f58..c7bdeb0 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -72,12 +72,11 @@ export default class ModlogCommand extends BushCommand { const niceLogs = logs .filter((log) => !log.pseudo) .filter((log) => !(log.hidden && hidden)) - .map((log) => ModlogCommand.generateModlogInfo(log, false)); - if (!logs.length || !niceLogs.length) - return message.util.reply(`${emojis.error} **${foundUser.tag}** does not have any modlogs.`); + .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 chunked: string[][] = chunk(niceLogs, 4); const embedPages = chunked.map((chunk) => ({ - title: `${foundUser.tag}'s Mod Logs`, + title: `${foundUser.tag}'s Modlogs`, description: chunk.join(ModlogCommand.separator), color: colors.default })); @@ -89,22 +88,22 @@ export default class ModlogCommand extends BushCommand { 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), + description: ModlogCommand.generateModlogInfo(entry, true, false), color: colors.default }; return await ButtonPaginator.send(message, [embed]); } } - public static generateModlogInfo(log: ModLog, showUser: boolean): string { + 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}>`); - modLog.push(`**Moderator:** <@!${log.moderator}>`); + 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) modLog.push(`**Evidence:** ${trim(log.evidence)}`); + if (log.evidence && !userFacing) modLog.push(`**Evidence:** ${trim(log.evidence)}`); return modLog.join(`\n`); } } diff --git a/src/commands/moderation/myLogs.ts b/src/commands/moderation/myLogs.ts new file mode 100644 index 0000000..ab67a18 --- /dev/null +++ b/src/commands/moderation/myLogs.ts @@ -0,0 +1,74 @@ +import { + BushCommand, + ButtonPaginator, + chunk, + clientSendAndPermCheck, + colors, + emojis, + ModLog, + OptArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; + +import { ApplicationCommandOptionType } from 'discord.js'; +import { input, sanitizeInputForDiscord } from '../../lib/common/util/Format.js'; +import ModlogCommand from './modlog.js'; +export default class MyLogsCommand extends BushCommand { + public constructor() { + super('myLogs', { + aliases: ['my-logs', 'my-log', 'my-modlogs', 'my-modlog'], + category: 'moderation', + description: 'Displays your own moderation logs.', + usage: ['my-logs [server]'], + examples: ['my-logs', 'my-logs 516977525906341928'], + args: [ + { + id: 'server', + description: 'The server to get your mod logs from.', + type: 'guild', + prompt: 'What server would you like to view your mod logs from?', + retry: '{error} Choose a valid server to view your modlogs from.', + optional: true, + slashType: ApplicationCommandOptionType.String + } + ], + slash: true, + channel: null, + clientPermissions: (m) => clientSendAndPermCheck(m), + userPermissions: [] + }); + } + + public override async exec(message: CommandMessage | SlashMessage, args: { server: OptArgType<'guild'> }) { + const guild = args.server ?? message.guild; + + if (!guild) { + return message.util!.send(`${emojis.error} When in DMs, you must provide a server to view your modlogs in.`); + } + + const logs = await ModLog.findAll({ + where: { + guild: guild.id, + user: message.author.id + }, + order: [['createdAt', 'ASC']] + }); + + const niceLogs = logs + .filter((log) => !log.pseudo && !log.hidden) + .map((log) => ModlogCommand.generateModlogInfo(log, false, true)); + + if (niceLogs.length < 1) return message.util.reply(`${emojis.error} You don't have any modlogs in ${input(guild.name)}.`); + + const chunked: string[][] = chunk(niceLogs, 4); + + const embedPages = chunked.map((chunk) => ({ + title: `Your Modlogs in ${sanitizeInputForDiscord(guild.name)}`, + description: chunk.join(ModlogCommand.separator), + color: colors.default + })); + + return await ButtonPaginator.send(message, embedPages, undefined, true); + } +} |