-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSongRequestBot.js
56 lines (44 loc) · 1.52 KB
/
SongRequestBot.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
const tmi = require('tmi.js');
const ioHook = require('iohook');
var fs = require('fs');
// Define configuration options
const opts = {
identity: {
username: "USERNAME",
password: "PASSWORD"
},
channels: [
"CHANNEL_NAME"
]
};
// Create a client with our options
const client = new tmi.client(opts);
// Register our event handlers (defined below)
client.on('connected', onConnectedHandler);
// Register and start hook
ioHook.start();
// Connect to Twitch:
client.connect();
// Change working directory to Rocksniffer Output folder
process.chdir('ROCKSNIFFER_OUTPUT_DIRECTORY')
// Activate function that listens for keypress.
ioHook.on('keydown', function(KeyPress) {
// Uncomment the following line to have the script print out the keypress detail for custom configuration
// console.log(KeyPress);
if(KeyPress.keycode == 73){
// Read song_details.txt from RockSniffer to determine 'Artist - Song Title'
fs.readFile('song_details.txt', 'utf8', function(err, data) {
// Throw error if song_details not found
if (err) throw err;
// If song_details.txt not empty, create and send string to chat in the form of '!sr ARTIST - TITLE' for KokoliBot
if (data !== '') {client.say('CHANNEL_NAME','!sr ' + data);}
});
}
if(KeyPress.keycode == 77){
client.say('CHANNEL_NAME','!next');
}
});
// Called every time the bot connects to Twitch chat
function onConnectedHandler (addr, port) {
console.log(`* Connected to ${addr}:${port}`);
}