Skip to content

Commit

Permalink
Emit to debug listener instead of logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Didas-git committed May 28, 2024
1 parent 41900fa commit 3466513
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/handlers/src/advanced/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);
Expand Down
16 changes: 8 additions & 8 deletions packages/handlers/src/advanced/shared.ts
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 3466513

Please sign in to comment.