diff options
Diffstat (limited to 'src/tasks')
-rw-r--r-- | src/tasks/cpuUsage.ts | 6 | ||||
-rw-r--r-- | src/tasks/handleReminders.ts | 7 | ||||
-rw-r--r-- | src/tasks/memberCount.ts | 6 | ||||
-rw-r--r-- | src/tasks/removeExpiredPunishements.ts | 16 | ||||
-rw-r--r-- | src/tasks/updateCache.ts | 15 | ||||
-rw-r--r-- | src/tasks/updateHighlightCache.ts | 2 | ||||
-rw-r--r-- | src/tasks/updateStats.ts | 10 |
7 files changed, 34 insertions, 28 deletions
diff --git a/src/tasks/cpuUsage.ts b/src/tasks/cpuUsage.ts index 6ce6671..f456c31 100644 --- a/src/tasks/cpuUsage.ts +++ b/src/tasks/cpuUsage.ts @@ -1,5 +1,5 @@ import { BushTask, Time } from '#lib'; -import { cpu } from 'node-os-utils'; +import osu from 'node-os-utils'; export default class CpuUsageTask extends BushTask { public constructor() { @@ -10,7 +10,7 @@ export default class CpuUsageTask extends BushTask { } public async exec() { - const cpuStats = await cpu.usage(client.stats.cpu === undefined ? 100 * Time.Millisecond : Time.Minute); - client.stats.cpu = cpuStats; + const cpuStats = await osu.cpu.usage(this.client.stats.cpu === undefined ? 100 * Time.Millisecond : Time.Minute); + this.client.stats.cpu = cpuStats; } } diff --git a/src/tasks/handleReminders.ts b/src/tasks/handleReminders.ts index 79693f5..7863c9a 100644 --- a/src/tasks/handleReminders.ts +++ b/src/tasks/handleReminders.ts @@ -19,11 +19,14 @@ export default class HandlerRemindersTask extends BushTask { } }); - void client.logger.verbose(`handlerReminders`, `Queried reminders, found <<${expiredEntries.length}>> expired reminders.`); + void this.client.logger.verbose( + `handlerReminders`, + `Queried reminders, found <<${expiredEntries.length}>> expired reminders.` + ); for (const entry of expiredEntries) { setTimeout(() => { - void client.users + void this.client.users .send( entry.user, `The reminder you set ${dateDelta(entry.created)} ago has expired: ${format.bold(entry.content)}\n${entry.messageUrl}` diff --git a/src/tasks/memberCount.ts b/src/tasks/memberCount.ts index fa51080..ea422fa 100644 --- a/src/tasks/memberCount.ts +++ b/src/tasks/memberCount.ts @@ -10,10 +10,10 @@ export default class MemberCountTask extends BushTask { } public override async exec() { - if (!client.config.isProduction) return; + if (!this.client.config.isProduction) return; const res = await Promise.allSettled( - client.guilds.cache + this.client.guilds.cache .filter((g) => g.memberCount >= 100) .map((g) => MemberCount.create({ guildId: g.id, memberCount: g.memberCount })) ); @@ -22,7 +22,7 @@ export default class MemberCountTask extends BushTask { .filter((r) => r.status === 'rejected') .forEach((r) => { assert(r.status === 'rejected'); - void client.console.error('memberCount', r.status); + void this.client.console.error('memberCount', r.status); }); } } diff --git a/src/tasks/removeExpiredPunishements.ts b/src/tasks/removeExpiredPunishements.ts index 3f6f6dd..0b20a27 100644 --- a/src/tasks/removeExpiredPunishements.ts +++ b/src/tasks/removeExpiredPunishements.ts @@ -1,4 +1,4 @@ -import { ActivePunishment, ActivePunishmentType, BushTask, resolveNonCachedUser, Time } from '#lib'; +import { ActivePunishment, ActivePunishmentType, BushTask, Time } from '#lib'; import assert from 'assert'; const { Op } = (await import('sequelize')).default; @@ -19,19 +19,19 @@ export default class RemoveExpiredPunishmentsTask extends BushTask { } }); - void client.logger.verbose( + void this.client.logger.verbose( `removeExpiredPunishments`, `Queried punishments, found <<${expiredEntries.length}>> expired punishments.` ); for (const entry of expiredEntries) { - const guild = client.guilds.cache.get(entry.guild); + const guild = this.client.guilds.cache.get(entry.guild); if (!guild) continue; // eslint-disable-next-line @typescript-eslint/no-misused-promises setTimeout(async () => { const member = guild.members.cache.get(entry.user); - const user = await resolveNonCachedUser(entry.user); + const user = await this.client.utils.resolveNonCachedUser(entry.user); assert(guild); switch (entry.type) { @@ -40,7 +40,7 @@ export default class RemoveExpiredPunishmentsTask extends BushTask { const result = await guild.bushUnban({ user: user, reason: 'Punishment expired' }); if (['success', 'user not banned', 'cannot resolve user'].includes(result)) await entry.destroy(); else throw new Error(result); - void client.logger.verbose(`removeExpiredPunishments`, `Unbanned ${entry.user}.`); + void this.client.logger.verbose(`removeExpiredPunishments`, `Unbanned ${entry.user}.`); break; } case ActivePunishmentType.BLOCK: { @@ -51,7 +51,7 @@ export default class RemoveExpiredPunishmentsTask extends BushTask { const result = await member.bushUnblock({ reason: 'Punishment expired', channel: entry.extraInfo }); if (['success', 'user not blocked'].includes(result)) await entry.destroy(); else throw new Error(result); - void client.logger.verbose(`removeExpiredPunishments`, `Unblocked ${entry.user}.`); + void this.client.logger.verbose(`removeExpiredPunishments`, `Unblocked ${entry.user}.`); break; } case ActivePunishmentType.MUTE: { @@ -59,7 +59,7 @@ export default class RemoveExpiredPunishmentsTask extends BushTask { const result = await member.bushUnmute({ reason: 'Punishment expired' }); if (['success', 'failed to dm'].includes(result)) await entry.destroy(); else throw new Error(result); - void client.logger.verbose(`removeExpiredPunishments`, `Unmuted ${entry.user}.`); + void this.client.logger.verbose(`removeExpiredPunishments`, `Unmuted ${entry.user}.`); break; } case ActivePunishmentType.ROLE: { @@ -74,7 +74,7 @@ export default class RemoveExpiredPunishmentsTask extends BushTask { if (['success', 'failed to dm'].includes(result)) await entry.destroy(); else throw new Error(result); - void client.logger.verbose(`removeExpiredPunishments`, `Removed a punishment role from ${entry.user}.`); + void this.client.logger.verbose(`removeExpiredPunishments`, `Removed a punishment role from ${entry.user}.`); break; } } diff --git a/src/tasks/updateCache.ts b/src/tasks/updateCache.ts index 487b9bc..0dc49df 100644 --- a/src/tasks/updateCache.ts +++ b/src/tasks/updateCache.ts @@ -1,5 +1,6 @@ import { Time } from '#constants'; import { Global, Guild, Shared, type BushClient } from '#lib'; +import { Client } from 'discord.js'; import config from '../../config/options.js'; import { BushTask } from '../lib/extensions/discord-akairo/BushTask.js'; @@ -13,11 +14,11 @@ export default class UpdateCacheTask extends BushTask { public async exec() { await Promise.all([ - UpdateCacheTask.#updateGlobalCache(client), - UpdateCacheTask.#updateSharedCache(client), - UpdateCacheTask.#updateGuildCache(client) + UpdateCacheTask.#updateGlobalCache(this.client), + UpdateCacheTask.#updateSharedCache(this.client), + UpdateCacheTask.#updateGuildCache(this.client) ]); - void client.logger.verbose(`UpdateCache`, `Updated cache.`); + void this.client.logger.verbose(`UpdateCache`, `Updated cache.`); } public static async init(client: BushClient) { @@ -28,7 +29,7 @@ export default class UpdateCacheTask extends BushTask { ]); } - static async #updateGlobalCache(client: BushClient) { + static async #updateGlobalCache(client: Client) { const environment = config.environment; const row: { [x: string]: any } = ((await Global.findByPk(environment)) ?? (await Global.create({ environment }))).toJSON(); @@ -39,7 +40,7 @@ export default class UpdateCacheTask extends BushTask { } } - static async #updateSharedCache(client: BushClient) { + static async #updateSharedCache(client: Client) { const row: { [x: string]: any } = ((await Shared.findByPk(0)) ?? (await Shared.create())).toJSON(); for (const option in row) { @@ -50,7 +51,7 @@ export default class UpdateCacheTask extends BushTask { } } - static async #updateGuildCache(client: BushClient) { + static async #updateGuildCache(client: Client) { const rows = await Guild.findAll(); for (const row of rows) { client.cache.guilds.set(row.id, row.toJSON() as Guild); diff --git a/src/tasks/updateHighlightCache.ts b/src/tasks/updateHighlightCache.ts index d4fca71..4677ea7 100644 --- a/src/tasks/updateHighlightCache.ts +++ b/src/tasks/updateHighlightCache.ts @@ -10,6 +10,6 @@ export default class UpdateHighlightCacheTask extends BushTask { } public async exec() { - return client.highlightManager.syncCache(); + return this.client.highlightManager.syncCache(); } } diff --git a/src/tasks/updateStats.ts b/src/tasks/updateStats.ts index 0e50c23..0d0e661 100644 --- a/src/tasks/updateStats.ts +++ b/src/tasks/updateStats.ts @@ -1,4 +1,5 @@ import { BushTask, Stat, Time } from '#lib'; +import { Client } from 'discord.js'; export default class UpdateStatsTask extends BushTask { public constructor() { @@ -10,13 +11,14 @@ export default class UpdateStatsTask extends BushTask { public async exec() { const row = - (await Stat.findByPk(client.config.environment)) ?? (await Stat.create({ environment: client.config.environment })); - row.commandsUsed = client.stats.commandsUsed; - row.slashCommandsUsed = client.stats.slashCommandsUsed; + (await Stat.findByPk(this.client.config.environment)) ?? + (await Stat.create({ environment: this.client.config.environment })); + row.commandsUsed = this.client.stats.commandsUsed; + row.slashCommandsUsed = this.client.stats.slashCommandsUsed; await row.save(); } - public static async init(): Promise<{ commandsUsed: bigint; slashCommandsUsed: bigint }> { + public static async init(client: Client): Promise<{ commandsUsed: bigint; slashCommandsUsed: bigint }> { const temp = (await Stat.findByPk(client.config.environment)) ?? (await Stat.create({ environment: client.config.environment })); return { commandsUsed: temp.commandsUsed, slashCommandsUsed: temp.slashCommandsUsed }; |