-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
72 lines (60 loc) · 1.96 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
const tmi = require('tmi.js');
require('custom-env').env()
const opts = {
identity: {
username: process.env.TWITCH_USERNAME,
password: process.env.TWITCH_PASSWORD,
},
channels: [
process.env.TWITCH_CHANNEL,
]
};
console.log(process.env.TWITCH_USERNAME)
// 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
// Remove whitespace from chat message
const commandName = msg.trim();
var message = ""
if(commandName.indexOf('!') === 0) {
switch (commandName) {
case "!roll":
const num = roll();
message = `@${context['display-name']} rolled a ${num} `
break;
case "!lurk":
message = `@${context['display-name']} Is a legend for lurking in the stream, enjoy the free points fella`
break;
case "!twitter":
message = `https://twitter.com/prawn185`
break;
case "!discord":
message = ` I have a discord so you can get notified when I'm live POG https://discord.gg/VSejbnhPcT`
break;
case "!luckydip":
message = `When you have the appropriate channel points you can choose a number between 1 10 to win £10`
break;
default:
message = `@${context['display-name']} ${commandName} is not a command`
break;
}
client.say(target, message);
}
}
// Function called when the "dice" command is issued
function roll () {
const sides = 999;
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}`);
console.log("Ready and waiting for your command");
}