diff --git a/src/client/DiscordClient.ts b/src/client/DiscordClient.ts index b25373e..84d83e8 100644 --- a/src/client/DiscordClient.ts +++ b/src/client/DiscordClient.ts @@ -235,7 +235,7 @@ class DiscordClient extends Client this.#activityInterval = setInterval(() => { this.#setActivity(); - }, 1800_000); // 30 min + }, Util.random(5, 10) * 60 * 60 * 1000); this.#built = true; this.emit('built'); @@ -345,10 +345,8 @@ class DiscordClient extends Client { if (!this.shard || !this.user) throw new Error('Missing shard or user'); - const activities: { - [key: number]: () => Promise - } = { - 2: async () => + const activities: (() => Promise)[] = [ + async () => { const result = await this.shard?.broadcastEval((client) => client.guilds.cache.size).catch(() => null); if (!result) @@ -356,7 +354,7 @@ class DiscordClient extends Client const guildCount = result.reduce((p, v) => p + v, 0); this.user?.setActivity(`${guildCount} servers`, { type: ActivityType.Watching }); }, - 1: async () => + async () => { const result = await this.shard?.broadcastEval((client) => client.users.cache.size).catch(() => null); if (!result) @@ -364,20 +362,19 @@ class DiscordClient extends Client const userCount = result.reduce((p, v) => p + v, 0); this.user?.setActivity(`${userCount} users`, { type: ActivityType.Listening }); }, - 0: async () => + async () => { this.user?.setActivity('for /help', { type: ActivityType.Listening }); } - }; + ]; if (!this.shard) return; await activities[this.#activity](); - if (this.#activity === Math.max(...Object.keys(activities).map(val => parseInt(val)))) + if (this.#activity === activities.length - 1) this.#activity = 0; else this.#activity++; - } get singleton () diff --git a/src/client/components/Resolver.ts b/src/client/components/Resolver.ts index 8f9db12..d014421 100644 --- a/src/client/components/Resolver.ts +++ b/src/client/components/Resolver.ts @@ -474,21 +474,19 @@ class Resolver // } - resolveBoolean (input: string | boolean) + resolveBoolean (input: string | boolean | null) { + if (input === null) + return null; // Ensure input is a string input = `${input}`.toLowerCase(); const truthy = [ 'on', 'true', 'yes', 'enable', 'y', 't' ]; const falsey = [ 'off', 'false', 'no', 'disable', 'n', 'f' ]; if (truthy.includes(input)) - { return true; - } else if (falsey.includes(input)) - { return false; - } return null; } diff --git a/src/client/components/observers/AuditLog.ts b/src/client/components/observers/AuditLog.ts index 8d4eeb2..a4d86e9 100644 --- a/src/client/components/observers/AuditLog.ts +++ b/src/client/components/observers/AuditLog.ts @@ -206,7 +206,7 @@ class AuditLogObserver extends Observer const entry = audit.entries.filter((e) => e?.target?.id === user && subtype ? e.changes.some((c) => c.key === subtype) : true).first(); - if (!entry || entry.executor!.id === this.client.user!.id) + if (!entry || entry.executor?.id === this.client.user!.id) return null; if (entry.target!.id !== user) return null; diff --git a/src/client/components/observers/Automoderation.ts b/src/client/components/observers/Automoderation.ts index ae9014f..ce23aba 100644 --- a/src/client/components/observers/Automoderation.ts +++ b/src/client/components/observers/Automoderation.ts @@ -227,7 +227,7 @@ export default class AutoModeration extends Observer implements Initialisable if (result) { filterResult = result; - log += `\nMessage matched with "${result._matcher}" in fuzzy.\nMatched word: ${result.match}\nFull content: ${content}\nSimilarity: ${result.sim}\nThreshold: ${result.threshold}`; + log += `\nMessage matched with "${result.word}" in fuzzy.\nMatched word: ${result.match}\nFull content: ${content}\nSimilarity: ${result.sim}\nThreshold: ${result.threshold}`; } } diff --git a/src/client/interfaces/CommandOption.ts b/src/client/interfaces/CommandOption.ts index 3811aeb..0700f56 100644 --- a/src/client/interfaces/CommandOption.ts +++ b/src/client/interfaces/CommandOption.ts @@ -601,9 +601,9 @@ class CommandOption }, BOOLEAN: async () => { - if (!this.#rawValue) + if (!this.#rawValue && !this.valueOptional) throw new Error('No rawValue supplied'); - if (typeof this.#rawValue !== 'string') + if (this.#rawValue && typeof this.#rawValue !== 'string') throw new Error('Invalid rawValue'); const boolean = this.client.resolver.resolveBoolean(this.#rawValue); if (boolean === null && this.valueOptional) diff --git a/src/utilities/Util.ts b/src/utilities/Util.ts index 8c54f67..edc86e1 100644 --- a/src/utilities/Util.ts +++ b/src/utilities/Util.ts @@ -151,6 +151,25 @@ class Util return randomUUID(); } + /** + * Returns a random integer in [min, max] + * If max is omitted, min will shifted to max and min set to 0 + * + * @static + * @param min + * @param max + * @memberof Util + */ + static random (min: number, max?: number) + { + if (typeof max === 'undefined') + { + max = min; + min = 0; + } + return Math.floor(Math.random() * (max - min + 1) + min); + } + /** * Fatally throw an error. Sends a signal to the parent process not to restart the process *