refactor: commands, listeners

This commit is contained in:
Jozef Steinhübl 2023-08-23 07:14:18 +02:00
parent 23a8fd94c4
commit 01fc5af809
9 changed files with 32 additions and 16 deletions

1
src/commands/index.ts Normal file
View file

@ -0,0 +1 @@
import "./version.ts"

View file

@ -1 +1,6 @@
export default {}; import { defineCommand } from "../loaders/commands";
export default defineCommand({
name: "version",
run: (context) => {}
});

View file

@ -1,4 +1,5 @@
import "./loaders"; import "./commands"
import "./listeners";
import { Bubu } from "./structs/Client.ts"; import { Bubu } from "./structs/Client.ts";

1
src/listeners/index.ts Normal file
View file

@ -0,0 +1 @@
import "./ready.ts";

View file

@ -1,9 +1,10 @@
import { defineListener } from "../loaders/listeners.ts"; import { defineListener } from "../loaders/listeners.ts";
import { Events } from "discord.js"; import { Client, Events } from "discord.js";
defineListener({ defineListener({
event: Events.ClientReady, event: Events.ClientReady,
run: (client) => { once: true,
run: (client: Client) => {
console.log("heeh"); console.log("heeh");
} }
}) })

View file

@ -1,2 +1,12 @@
import "../commands/version.ts"; interface Command {
name: string;
run: (
context
) => any;
}
export const COMMANDS: Map<string, Command> = new Map();
export function defineCommand<T extends Command>(command: T) {
COMMANDS.set(command.name, command);
}

View file

@ -1,2 +0,0 @@
import "./commands.ts";
import "./listeners.ts";

View file

@ -1,8 +1,8 @@
import { ClientEvents, Events } from "discord.js"; import type { ClientEvents } from "discord.js";
import "../listeners/ready.ts";
interface Listener<E extends keyof ClientEvents> { interface Listener<E extends keyof ClientEvents> {
event: E; event: E;
once?: boolean;
run: ( run: (
...args: ClientEvents[E] ...args: ClientEvents[E]
) => any; ) => any;

View file

@ -1,12 +1,11 @@
import { Client, GatewayIntentBits, } from "discord.js"; import { Client, GatewayIntentBits } from "discord.js";
export const Bubu = new Client({ export const Bubu = new Client({
intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent | GatewayIntentBits.GuildMembers,
//intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent | GatewayIntentBits.GuildMembers, allowedMentions: {
//allowedMentions: { parse: [],
// parse: [], repliedUser: false,
// repliedUser: false, }
//}
}); });
Bubu.on("error", console.log); Bubu.on("error", console.log);