mirror of
https://github.com/xHyroM/roles-bot.git
synced 2024-11-21 16:11:04 +01:00
feat(bot): add commands, structs
This commit is contained in:
parent
f22e1d6430
commit
eebc948a58
6 changed files with 57 additions and 1 deletions
5
packages/bot/src/commands/setup.ts
Normal file
5
packages/bot/src/commands/setup.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { Command } from "../structs/Command";
|
||||
|
||||
new Command({
|
||||
name: "setup",
|
||||
});
|
|
@ -1,3 +1,8 @@
|
|||
import "./commands/setup";
|
||||
import { COMMANDS } from "./registers";
|
||||
|
||||
console.log(COMMANDS);
|
||||
|
||||
export default {
|
||||
fetch: (request: Request) => {
|
||||
console.log(request);
|
||||
|
|
13
packages/bot/src/registers.ts
Normal file
13
packages/bot/src/registers.ts
Normal file
|
@ -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);
|
||||
};
|
15
packages/bot/src/structs/Command.ts
Normal file
15
packages/bot/src/structs/Command.ts
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
18
packages/bot/src/structs/Listener.ts
Normal file
18
packages/bot/src/structs/Listener.ts
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -8,4 +8,4 @@
|
|||
"esModuleInterop": true,
|
||||
"types": ["@cloudflare/workers-types", "jest"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue