diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-05 21:45:29 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-05 21:45:29 -0400 |
commit | e3c116e0f4b741032fe777936fdf5d80f0b011e6 (patch) | |
tree | 024bd9884f1456983faae2b62b59485a879ac934 /src | |
parent | c8a5bfe694ee6e784a0c5cbe1a7076b1c055249a (diff) | |
download | tanzanite-e3c116e0f4b741032fe777936fdf5d80f0b011e6.tar.gz tanzanite-e3c116e0f4b741032fe777936fdf5d80f0b011e6.tar.bz2 tanzanite-e3c116e0f4b741032fe777936fdf5d80f0b011e6.zip |
modlogid uuid -> nanoid
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/moderation/modlog.ts | 30 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 6 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuildMember.ts | 25 | ||||
-rw-r--r-- | src/lib/models/ActivePunishment.ts | 6 | ||||
-rw-r--r-- | src/lib/models/ModLog.ts | 4 | ||||
-rw-r--r-- | src/listeners/custom/bushPurge.ts | 1 |
6 files changed, 40 insertions, 32 deletions
diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index 0be6971..459e53c 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -1,5 +1,5 @@ import { BushCommand, BushMessage, BushSlashMessage, BushUser, ModLog } from '@lib'; -import { User } from 'discord.js'; +import { MessageEmbed, User } from 'discord.js'; export default class ModlogCommand extends BushCommand { public constructor() { @@ -23,7 +23,7 @@ export default class ModlogCommand extends BushCommand { { id: 'hidden', match: 'flag', - flags: ['--hidden', '-h'], + flag: ['--hidden', '-h'], default: false } ], @@ -51,8 +51,8 @@ export default class ModlogCommand extends BushCommand { const modLog = [ `**Case ID**: ${log.id}`, `**Type**: ${log.type.toLowerCase()}`, - `**User**: <@!${log.user}> (${log.user})`, - `**Moderator**: <@!${log.moderator}> (${log.moderator})` + `**User**: <@!${log.user}>`, + `**Moderator**: <@!${log.moderator}>` ]; if (log.duration) modLog.push(`**Duration**: ${util.humanizeDuration(log.duration)}`); modLog.push(`**Reason**: ${trim(log.reason ?? 'No Reason Specified.')}`); @@ -73,14 +73,20 @@ export default class ModlogCommand extends BushCommand { }, order: [['createdAt', 'ASC']] }); - if (!logs.length) return message.util.reply(`${util.emojis.error} **${foundUser.tag}** does not have any modlogs.`); - const niceLogs = logs.filter((log) => !log.pseudo && !log.hidden && !hidden).map((log) => this.#generateModlogInfo(log)); - const chunked: string[][] = util.chunk(niceLogs, 3); - const embedPages = chunked.map((chunk) => ({ - title: `${foundUser.tag}'s Mod Logs`, - description: chunk.join('\n━━━━━━━━━━━━━━━\n'), - color: util.colors.default - })); + const niceLogs = logs + .filter((log) => !log.pseudo || (!log.hidden && !hidden)) + .map((log) => this.#generateModlogInfo(log)); + if (!logs.length || !niceLogs.length) + return message.util.reply(`${util.emojis.error} **${foundUser.tag}** does not have any modlogs.`); + const chunked: string[][] = util.chunk(niceLogs, 4); + const embedPages = chunked.map( + (chunk) => + new MessageEmbed({ + title: `${foundUser.tag}'s Mod Logs`, + description: chunk.join('\n━━━━━━━━━━━━━━━\n'), + color: util.colors.default + }) + ); return await util.buttonPaginate(message, embedPages, undefined, true); } else if (search) { const entry = await ModLog.findByPk(search as string); diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index fec0174..91d5eb6 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -1133,6 +1133,7 @@ export class BushClientUtil extends ClientUtil { reason: string | undefined | null; duration?: number; guild: BushGuildResolvable; + pseudo?: boolean; }, getCaseNumber = false ): Promise<{ log: ModLog | null; caseNum: number | null }> { @@ -1158,7 +1159,8 @@ export class BushClientUtil extends ClientUtil { moderator, reason: options.reason, duration: duration, - guild + guild, + pseudo: options.pseudo ?? false }); const saveResult: ModLog | null = await modLogEntry.save().catch(async (e) => { await util.handleError('createModLogEntry', e); @@ -1176,7 +1178,7 @@ export class BushClientUtil extends ClientUtil { user: BushGuildMemberResolvable; duration: number | undefined; guild: BushGuildResolvable; - modlog?: string; + modlog: string; extraInfo?: Snowflake; }): Promise<ActivePunishment | null> { const expires = options.duration ? new Date(new Date().getTime() + options.duration ?? 0) : undefined; diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts index 4dd1a5d..5575303 100644 --- a/src/lib/extensions/discord.js/BushGuildMember.ts +++ b/src/lib/extensions/discord.js/BushGuildMember.ts @@ -145,25 +145,24 @@ export class BushGuildMember extends GuildMember { const ret = await (async () => { if (options.addToModlog || options.duration) { - const { log: modlog } = options.addToModlog - ? await util.createModLogEntry({ - type: options.duration ? ModLogType.TEMP_PUNISHMENT_ROLE : ModLogType.PERM_PUNISHMENT_ROLE, - guild: this.guild, - moderator: moderator.id, - user: this, - reason: 'N/A' - }) - : { log: null }; - caseID = modlog?.id; - - if (!modlog && options.addToModlog) return 'error creating modlog entry'; + const { log: modlog } = await util.createModLogEntry({ + type: options.duration ? ModLogType.TEMP_PUNISHMENT_ROLE : ModLogType.PERM_PUNISHMENT_ROLE, + guild: this.guild, + moderator: moderator.id, + user: this, + reason: 'N/A', + pseudo: !options.addToModlog + }); + + if (!modlog) return 'error creating modlog entry'; + caseID = modlog.id; if (options.addToModlog || options.duration) { const punishmentEntrySuccess = await util.createPunishmentEntry({ type: 'role', user: this, guild: this.guild, - modlog: modlog?.id ?? undefined, + modlog: modlog.id, duration: options.duration, extraInfo: options.role.id }); diff --git a/src/lib/models/ActivePunishment.ts b/src/lib/models/ActivePunishment.ts index 794560f..f453426 100644 --- a/src/lib/models/ActivePunishment.ts +++ b/src/lib/models/ActivePunishment.ts @@ -1,6 +1,6 @@ import { Snowflake } from 'discord.js'; +import { nanoid } from 'nanoid'; import { DataTypes, Sequelize } from 'sequelize'; -import { v4 as uuidv4 } from 'uuid'; import { BaseModel } from './BaseModel'; export enum ActivePunishmentType { @@ -26,7 +26,7 @@ export interface ActivePunishmentModelCreationAttributes { guild: Snowflake; extraInfo?: Snowflake; expires?: Date; - modlog?: string; + modlog: string; } const NEVER_USED = 'This should never be executed'; @@ -112,7 +112,7 @@ export class ActivePunishment type: DataTypes.STRING, primaryKey: true, allowNull: false, - defaultValue: uuidv4 + defaultValue: nanoid }, type: { type: DataTypes.STRING, diff --git a/src/lib/models/ModLog.ts b/src/lib/models/ModLog.ts index 5c87331..a70913d 100644 --- a/src/lib/models/ModLog.ts +++ b/src/lib/models/ModLog.ts @@ -1,6 +1,6 @@ import { Snowflake } from 'discord.js'; +import { nanoid } from 'nanoid'; import { DataTypes, Sequelize } from 'sequelize'; -import { v4 as uuidv4 } from 'uuid'; import { BaseModel } from './BaseModel'; import { jsonParseGet, jsonParseSet, NEVER_USED } from './__helpers'; @@ -155,7 +155,7 @@ export class ModLog extends BaseModel<ModLogModel, ModLogModelCreationAttributes type: DataTypes.STRING, primaryKey: true, allowNull: false, - defaultValue: uuidv4 + defaultValue: nanoid }, type: { type: DataTypes.STRING, //# This is not an enum because of a sequelize issue: https://github.com/sequelize/sequelize/issues/2554 diff --git a/src/listeners/custom/bushPurge.ts b/src/listeners/custom/bushPurge.ts index 240af96..22de99c 100644 --- a/src/listeners/custom/bushPurge.ts +++ b/src/listeners/custom/bushPurge.ts @@ -28,6 +28,7 @@ export default class BushPurgeListener extends BushListener { .setColor(util.colors.discord.DARK_PURPLE) .setTimestamp() .setFooter(`${messages.size.toLocaleString()} Messages`) + .setAuthor(moderator.tag, moderator.avatarURL({ dynamic: true, format: 'png', size: 4096 }) ?? undefined) .addField('**Action**', `${'Purge'}`) .addField('**Moderator**', `${moderator} (${moderator.tag})`) .addField('**Channel**', `<#${channel.id}> (${channel.name})`) |