From 1aa0fbb9e281ed8b4e230a38ab205241cc39a078 Mon Sep 17 00:00:00 2001 From: Jaron Date: Wed, 15 Jan 2025 14:50:48 -0500 Subject: [PATCH] Added workflow and fixed bug with command handling --- .github/workflows/{main.yml => ci.yml} | 2 +- .github/workflows/publish.yml | 21 +++++++++++---------- package.json | 6 +++--- src/services/bus.ts | 1 + src/services/connectors/gateway.ts | 16 ++++++++-------- src/services/processor.ts | 3 +++ 6 files changed, 27 insertions(+), 22 deletions(-) rename .github/workflows/{main.yml => ci.yml} (97%) diff --git a/.github/workflows/main.yml b/.github/workflows/ci.yml similarity index 97% rename from .github/workflows/main.yml rename to .github/workflows/ci.yml index 50d01a9..adf1830 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: CI +name: CI (template) on: workflow_dispatch jobs: build: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 98c2566..0dc0802 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,14 +4,15 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 - with: - node-version: 14 - registry-url: https://registry.npmjs.org/ - - run: yarn - - run: yarn build - # - run: yarn test - - run: yarn publish --access public + # Pull repo + - uses: actions/checkout@v2 + # Install bun + - uses: oven-sh/setup-bun@v2 + # Run tests + # TODO: Add tests + # Build + - run: bun build + # Publish + - run: bun publish env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} \ No newline at end of file + NPM_CONFIG_REGISTRY: https://registry.npmjs.org/_authToken=${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index 7301834..5b52522 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "unicord", - "description": "A simple discord library primarily for TypeScript. REST like and easy to use.", - "version": "0.0.3", + "description": "A simple discord library primarily for TypeScript. Web server like and easy to use.", + "version": "0.0.4", "module": "src/index.ts", "type": "module", "main": "out/index.js", @@ -17,7 +17,7 @@ "build:packages": "bun run build:types && bun run build:core -- --packages external", "build:nocheck": "bun run build:types:nocheck && bun run build:core", - "build:core": "bun build src/index.ts --outdir out --drop=console --drop=debugger", + "build:core": "bun build src/index.ts --outdir out --drop=debugger", "build:types": "tsc --emitDeclarationOnly --project tsconfig.json", "build:types:nocheck": "bun run build:types -- --noCheck", diff --git a/src/services/bus.ts b/src/services/bus.ts index 7f96f55..e5bd283 100644 --- a/src/services/bus.ts +++ b/src/services/bus.ts @@ -5,6 +5,7 @@ const EventBus = new EventEmitter() as Emitter; export type Emitter = EventEmitter & { emit: (event_name: string, context: Context | null, ...args: any[]) => boolean + on: (event_name: string, listener: Function) => Emitter } export { EventBus }; \ No newline at end of file diff --git a/src/services/connectors/gateway.ts b/src/services/connectors/gateway.ts index ae0b2a2..241b9c5 100644 --- a/src/services/connectors/gateway.ts +++ b/src/services/connectors/gateway.ts @@ -205,15 +205,15 @@ export class Gateway { // Generate context const context = new Context(this.client, this.api, { message }); // Dispatch event for the command - this.bus.emit(`command:${command}`, context, args); + // this.bus.emit(`${HandlerType.ChatCommands}:${command}`, context, args); // // Check if command exists - // if (this.processor[HandlerType.ChatCommands].has(command)) { - // // Execute the handler - // this.processor[HandlerType.ChatCommands].execute(command, context, args); - // } else { - // // TODO: Custom unknown command handler - // context.reply(`Unknown command: ${command}`); - // } + if (this.processor[HandlerType.ChatCommands].has(command)) { + // Execute the handler + this.processor[HandlerType.ChatCommands].execute(command, context, args); + } else { + // TODO: Custom unknown command handler + // context.reply(`Unknown command: ${command}`); + } } }; diff --git a/src/services/processor.ts b/src/services/processor.ts index cdbde1f..7d2fbe8 100644 --- a/src/services/processor.ts +++ b/src/services/processor.ts @@ -64,6 +64,9 @@ export class Processor { throw new Error('Event handlers cannot be a CommandHandler'); } // Validate and resolve the args + // TODO: There's no reason this can't use the hydrator system + // Hydrator should have a more genric subcomponent that can be used anywhere and is more dumb. + // Basically a function that accepts id's and returns values. const resolvedArgs = await this.validateAndResolveArgs(argsOrPayload, handler.args); // Execute the handler await Promise.resolve(handler[Trait.execute](context!, resolvedArgs));