-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (40 loc) · 1.26 KB
/
index.js
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
50
51
require("dotenv").config();
const TMI = require("tmi.js");
const fs = require("node:fs");
const path = require("node:path");
const client = new TMI.Client({
options: { debug: true },
identity: {
username: process.env.USERNAME,
password: process.env.OAUTH_TOKEN,
},
channels: ["Kingerious"],
});
client.connect().catch(console.error);
const greetings = ["hi", "hello", "hey", "heyo", "hiyo"];
const byes = ["bye", "cya", "goodbye", "see ya", "gtg"];
const commands = [];
const commandsPath = path.join(__dirname, "./commands");
const commandFiles = fs
.readdirSync(commandsPath)
.filter((f) => f.endsWith(".js"));
for (const command of commandFiles) {
const commandContent = require(path.join(commandsPath, command));
commands.push({
name: commandContent.name,
execute: commandContent.execute,
});
}
client.on("message", (channel, { username }, message, self) => {
if (self) return;
if (greetings.includes(message))
return client.say(channel, `Hello there @${username}!`);
if (byes.includes(message)) return client.say(channel, `Bye @${username}!`);
if (message.startsWith("!")) {
commands.map((obj) => {
if (obj.name == message.split("!")[1]) {
obj.execute(channel, username, message, client);
}
});
}
});