summary refs log tree commit diff
path: root/slowcord/bot/src/Bot.ts
blob: a89102e63c1f34eee0ed89f6fd428e6431817989 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 = (msg: Message) => {
		const prefix = process.env.PREFIX as string;
		if (msg.content.indexOf(prefix) === -1) return;
		if (msg.author.bot) 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;

		command.exec({
			user: msg.author,
			member: msg.member,
			guild: msg.guild,
			message: msg,
			args: args,
		});
	};
}