forked from ChaitanyaLKulkarni/COCBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.js
66 lines (56 loc) · 1.67 KB
/
bot.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const tmi = require("tmi.js");
const prefix = process.env.BOT_PREFIX;
const client = new tmi.Client({
options: {},
connection: {
reconnect: true,
secure: true,
},
identity: {
username: process.env.BOT_NICK,
password: process.env.TMI_TOKEN,
},
channels: process.env.CHANNELS.split(","),
});
client.connect().catch(console.error);
client.on("message", async (channel, user, message, self) => {
if (self) return;
if (message[0] !== prefix) return;
message = message.slice(prefix.length);
channel = channel.slice(1); //Removes #
const isMod =
user.mod || user["user-type"] === "mod" || channel === user.username;
channel = channel.toLowerCase();
opts = message.split(" ");
cmd = opts.shift();
console.log(cmd);
let op = "";
switch (cmd) {
case "coc":
op = await client.on_cocCmd(channel, opts, isMod);
break;
case "link":
case "l":
op = await client.on_linkCmd(channel, opts, isMod);
break;
case "add":
case "set":
op = await client.on_addCmd(channel, opts, isMod);
break;
case "remove":
case "reset":
op = await client.on_removeCmd(channel, opts, isMod);
break;
case "help":
op = client.on_helpCmd(channel, opts, isMod);
for (const o of op) {
if (!o) continue;
await client.say(channel, o);
}
return;
default:
op = await client.on_elseCmd(channel, cmd, isMod);
}
if (op) client.say(channel, op);
});
module.exports = client;