From eb0a63a4b92f715f0bbd405290029e74361794df Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 8 Dec 2023 00:30:33 +0200 Subject: [PATCH 1/2] Small fixes here and there --- src/client/infractions/Lockdown.ts | 1 - src/client/infractions/Mute.ts | 2 -- src/client/infractions/Warn.ts | 12 +++--------- src/client/interfaces/CommandOption.ts | 18 ++++++++++-------- src/client/interfaces/Infraction.ts | 8 ++++---- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/client/infractions/Lockdown.ts b/src/client/infractions/Lockdown.ts index 0be0162..0a6633c 100644 --- a/src/client/infractions/Lockdown.ts +++ b/src/client/infractions/Lockdown.ts @@ -175,7 +175,6 @@ class LockdownInfraction extends Infraction async verify () { - const perms = (this.target as GuildChannel).permissionsFor(this.client.user!); const missing = perms?.missing([ 'ManageRoles', 'SendMessages', 'AddReactions', 'ViewChannel' ]); if (!perms || missing?.length) diff --git a/src/client/infractions/Mute.ts b/src/client/infractions/Mute.ts index 37bc525..4f6efaa 100644 --- a/src/client/infractions/Mute.ts +++ b/src/client/infractions/Mute.ts @@ -195,7 +195,6 @@ class MuteInfraction extends Infraction return this._fail('COMMAND_MUTE_MISSING_MANAGEROLE_PERM'); return super._verify(); - } async resolve (_staff: UserWrapper, _reason: string, _notify: boolean): Promise @@ -212,7 +211,6 @@ class MuteInfraction extends Infraction error = false; const settings = await this.guild.settings(); - const { removedRoles = [], muteType = settings.mute.type, muteRole = settings.mute.role } = this.data || {}; // TODO: Change this to not rely on the member const member = await this.guild.memberWrapper(this.targetId!).catch(() => null); diff --git a/src/client/infractions/Warn.ts b/src/client/infractions/Warn.ts index d8d9597..e898693 100644 --- a/src/client/infractions/Warn.ts +++ b/src/client/infractions/Warn.ts @@ -5,7 +5,7 @@ import { WarnData } from '../../../@types/Infractions.js'; import { MemberWrapper } from '../components/wrappers/index.js'; import { InfractionTargetType, InfractionType } from '../../../@types/Client.js'; -class WarnInfraction extends Infraction +class WarnInfraction extends Infraction { static get Type (): InfractionType { @@ -21,12 +21,10 @@ class WarnInfraction extends Infraction constructor (client: DiscordClient, logger: LoggerClient, opts: WarnData) { - - if (opts.fetched) + if (opts.fetched) super(client, logger, opts); - else + else { - super(client, logger, { targetType: 'USER', type: opts.type, @@ -47,9 +45,7 @@ class WarnInfraction extends Infraction if (!(opts.target instanceof MemberWrapper)) throw new Error('Guild member required'); this.member = opts.target; - } - } async execute () @@ -60,13 +56,11 @@ class WarnInfraction extends Infraction async verify () { - // NOTE: If I want to readd permission checking for escalations. // const permissions = await this.client.permissions.execute(this.message, this.message.command); // if(permissions.error) return super._fail('COMMAND_WARN_INSUFFICIENTPERMISSIONS'); return super._verify(); - } } diff --git a/src/client/interfaces/CommandOption.ts b/src/client/interfaces/CommandOption.ts index 5aa7abd..e1b097d 100644 --- a/src/client/interfaces/CommandOption.ts +++ b/src/client/interfaces/CommandOption.ts @@ -81,8 +81,8 @@ class CommandOption throw new Error('Type cannot be an array here'); this.#type = options.type ?? CommandOptionType.STRING; this.#required = Boolean(options.required); - this.#autocomplete = options.autocomplete || false; - this.#choices = options.choices || []; // Used for STRING/INTEGER/NUMBER types. + this.#autocomplete = options.autocomplete ?? false; + this.#choices = options.choices ?? []; // Used for STRING/INTEGER/NUMBER types. this.#options = []; if (options.options) @@ -98,10 +98,10 @@ class CommandOption // Used for INTEGER/NUMBER/FLOAT types. if (typeof options.minimum === 'number') this.#minimum = options.minimum; - if (typeof options.maximum === 'number') + if (typeof options.maximum === 'number') this.#maximum = options.maximum; - this.#slashOption = options.slashOption || false; + this.#slashOption = options.slashOption ?? false; this.#flag = options.flag ?? false; // used with message based command options this.#valueOptional = options.valueOptional ?? false; if (this.#valueOptional && typeof options.defaultValue === 'undefined') @@ -112,7 +112,7 @@ class CommandOption // this.words = options.words ?? null; // Used when parsing strings if the command has multiple string types that aren't flags // Used in cloned options when parsing final value - this.#guild = options.guild || null; + this.#guild = options.guild ?? null; this.#rawValue = options.rawValue ?? null; // Raw value input from Discord. -- use ?? where the value is potentially false, otherwise we end up with false -> null } @@ -191,7 +191,7 @@ class CommandOption return `__${usage.name.replace('》', '').trim()}__\n${usage.value}`; }).join('\n\n'); } - else if (CommandOptionType[this.type] === 'SUB_COMMAND') + else if (CommandOptionType[this.type] === 'SUB_COMMAND') { if (this.options.length) value = this.options.map((opt) => opt.usage(guild, true).value).join('\n'); @@ -291,7 +291,8 @@ class CommandOption continue; if (PointsReg.test(str)) { - value = num; removed = [ str ]; + value = num; + removed = [ str ]; break; } const index = this.#rawValue.indexOf(str); @@ -299,7 +300,8 @@ class CommandOption const tmp = str + next; if (PointsReg.test(tmp)) { - value = num; removed = [ str, next ]; + value = num; + removed = [ str, next ]; break; } } diff --git a/src/client/interfaces/Infraction.ts b/src/client/interfaces/Infraction.ts index 01a873b..9f587d7 100644 --- a/src/client/interfaces/Infraction.ts +++ b/src/client/interfaces/Infraction.ts @@ -242,13 +242,13 @@ class Infraction throw new Error('Expected this method to be implemented in a subclass'); } - async save () + async save () { const filter: {id: string, _id?: ObjectId} = { id: this.id }; if (this.#mongoId) filter._id = this.#mongoId; return this.#client.mongodb.infractions.updateOne(filter, { $set: this.json }) - .catch((error: Error) => + .catch((error: Error) => { this.#logger.error(`There was an issue saving infraction data to the database.\n${error.stack || error}\nInfraction data:\n${inspect(this.json)}`); }); @@ -256,9 +256,9 @@ class Infraction hyperlink (modLogMessage = false) { - if (this.#hyperlink) + if (this.#hyperlink) return this.#hyperlink; - if (modLogMessage) + if (modLogMessage) return `https://discord.com/channels/${this.#guildId}/${this.#modLogId}/${this.#modLogMessageId}`; return `https://discord.com/channels/${this.#guildId}/${this.#channelId}/${this.#messageId}`; } From 07eec3cd9db89be05c908323a5b8a444bd1a7b98 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 8 Dec 2023 00:30:43 +0200 Subject: [PATCH 2/2] forgot a file --- src/client/components/ModerationManager.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/client/components/ModerationManager.ts b/src/client/components/ModerationManager.ts index ac625c3..b820a58 100644 --- a/src/client/components/ModerationManager.ts +++ b/src/client/components/ModerationManager.ts @@ -366,12 +366,12 @@ class ModerationManager implements Initialisable break; } } - if (modpoints.multiplier) + if (modpoints.multiplier) expiration *= points; } const verify = async (infraction: InfractionClass, escalated = false): - Promise<(InfractionFail | InfractionSuccess) & { escalation?: EscalationResult }> => + Promise<(InfractionFail | InfractionSuccess) & { escalation?: EscalationResult }> => { // const verification = await infraction.verify(info.executor, target, info.channel); @@ -456,9 +456,9 @@ class ModerationManager implements Initialisable let response = await verify(infraction); - if (response.escalation) + if (response.escalation) { - if (Constant.Hierarchy[infraction.type] <= Constant.Hierarchy[response.escalation.type]) + if (Constant.Hierarchy[infraction.type] <= Constant.Hierarchy[response.escalation.type]) { // this is just to shut up the TS checker const escalationClass = Constant.Infractions[response.escalation.type] as typeof InfractionClass; @@ -499,7 +499,6 @@ class ModerationManager implements Initialisable points, expiration, timestamp: response.infraction.timestamp, id: response.infraction.id }); return result; - } async _handleArguments (invoker: InvokerWrapper, targets: ModerationTargets, args: {[key: string]: CommandOption | undefined}) @@ -569,13 +568,13 @@ class ModerationManager implements Initialisable executor }).execute(); } - catch (err) + catch (err) { const error = err as Error; this.#logger.error(`Error when resolving infraction:\n${error.stack || error}`); } } - else + else { // Target left guild or channel was removed from the guild. What should happen in this situation? // Maybe continue checking if the user rejoins, but the channel will always be gone. @@ -614,9 +613,7 @@ class ModerationManager implements Initialisable }, callBackAt - currentDate), infraction }); - } - } async removeCallback (infraction: InfractionClass | InfractionJSON, updateCase = false) @@ -668,8 +665,7 @@ class ModerationManager implements Initialisable async findLatestInfraction (type: InfractionType, target: ModerationTarget) { - - const callback = this.#callbacks.filter((c) => + const callback = this.#callbacks.filter((c) => { return c.infraction.type === type && c.infraction.target === target.id; @@ -683,7 +679,6 @@ class ModerationManager implements Initialisable { sort: { timestamp: -1 } } ); return result || null; - } }