-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
69 lines (53 loc) · 1.77 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
const tmi = require('tmi.js');
const config = require("./objects/config")
const AllInOne = require("./objects/allinone");
const Line = require("./objects/line")
const getData = require("./objects/requestHandler")
var ding = new Audio('./sounds/din.mp3');
const ourFullData = new AllInOne();
// Define configuration options
const opts = {
identity: {
username: config.BOT_USERNAME,
password: config.OAUTH_TOKEN
},
channels: [config.CHANNEL_NAME]
};
// Create a client with our options
const client = new tmi.client(opts);
// Register our event handlers (defined below)
client.on('message', onMessageHandler);
client.on('connected', onConnectedHandler);
// Connect to Twitch:
client.connect();
// Called every time a message comes in
function onMessageHandler(target, context, msg, self) {
if (self) { return; } // Ignore messages from the bot
//const commandName = msg.trim().toLowerCase();
getData(context["user-id"])
.then((dt) => {
addCom(context["username"], msg, dt.data.logo, "black")
})
.catch(function(error) {
// handle error
console.log(error);
})
}
// Called every time the bot connects to Twitch chat
function onConnectedHandler(addr, port) {
console.log(`* Connected to ${addr}:${port}`);
addCom("bot", `Connected`, "https://cdn3.iconfinder.com/data/icons/chat-bot-emoji-blue-filled-color/300/3551860Untitled-3-512.png", "white")
}
function addCom(name, text, img, nameColor) {
let newCom = new Line(name, text, img, nameColor);
ourFullData.lines.unshift(newCom)
document.getElementById("root").innerHTML = ourFullData.render()
//playSound(0)
}
function playSound(e) {
// switch (e) {
// default:
ding.play();
// break;
//}
}