From eebc948a58fbc045edd8bdc2b327ce1205f4b991 Mon Sep 17 00:00:00 2001 From: xHyroM Date: Wed, 5 Apr 2023 14:44:17 +0200 Subject: [PATCH] feat(bot): add commands, structs --- packages/bot/src/commands/setup.ts | 5 +++++ packages/bot/src/index.ts | 5 +++++ packages/bot/src/registers.ts | 13 +++++++++++++ packages/bot/src/structs/Command.ts | 15 +++++++++++++++ packages/bot/src/structs/Listener.ts | 18 ++++++++++++++++++ packages/bot/tsconfig.json | 2 +- 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 packages/bot/src/commands/setup.ts create mode 100644 packages/bot/src/registers.ts create mode 100644 packages/bot/src/structs/Command.ts create mode 100644 packages/bot/src/structs/Listener.ts diff --git a/packages/bot/src/commands/setup.ts b/packages/bot/src/commands/setup.ts new file mode 100644 index 0000000..848b119 --- /dev/null +++ b/packages/bot/src/commands/setup.ts @@ -0,0 +1,5 @@ +import { Command } from "../structs/Command"; + +new Command({ + name: "setup", +}); diff --git a/packages/bot/src/index.ts b/packages/bot/src/index.ts index 1591aac..0349ffb 100644 --- a/packages/bot/src/index.ts +++ b/packages/bot/src/index.ts @@ -1,3 +1,8 @@ +import "./commands/setup"; +import { COMMANDS } from "./registers"; + +console.log(COMMANDS); + export default { fetch: (request: Request) => { console.log(request); diff --git a/packages/bot/src/registers.ts b/packages/bot/src/registers.ts new file mode 100644 index 0000000..47cb39d --- /dev/null +++ b/packages/bot/src/registers.ts @@ -0,0 +1,13 @@ +import { Command } from "./structs/Command"; +import { Listener } from "./structs/Listener"; + +export const COMMANDS: Command[] = []; +export const LISTENERS: Listener[] = []; + +export const registerCommand = (command: Command) => { + COMMANDS.push(command); +}; + +export const registerListener = (listener: Listener) => { + LISTENERS.push(listener); +}; diff --git a/packages/bot/src/structs/Command.ts b/packages/bot/src/structs/Command.ts new file mode 100644 index 0000000..1763af1 --- /dev/null +++ b/packages/bot/src/structs/Command.ts @@ -0,0 +1,15 @@ +import { registerCommand } from "../registers"; + +interface CommandOptions { + name: string; +} + +export class Command { + public name: string; + + constructor(options: CommandOptions) { + this.name = options.name; + + registerCommand(this); + } +} diff --git a/packages/bot/src/structs/Listener.ts b/packages/bot/src/structs/Listener.ts new file mode 100644 index 0000000..c6b1ff2 --- /dev/null +++ b/packages/bot/src/structs/Listener.ts @@ -0,0 +1,18 @@ +import { registerListener } from "../registers"; + +interface ListenerOptions { + name: string; + once: boolean | undefined; +} + +export class Listener { + public name: string; + public once: boolean; + + constructor(options: ListenerOptions) { + this.name = options.name; + this.once = options.once ?? false; + + registerListener(this); + } +} diff --git a/packages/bot/tsconfig.json b/packages/bot/tsconfig.json index 2bc338a..bcc3ab9 100644 --- a/packages/bot/tsconfig.json +++ b/packages/bot/tsconfig.json @@ -8,4 +8,4 @@ "esModuleInterop": true, "types": ["@cloudflare/workers-types", "jest"] } -} \ No newline at end of file +}