diff --git a/@types/Moderation.d.ts b/@types/Moderation.d.ts index 1b668fa..2bc0cb8 100644 --- a/@types/Moderation.d.ts +++ b/@types/Moderation.d.ts @@ -88,4 +88,4 @@ export type MissingPermsProps = { export type InfractionEditResult = { error: true, index: string -} | undefined; \ No newline at end of file +} | undefined | void; \ No newline at end of file diff --git a/src/client/components/EventHooker.ts b/src/client/components/EventHooker.ts index 52c3f6d..d5dadfa 100644 --- a/src/client/components/EventHooker.ts +++ b/src/client/components/EventHooker.ts @@ -15,7 +15,7 @@ class EventHooker #target: DiscordClient; #logger: LoggerClient; #events: Map; - #safeEvents: string[]; + #safeEvents: (keyof ClientEvents)[]; constructor (target: DiscordClient) { @@ -26,7 +26,7 @@ class EventHooker this.#events = new Map(); this.#logger = target.createLogger(this); - this.#safeEvents = [ 'componentUpdate', 'ready', 'shardReady', 'rateLimit', 'guildCreate' ]; + this.#safeEvents = [ 'componentUpdate', 'ready', 'shardReady', 'rateLimit', 'guildCreate', 'apiResponse' ]; } hook (eventName: K, func: EventHook) diff --git a/src/client/components/ModerationManager.ts b/src/client/components/ModerationManager.ts index 819e347..0b51eb6 100644 --- a/src/client/components/ModerationManager.ts +++ b/src/client/components/ModerationManager.ts @@ -15,6 +15,7 @@ import { Kick, Lockdown, Mute, + Note, Removerole, Softban, Unban, Unlockdown, @@ -41,6 +42,7 @@ const Constant: { REMOVEROLE: typeof Removerole; LOCKDOWN: typeof Lockdown; UNLOCKDOWN: typeof Unlockdown; + NOTE: typeof Note }, Hierarchy: { [key: string]: number @@ -58,7 +60,8 @@ const Constant: { ADDROLE: Addrole, REMOVEROLE: Removerole, LOCKDOWN: Lockdown, - UNLOCKDOWN: Unlockdown + UNLOCKDOWN: Unlockdown, + NOTE: Note }, Hierarchy: { WARN: 0, @@ -87,6 +90,7 @@ class ModerationManager implements Initialisable REMOVEROLE: typeof Removerole; LOCKDOWN: typeof Lockdown; UNLOCKDOWN: typeof Unlockdown; + NOTE: typeof Note }; get infractionClasses () @@ -101,13 +105,10 @@ class ModerationManager implements Initialisable constructor (client: DiscordClient) { - this.#client = client; this.#callbacks = new Collection(); this.#logger = client.createLogger(this); // new Logger({ name: 'ModMngr' }); - this.#infractionClasses = Constant.Infractions; - } actions: { diff --git a/src/client/components/commands/moderation/Edit.ts b/src/client/components/commands/moderation/Edit.ts index d6b9edc..a1a0c2c 100644 --- a/src/client/components/commands/moderation/Edit.ts +++ b/src/client/components/commands/moderation/Edit.ts @@ -77,7 +77,7 @@ class EditCommand extends SlashCommand const results: InfractionEditResult[] = []; if (reasonOpt) - await infraction.editReason(member, reason ?? 'N/A'); + results.push(await infraction.editReason(member, reason ?? 'N/A')); if (points) results.push(await infraction.editPoints(member, points.asNumber)); if (expiration) diff --git a/src/client/infractions/Unmute.ts b/src/client/infractions/Unmute.ts index 8d8b5a1..ffffa37 100644 --- a/src/client/infractions/Unmute.ts +++ b/src/client/infractions/Unmute.ts @@ -60,6 +60,7 @@ class UnmuteInfraction extends Infraction now = Date.now(); let callback = null; + // TODO: Make this not rely on a member wrapper const memberWrapper = await this.guild.memberWrapper(this.member!).catch(() => null); if (Object.keys(this.data).length) { @@ -69,7 +70,7 @@ class UnmuteInfraction extends Infraction } else { - callback = await memberWrapper!.getCallback('MUTE'); + callback = await memberWrapper?.getCallback('MUTE'); if (callback) { removedRoles = callback.infraction.data.removedRoles ?? null; @@ -101,7 +102,7 @@ class UnmuteInfraction extends Infraction if (!callback && settings.mute.type < 3) { - if (role && this.member!.roles.cache.has((role as Role).id)) + if (role && this.member?.roles.cache.has((role as Role).id)) { try { diff --git a/src/client/interfaces/Infraction.ts b/src/client/interfaces/Infraction.ts index d35cf49..857d0fe 100644 --- a/src/client/interfaces/Infraction.ts +++ b/src/client/interfaces/Infraction.ts @@ -657,7 +657,7 @@ class Infraction await this.#modLogMessage.edit({ embeds: [ await this.#embed() ] }); } - async editReason (staff: UserResolveable, reason: string) + async editReason (staff: UserResolveable, reason: string): Promise { this.#error(); const log: InfractionChange = { @@ -813,12 +813,10 @@ class Infraction await this.#patch(data); return this; - } async #patch (data: WithId) { - this.#mongoId = new ObjectId(data._id); this.#callbacked = data._callbacked ?? false; this.#fetched = true;