aboutsummaryrefslogtreecommitdiff
path: root/src/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'src/tasks')
-rw-r--r--src/tasks/cache/updateCache.ts49
-rw-r--r--src/tasks/cache/updatePriceItemCache.ts6
-rw-r--r--src/tasks/feature/handleReminders.ts5
-rw-r--r--src/tasks/feature/removeExpiredPunishements.ts2
-rw-r--r--src/tasks/feature/updateStats.d.ts10
-rw-r--r--src/tasks/feature/updateStats.js22
-rw-r--r--src/tasks/feature/updateStats.js.map1
-rw-r--r--src/tasks/feature/updateStats.ts7
8 files changed, 40 insertions, 62 deletions
diff --git a/src/tasks/cache/updateCache.ts b/src/tasks/cache/updateCache.ts
index 595a872..190e2a4 100644
--- a/src/tasks/cache/updateCache.ts
+++ b/src/tasks/cache/updateCache.ts
@@ -1,8 +1,4 @@
-import { Global, Guild, Shared, type BushClient } from '#lib';
-import type { Client } from 'discord.js';
-import config from '../../../config/options.js';
-import { BushTask } from '../../../lib/extensions/discord-akairo/BushTask.js';
-import { Time } from '../../../lib/utils/BushConstants.js';
+import { BushTask, Time, updateEveryCache } from '#lib';
export default class UpdateCacheTask extends BushTask {
public constructor() {
@@ -13,48 +9,7 @@ export default class UpdateCacheTask extends BushTask {
}
public async exec() {
- await Promise.all([
- UpdateCacheTask.#updateGlobalCache(this.client),
- UpdateCacheTask.#updateSharedCache(this.client),
- UpdateCacheTask.#updateGuildCache(this.client)
- ]);
+ await updateEveryCache(this.client);
void this.client.logger.verbose(`UpdateCache`, `Updated cache.`);
}
-
- public static async init(client: BushClient) {
- await Promise.all([
- UpdateCacheTask.#updateGlobalCache(client),
- UpdateCacheTask.#updateSharedCache(client),
- UpdateCacheTask.#updateGuildCache(client)
- ]);
- }
-
- static async #updateGlobalCache(client: Client) {
- const environment = config.environment;
- const row: { [x: string]: any } = ((await Global.findByPk(environment)) ?? (await Global.create({ environment }))).toJSON();
-
- for (const option in row) {
- if (Object.keys(client.cache.global).includes(option)) {
- client.cache.global[option as keyof typeof client.cache.global] = row[option];
- }
- }
- }
-
- static async #updateSharedCache(client: Client) {
- const row: { [x: string]: any } = ((await Shared.findByPk(0)) ?? (await Shared.create())).toJSON();
-
- for (const option in row) {
- if (Object.keys(client.cache.shared).includes(option)) {
- client.cache.shared[option as keyof typeof client.cache.shared] = row[option];
- if (option === 'superUsers') client.superUserID = row[option];
- }
- }
- }
-
- 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/cache/updatePriceItemCache.ts b/src/tasks/cache/updatePriceItemCache.ts
index 55115cc..bafbfaf 100644
--- a/src/tasks/cache/updatePriceItemCache.ts
+++ b/src/tasks/cache/updatePriceItemCache.ts
@@ -1,5 +1,4 @@
import { BushTask, Time } from '#lib';
-import got from 'got';
import PriceCommand, { AuctionAverages, Bazaar, LowestBIN } from '../../commands/utilities/price.js';
export default class UpdatePriceItemCache extends BushTask {
@@ -13,9 +12,8 @@ export default class UpdatePriceItemCache extends BushTask {
public async exec() {
const [bazaar, currentLowestBIN, averageLowestBIN, auctionAverages] = (await Promise.all(
PriceCommand.urls.map(({ url }) =>
- got
- .get(url)
- .json()
+ fetch(url)
+ .then((p) => (p.ok ? p.json() : undefined))
.catch(() => undefined)
)
)) as [Bazaar?, LowestBIN?, LowestBIN?, AuctionAverages?];
diff --git a/src/tasks/feature/handleReminders.ts b/src/tasks/feature/handleReminders.ts
index 1e44083..a9f5658 100644
--- a/src/tasks/feature/handleReminders.ts
+++ b/src/tasks/feature/handleReminders.ts
@@ -1,5 +1,5 @@
import { BushTask, dateDelta, format, Reminder, Time } from '#lib';
-const { Op } = (await import('sequelize')).default;
+import { Op } from 'sequelize';
export default class HandlerRemindersTask extends BushTask {
public constructor() {
@@ -29,8 +29,7 @@ export default class HandlerRemindersTask extends BushTask {
void this.client.users
.send(
entry.user,
- `The reminder you set ${dateDelta(entry.created)} ago has expired: ${format.bold(entry.content)}
-${entry.messageUrl}`
+ `The reminder you set ${dateDelta(entry.created)} ago has expired: ${format.bold(entry.content)}\n${entry.messageUrl}`
)
.catch(() => false);
void entry.update({ notified: true });
diff --git a/src/tasks/feature/removeExpiredPunishements.ts b/src/tasks/feature/removeExpiredPunishements.ts
index c21454b..30b8eba 100644
--- a/src/tasks/feature/removeExpiredPunishements.ts
+++ b/src/tasks/feature/removeExpiredPunishements.ts
@@ -1,6 +1,6 @@
import { ActivePunishment, ActivePunishmentType, BushTask, Time } from '#lib';
import assert from 'assert/strict';
-const { Op } = (await import('sequelize')).default;
+import { Op } from 'sequelize';
export default class RemoveExpiredPunishmentsTask extends BushTask {
public constructor() {
diff --git a/src/tasks/feature/updateStats.d.ts b/src/tasks/feature/updateStats.d.ts
new file mode 100644
index 0000000..1274267
--- /dev/null
+++ b/src/tasks/feature/updateStats.d.ts
@@ -0,0 +1,10 @@
+import { BushTask } from '#lib';
+import { Client } from 'discord.js';
+export default class UpdateStatsTask extends BushTask {
+ constructor();
+ exec(): Promise<void>;
+ static init(client: Client): Promise<{
+ commandsUsed: bigint;
+ slashCommandsUsed: bigint;
+ }>;
+}
diff --git a/src/tasks/feature/updateStats.js b/src/tasks/feature/updateStats.js
new file mode 100644
index 0000000..18a9a7c
--- /dev/null
+++ b/src/tasks/feature/updateStats.js
@@ -0,0 +1,22 @@
+import { BushTask, Stat, Time } from '#lib';
+import { Client } from 'discord.js';
+export default class UpdateStatsTask extends BushTask {
+ constructor() {
+ super('updateStats', {
+ delay: 10 * 60000,
+ runOnStart: true
+ });
+ }
+ async exec() {
+ const row = (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();
+ }
+ static async init(client) {
+ const temp = (await Stat.findByPk(client.config.environment)) ?? (await Stat.create({ environment: client.config.environment }));
+ return { commandsUsed: temp.commandsUsed, slashCommandsUsed: temp.slashCommandsUsed };
+ }
+}
+//# sourceMappingURL=updateStats.js.map \ No newline at end of file
diff --git a/src/tasks/feature/updateStats.js.map b/src/tasks/feature/updateStats.js.map
new file mode 100644
index 0000000..01cd260
--- /dev/null
+++ b/src/tasks/feature/updateStats.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"updateStats.js","sourceRoot":"","sources":["updateStats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,QAAQ;IACpD;QACC,KAAK,CAAC,aAAa,EAAE;YACpB,KAAK,EAAE,EAAE,QAAc;YACvB,UAAU,EAAE,IAAI;SAChB,CAAC,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,IAAI;QAChB,MAAM,GAAG,GACR,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACrD,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QACtE,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC;QAClD,GAAG,CAAC,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC;QAC5D,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAClB,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAc;QACtC,MAAM,IAAI,GACT,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QACrH,OAAO,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC;IACvF,CAAC;CACD"} \ No newline at end of file
diff --git a/src/tasks/feature/updateStats.ts b/src/tasks/feature/updateStats.ts
index 0d0e661..77b7c30 100644
--- a/src/tasks/feature/updateStats.ts
+++ b/src/tasks/feature/updateStats.ts
@@ -1,5 +1,4 @@
import { BushTask, Stat, Time } from '#lib';
-import { Client } from 'discord.js';
export default class UpdateStatsTask extends BushTask {
public constructor() {
@@ -17,10 +16,4 @@ export default class UpdateStatsTask extends BushTask {
row.slashCommandsUsed = this.client.stats.slashCommandsUsed;
await row.save();
}
-
- 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 };
- }
}