forked from Galactic/galactic-bot
Bugfixes to commandOption and audit log observer
This commit is contained in:
parent
b41435f3ad
commit
71b025c514
@ -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<void>
|
||||
} = {
|
||||
2: async () =>
|
||||
const activities: (() => Promise<void>)[] = [
|
||||
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 ()
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user