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.#activityInterval = setInterval(() =>
|
||||||
{
|
{
|
||||||
this.#setActivity();
|
this.#setActivity();
|
||||||
}, 1800_000); // 30 min
|
}, Util.random(5, 10) * 60 * 60 * 1000);
|
||||||
|
|
||||||
this.#built = true;
|
this.#built = true;
|
||||||
this.emit('built');
|
this.emit('built');
|
||||||
@ -345,10 +345,8 @@ class DiscordClient extends Client
|
|||||||
{
|
{
|
||||||
if (!this.shard || !this.user)
|
if (!this.shard || !this.user)
|
||||||
throw new Error('Missing shard or user');
|
throw new Error('Missing shard or user');
|
||||||
const activities: {
|
const activities: (() => Promise<void>)[] = [
|
||||||
[key: number]: () => Promise<void>
|
async () =>
|
||||||
} = {
|
|
||||||
2: async () =>
|
|
||||||
{
|
{
|
||||||
const result = await this.shard?.broadcastEval((client) => client.guilds.cache.size).catch(() => null);
|
const result = await this.shard?.broadcastEval((client) => client.guilds.cache.size).catch(() => null);
|
||||||
if (!result)
|
if (!result)
|
||||||
@ -356,7 +354,7 @@ class DiscordClient extends Client
|
|||||||
const guildCount = result.reduce((p, v) => p + v, 0);
|
const guildCount = result.reduce((p, v) => p + v, 0);
|
||||||
this.user?.setActivity(`${guildCount} servers`, { type: ActivityType.Watching });
|
this.user?.setActivity(`${guildCount} servers`, { type: ActivityType.Watching });
|
||||||
},
|
},
|
||||||
1: async () =>
|
async () =>
|
||||||
{
|
{
|
||||||
const result = await this.shard?.broadcastEval((client) => client.users.cache.size).catch(() => null);
|
const result = await this.shard?.broadcastEval((client) => client.users.cache.size).catch(() => null);
|
||||||
if (!result)
|
if (!result)
|
||||||
@ -364,20 +362,19 @@ class DiscordClient extends Client
|
|||||||
const userCount = result.reduce((p, v) => p + v, 0);
|
const userCount = result.reduce((p, v) => p + v, 0);
|
||||||
this.user?.setActivity(`${userCount} users`, { type: ActivityType.Listening });
|
this.user?.setActivity(`${userCount} users`, { type: ActivityType.Listening });
|
||||||
},
|
},
|
||||||
0: async () =>
|
async () =>
|
||||||
{
|
{
|
||||||
this.user?.setActivity('for /help', { type: ActivityType.Listening });
|
this.user?.setActivity('for /help', { type: ActivityType.Listening });
|
||||||
}
|
}
|
||||||
};
|
];
|
||||||
|
|
||||||
if (!this.shard)
|
if (!this.shard)
|
||||||
return;
|
return;
|
||||||
await activities[this.#activity]();
|
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;
|
this.#activity = 0;
|
||||||
else
|
else
|
||||||
this.#activity++;
|
this.#activity++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get singleton ()
|
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
|
// Ensure input is a string
|
||||||
input = `${input}`.toLowerCase();
|
input = `${input}`.toLowerCase();
|
||||||
const truthy = [ 'on', 'true', 'yes', 'enable', 'y', 't' ];
|
const truthy = [ 'on', 'true', 'yes', 'enable', 'y', 't' ];
|
||||||
const falsey = [ 'off', 'false', 'no', 'disable', 'n', 'f' ];
|
const falsey = [ 'off', 'false', 'no', 'disable', 'n', 'f' ];
|
||||||
|
|
||||||
if (truthy.includes(input))
|
if (truthy.includes(input))
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
else if (falsey.includes(input))
|
else if (falsey.includes(input))
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ class AuditLogObserver extends Observer
|
|||||||
const entry = audit.entries.filter((e) => e?.target?.id === user
|
const entry = audit.entries.filter((e) => e?.target?.id === user
|
||||||
&& subtype ? e.changes.some((c) => c.key === subtype) : true).first();
|
&& 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;
|
return null;
|
||||||
if (entry.target!.id !== user)
|
if (entry.target!.id !== user)
|
||||||
return null;
|
return null;
|
||||||
|
@ -227,7 +227,7 @@ export default class AutoModeration extends Observer implements Initialisable
|
|||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
filterResult = 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 () =>
|
BOOLEAN: async () =>
|
||||||
{
|
{
|
||||||
if (!this.#rawValue)
|
if (!this.#rawValue && !this.valueOptional)
|
||||||
throw new Error('No rawValue supplied');
|
throw new Error('No rawValue supplied');
|
||||||
if (typeof this.#rawValue !== 'string')
|
if (this.#rawValue && typeof this.#rawValue !== 'string')
|
||||||
throw new Error('Invalid rawValue');
|
throw new Error('Invalid rawValue');
|
||||||
const boolean = this.client.resolver.resolveBoolean(this.#rawValue);
|
const boolean = this.client.resolver.resolveBoolean(this.#rawValue);
|
||||||
if (boolean === null && this.valueOptional)
|
if (boolean === null && this.valueOptional)
|
||||||
|
@ -151,6 +151,25 @@ class Util
|
|||||||
return randomUUID();
|
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
|
* Fatally throw an error. Sends a signal to the parent process not to restart the process
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user