· 5 years ago · Oct 20, 2019, 08:08 AM
1const TwitchBot = require('twitch-bot');
2const BOTNAME = "неа, неа";
3const OAUTH_TOKEN = "неа, неа";
4const CHANNEL = "zakvielchannel"
5const startCommand = "START BOT"
6const stopCommand = "СТАПИД БОТ"
7const disableCommand = "АСТАНАВИС"
8let text = ("D: ".repeat(100) ) + ("Чтобы остановить бота напишите ") + stopCommand + (" | #$i$")
9const delay = 2000
10const autowaittime = 5 * 60 * 1000
11
12
13///////////////////////////////////////////////////
14
15
16Bot = new TwitchBot({
17 username: BOTNAME,
18 oauth: OAUTH_TOKEN,
19 channels: [CHANNEL]
20})
21
22let disablebyanyone = false
23let disabled = false;
24let autoid = false;
25let iid = false;
26let i = 0;
27
28Bot.on('join', (...p) => {
29 console.log("JOIN: ", ...p);
30});
31
32Bot.on('error', (...p) => {
33 console.log("ERROR: ", ...p);
34});
35
36function start(auto) {
37 console.log((auto ? "AUTO " : "MANUAL ") + "START");
38 disabled = false;
39 if (iid) clearInterval(iid);
40 iid = false;
41 i = 0;
42 iid = setInterval(() => {
43 i += 1;
44 let curText = text.replace('$i$', i);
45 if (curText.length >= 490)
46 curText = "..." + curText.substring((curText.length - 490) + 5);
47 Bot.say(curText);
48 console.log("Message #" + i);
49 }, delay);
50}
51
52Bot.on('message', (msg) => {
53 if (msg.message === startCommand && msg.username === BOTNAME.toLowerCase()) {
54 start(false);
55 }
56 if (msg.message === stopCommand || msg.message == disableCommand) {
57 if (!disabled) {
58 if (iid) clearInterval(iid);
59 iid = false;
60 if (msg.message == disableCommand && (msg.username === BOTNAME.toLowerCase() || disablebyanyone)) {
61 console.log("STOP by " + msg.username + " at msg #" + i);
62 disabled = true;
63 }
64 else {
65 console.log("STOP FOR + autowaittime + by " + msg.username + " at msg #" + i);
66 if (autoid) clearTimeout(autoid);
67 autoid = false;
68 autoid = setTimeout(() => {
69 start(true);
70 }, autowaittime);
71 }
72 }
73 }
74});