-
Notifications
You must be signed in to change notification settings - Fork 59
/
server.js
47 lines (40 loc) · 1.38 KB
/
server.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
const tmi = require("tmi.js");
const keyHandler = require("./keyHandler.js");
const config = require("./config.js");
// https://github.com/tmijs/tmi.js#tmijs
// for more options
const client = new tmi.client({
connection: {
secure: true,
reconnect: true,
},
channels: [config.channel],
});
const commandRegex =
config.regexCommands ||
new RegExp("^(" + config.commands.join("|") + ")$", "i");
client.on("message", function (channel, tags, message, self) {
let isCorrectChannel = `#${config.channel}` === channel;
let messageMatches = message.match(commandRegex);
if (self) return;
if (isCorrectChannel && messageMatches) {
// print username and message to console
console.log(`@${tags.username}: ${message}`);
// send the message to the emulator
keyHandler.sendKey(message.toLowerCase());
}
});
client.addListener("connected", function (address, port) {
console.log("Connected! Waiting for messages..");
});
client.addListener("disconnected", function (reason) {
console.log("Disconnected from the server! Reason: " + reason);
});
client.connect();
if (config.channel === 'twitchplayspokemon') {
console.log("");
console.log("'twitchplayspokemon' is the default channel! Otherwise, run with the environment variable: ");
console.log("TWITCH_CHANNEL=mychannelhere npm start");
console.log("");
}
console.log(`Connecting to /${config.channel}..`);