-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (55 loc) · 1.83 KB
/
index.js
File metadata and controls
63 lines (55 loc) · 1.83 KB
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
const tmi = require('tmi.js')
const axios = require('axios')
const config = require('./config.json')
const cooldown = new Set()
const dalert_endpoint = 'https://www.donationalerts.com/api/v1'
const options = {
identity: {
username: config.bot_username,
password: config.oauth_token
},
channels: config.channels
}
const client = new tmi.client(options)
client.on('message', onMessageHandler)
client.on('connected', onConnectedHandler)
client.connect();
async function onMessageHandler (target, context, msg, self) {
if (self) return
if(msg.indexOf(config.prefix) !== 0) return
var args = msg.slice(config.prefix.length).trim().split(/ +/g)
var commandName = args.shift().toLowerCase()
const roomId = context['room-id']
switch (commandName) {
case 'lastdonation':
if(cooldown.has(roomId)) return
cooldown.add(roomId)
try {
const req = await axios({
method: 'get',
url: `${dalert_endpoint}/alerts/donations`,
headers: {
"Authorization": `Bearer ${config.donationAlerts_Token}`
},
validateStatus: false
})
client.say(target, `Последний донат от ${req.data.data[0].username} - ${req.data.data[0].amount} ${req.data.data[0].currency}`)
} catch (error) {
client.say(target, `Возникла ошибка, сообщите об этом создателю канала`)
}
setTimeout(() => {
cooldown.delete(roomId)
}, config.cooldown);
break;
default:
break;
}
}
function rollDice () {
const sides = 6;
return Math.floor(Math.random() * sides) + 1;
}
// Called every time the bot connects to Twitch chat
function onConnectedHandler (addr, port) {
console.log(`* Connected to ${addr}:${port}`);
}