-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
99 lines (75 loc) · 3.27 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const tmi = require('tmi.js');
let config = require('./config.json')
let fetch = require('node-fetch')
const fs = require("fs");
let epog = require('./epogCommandHandler.js');
const client = new tmi.Client({
connection: {
reconnect: true,
secure: true
},
identity: config.identify,
channels: config.channels
});
let commands = epog.commands.all
if (config.WebhookLogging) {
var URL = config.WebhookURL
let WebhookSend = (message) => {
fetch(URL, {
"method": "POST",
"headers": { "Content-Type": "application/json" },
"body": JSON.stringify({
"content": message
})
})
.then(res => res)
.catch(err => console.error(err));
}
client.on("ban", (channel, username, reason, userstate) => {
WebhookSend(channel + ': ' + username + ' Banned from this channel! Reason: ' + reason)
});
const tierList = { 1000: 'Tier 1', 2000: 'Tier 2', 3000: 'Tier 3' };
client.on('resub', (channel, username, months, message, userstate, methods) => {
let msg = `${username} just resubbed for ${months} month(s)`;
if (methods.prime) msg += ` using Prime for ${months} month(s)`;
else if (methods.plan !== '1000') msg += ` | ${tierList[methods.plan]} `;
WebhookSend(`${channel}: ${msg}!`);
});
client.on("hosted", (channel, username, viewers, autohost) => {
WebhookSend(channel + ': ' + username + ', hosted us with ' + viewers + ' viewers! Thanks for the host ❤️')
})
client.on("raided", (channel, username, viewers) => {
WebhookSend(channel + ': ' + username + ', raided us with ' + viewers + ' viewers! Thanks for the raid ❤️')
})
}
client.on('resub', (channel, username, months, message, userstate, methods) => {
const tierList = { 1000: 'Tier 1', 2000: 'Tier 2', 3000: 'Tier 3' };
let msg = `${username} just resubbed for ${months} month(s)`;
if (methods.prime) msg += ` using Prime for ${months} month(s)`;
else if (methods.plan !== '1000') msg += ` | ${tierList[methods.plan]} `;
client.say(channel, `${msg}!`);
});
client.on('message', (channel, tags, message, self) => {
if (self) return;
const args = message.slice().trim().split(/ +/g)
let cmd = epog.commands.has(args.shift().toLowerCase())
if (cmd) cmd.run(client, channel, tags, message, self, args)
})
client.on("connected", (address, port) => {
console.log('Connected')
epog.initCommands("./commands/");
})
client.on("hosted", (channel, username, viewers, autohost) => {
client.say(channel, username + ', hosted us with ' + viewers + ' viewers! Thanks for the host ❤️')
})
client.on("raided", (channel, username, viewers) => {
client.say(channel, username + ', raided us with ' + viewers + ' viewers! Thanks for the raid ❤️')
})
let CustomCommands = require("./database/commands.json")
client.on('message', (channel, tags, message, self) => {
if (self) return;
const args = message.slice().trim().split(/ +/g)
let cmnd = CustomCommands[channel+'|'+args.shift().toLowerCase()]
if(cmnd) client.say(channel,cmnd.response)
})
client.connect().catch(console.error);