diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-08-14 21:43:24 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-08-14 21:43:24 -0400 |
commit | 82b7fdf99ba4ad50ca037ff11c8fd2d386c45e71 (patch) | |
tree | 87c9815a60c64503af623b20bc42e814ef4a73c4 | |
parent | 0c45d2739fafd1f7b93c2a826a00a81356be0c71 (diff) | |
download | tanzanite-82b7fdf99ba4ad50ca037ff11c8fd2d386c45e71.tar.gz tanzanite-82b7fdf99ba4ad50ca037ff11c8fd2d386c45e71.tar.bz2 tanzanite-82b7fdf99ba4ad50ca037ff11c8fd2d386c45e71.zip |
add mylogs command - view your own modlogs
-rw-r--r-- | src/commands/moderation/modlog.ts | 15 | ||||
-rw-r--r-- | src/commands/moderation/myLogs.ts | 74 | ||||
-rw-r--r-- | src/lib/common/HighlightManager.ts | 4 | ||||
-rw-r--r-- | src/lib/common/util/Format.ts | 10 | ||||
-rw-r--r-- | src/listeners/bush/appealListener.ts | 2 |
5 files changed, 93 insertions, 12 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); + } +} diff --git a/src/lib/common/HighlightManager.ts b/src/lib/common/HighlightManager.ts index a3c1813..4f891b7 100644 --- a/src/lib/common/HighlightManager.ts +++ b/src/lib/common/HighlightManager.ts @@ -11,7 +11,7 @@ import { type TextBasedChannel } from 'discord.js'; import { colors, Time } from '../utils/BushConstants.js'; -import { escapeMarkdown, sanitizeWtlAndControl } from './util/Format.js'; +import { sanitizeInputForDiscord } from './util/Format.js'; const NOTIFY_COOLDOWN = 5 * Time.Minute; const OWNER_NOTIFY_COOLDOWN = 5 * Time.Minute; @@ -451,7 +451,7 @@ export class HighlightManager { author: { name: hl.regex ? `/${hl.word}/gi` : hl.word }, fields: [{ name: 'Source message', value: `[Jump to message](${message.url})` }], color: colors.default, - footer: { text: `Triggered in ${escapeMarkdown(sanitizeWtlAndControl(`${message.guild}`))}` }, + footer: { text: `Triggered in ${sanitizeInputForDiscord(`${message.guild}`)}` }, timestamp: message.createdAt.toISOString() }; } diff --git a/src/lib/common/util/Format.ts b/src/lib/common/util/Format.ts index ff34745..debaf4b 100644 --- a/src/lib/common/util/Format.ts +++ b/src/lib/common/util/Format.ts @@ -88,7 +88,7 @@ export function spoiler(content: string): string { * @param text The input */ export function input(text: string): string { - return bold(escapeMarkdown(sanitizeWtlAndControl(`${text}`))); + return bold(sanitizeInputForDiscord(`${text}`)); } /** @@ -108,4 +108,12 @@ export function sanitizeWtlAndControl(str: string) { return `${str}`.replace(/[\u0000-\u001F\u007F-\u009F\u200B]/g, ''); } +/** + * Removed wtl and control characters and escapes any other markdown + * @param text The input + */ +export function sanitizeInputForDiscord(text: string): string { + return escapeMarkdown(sanitizeWtlAndControl(`${text}`)); +} + export { escapeMarkdown } from 'discord.js'; diff --git a/src/listeners/bush/appealListener.ts b/src/listeners/bush/appealListener.ts index cbe62a8..a4e1f00 100644 --- a/src/listeners/bush/appealListener.ts +++ b/src/listeners/bush/appealListener.ts @@ -69,7 +69,7 @@ export default class AppealListener extends BushListener { embed.addFields({ name: 'ยป Latest Modlogs', value: latestModlogs.length - ? latestModlogs.map((ml) => ModlogCommand.generateModlogInfo(ml, false)).join(ModlogCommand.separator) + ? latestModlogs.map((ml) => ModlogCommand.generateModlogInfo(ml, false, false)).join(ModlogCommand.separator) : 'No Modlogs Found' }); |