-
Notifications
You must be signed in to change notification settings - Fork 1
/
manual.js
51 lines (40 loc) · 1.46 KB
/
manual.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
require('dotenv').config()
const Twitch = require("twitch-js");
const axios = require("axios");
const fs = require("fs");
// Command
const COMMAND_NAME = "!talk"; // Command to type in chat.
// Check .env
if(process.env.TWITCH_CHANNEL === "") {
console.error(`You must enter a Twitch channel.`);
process.exit();
}
// Command cooldown
const COMMAND_COOLDOWN = Number(process.env.COMMAND_COOLDOWN);
let commandLastUsed = 0;
const client = new Twitch.client({
channels: [`#${process.env.TWITCH_CHANNEL}`]
});
// Twitch chat listener
client.on('chat', (channel, userstate, message, self) => {
// Is user that's posting a mod or broadcaster?
if(Math.round((new Date()).getTime() / 1000) > commandLastUsed + COMMAND_COOLDOWN) {
if(userstate.badges != null && userstate.badges.hasOwnProperty("broadcaster") && userstate.badges.broadcaster === '1' || userstate.mod === false) {
message = message.toLowerCase();
if(message.indexOf(COMMAND_NAME) === 0) { // sent !talk command
message = message.split(" ");
if(message.length > 1) { // sent prompt
message.shift();
message = message.join(" ");
// Write the message to a text file
fs.writeFileSync("prompt.txt", message);
// Call the Python script to perform text-to-speech
const spawn = require("child_process").spawn;
spawn("python", ["text_to_speech.py"]);
}
}
}
}
});
// Connect to twitch chat
client.connect();