From 3466513025d2455840260ea20d5b0fbf568af7aa Mon Sep 17 00:00:00 2001 From: DidaS Date: Tue, 28 May 2024 08:49:40 +0100 Subject: [PATCH] Emit to debug listener instead of logging --- packages/handlers/src/advanced/handler.ts | 6 +++--- packages/handlers/src/advanced/shared.ts | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/handlers/src/advanced/handler.ts b/packages/handlers/src/advanced/handler.ts index 4bae4cb..9a964b7 100644 --- a/packages/handlers/src/advanced/handler.ts +++ b/packages/handlers/src/advanced/handler.ts @@ -195,7 +195,7 @@ export class Handler { }); if (!await file.exists()) { - console.log("Publish all commands & creating cache"); + this.#emit?.(HandlerIdentifier.FRESH, undefined); await Bun.write(file, JSON.stringify(commands)); await client.rest.bulkOverwriteGlobalApplicationCommand(client.user.id, commandsJSON); return; @@ -220,11 +220,11 @@ export class Handler { } if (toPublish.length < 1) { - console.log("All commands were cached, nothing to update"); + this.#emit?.(HandlerIdentifier.CACHED, undefined); return; } - console.log("Publishing changed commands", toPublish); + this.#emit?.(HandlerIdentifier.CHANGES, toPublish); // Using bulkOverwriteGlobalApplicationCommand with only a set of commands deletes the ones not included in that set // eslint-disable-next-line no-await-in-loop for (let i = 0, { length } = toPublish; i < length; i++) await client.rest.createGlobalApplicationCommand(client.user.id, toPublish[i]); diff --git a/packages/handlers/src/advanced/shared.ts b/packages/handlers/src/advanced/shared.ts index a04b12e..fdd66e6 100644 --- a/packages/handlers/src/advanced/shared.ts +++ b/packages/handlers/src/advanced/shared.ts @@ -1,12 +1,12 @@ export type HandlerListener = (identifier: HandlerIdentifier, payload: unknown) => void; export const enum HandlerIdentifier { - FRESH = "FRESH", - CACHED = "CACHED", - CHANGES = "CHANGES", - LOADING = "LOADING", - INVALID_PATH = "INVALID", - INVALID_COMMAND = "INVALID_COMMAND", - SKIPPING_HANDLER = "SIPPING_HANDLER", - COMPILED = "COMPILED" + FRESH, + CACHED, + CHANGES, + LOADING, + INVALID_PATH, + INVALID_COMMAND, + SKIPPING_HANDLER, + COMPILED }