summary refs log tree commit diff
path: root/src-slowcord/bot/src/Bot.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-25 18:24:21 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-25 23:35:18 +1000
commitf44f5d7ac2d24ff836c2e1d4b2fa58da04b13052 (patch)
treea6655c41bb3db79c30fd876b06ee60fe9cf70c9b /src-slowcord/bot/src/Bot.ts
parentAllow edited_timestamp to passthrough in handleMessage (diff)
downloadserver-f44f5d7ac2d24ff836c2e1d4b2fa58da04b13052.tar.xz
Refactor to mono-repo + upgrade packages
Diffstat (limited to 'src-slowcord/bot/src/Bot.ts')
-rw-r--r--src-slowcord/bot/src/Bot.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/src-slowcord/bot/src/Bot.ts b/src-slowcord/bot/src/Bot.ts
new file mode 100644

index 00000000..45938846 --- /dev/null +++ b/src-slowcord/bot/src/Bot.ts
@@ -0,0 +1,48 @@ +import { Message } from "discord.js"; +import { Client } from "fosscord-gopnik/build/lib"; // huh? oh well. some bugs in my lib Ig + +import { Command, getCommands } from "./commands/index.js"; + +export default class Bot { + client: Client; + commands: { [key: string]: Command; } = {}; + + constructor(client: Client) { + this.client = client; + } + + onReady = async () => { + this.commands = await getCommands(); + + console.log(`Logged in as ${this.client.user!.tag}`); + + this.client.user!.setPresence({ + activities: [{ + name: "EVERYTHING", + type: "WATCHING", + }] + }); + }; + + onMessageCreate = async (msg: Message) => { + const prefix = process.env.PREFIX as string; + if (msg.author.bot) return; + if (!msg.content || msg.content.indexOf(prefix) === -1) return; + + const content = msg.content.slice(prefix.length).split(" "); + const cmd = content.shift(); + if (!cmd) return; + const args = content; + + const command = this.commands[cmd]; + if (!command) return; + + await command.exec({ + user: msg.author, + member: msg.member, + guild: msg.guild, + message: msg, + args: args, + }); + }; +} \ No newline at end of file