-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (27 loc) · 1.11 KB
/
index.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
const tmi = require('tmi.js');
const execSync = require('child_process').execSync;
// Settings
const speechCommand = 'espeak -p 25 -s 125 -v en-french+15';
const modsOnly = true;
const channelName = 'teklynk';
const ttsCommand = '!tts';
const client = new tmi.Client({
channels: [channelName]
});
client.connect();
client.on('message', (channel, user, message, self) => {
// Ignore echoed messages
if (self) {
return false;
}
if (user['message-type'] === 'chat' && message.startsWith(ttsCommand + ' ')) {
// Escape apostrophes and single quotes
message = message.replace(/'/g, 'A');
// Synchronously execute the speechCommand. This acts like a queue/buffer.
if (modsOnly && (user.mod || user.username.toLowerCase() === channelName.toLowerCase().trim())) {
execSync(speechCommand + " '" + message.substring(ttsCommand.length).trim() + "'");
} else if (!modsOnly || user.username.toLowerCase() === channelName.toLowerCase().trim()) {
execSync(speechCommand + " '" + message.substring(ttsCommand.length).trim() + "'");
}
}
});