-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.js
171 lines (135 loc) · 5.33 KB
/
handlers.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const client = require('./client').obtenerCliente();
const fn = require('./functions');
const strErrMsg = 'Oops! algo rarito ocurrió, estoy malito, pásenme la cobijita';
function onMessageHandler(channel, tags, message, self){
if (self) return;
let msg = message.toLowerCase();
const originalMsg = msg;
if(msg.indexOf('!cuenta') == 0){
msg = '!cuenta';
}
switch (msg) {
// Use 'tags' to obtain the username of the one who has keyed in a certain input
// 'channel' shall be used to specify the channel name in which the message is going to be displayed
// For one to send a message in a channel, you specify the channel name, then the message
// We shall use backticks when using tags to support template interpolation in JavaScript
case 'holiwis':
client.say(channel, `${tags.username}, hola!`).catch(err => console.error({err}));
break;
case '!minivel':
try{
if(tags.badges == null){
client.say(channel, `${tags.username} eres un simple mortal`);
return;
}
if(!fn.esBroadcaster(tags) && !fn.esMod(tags) && !fn.esVip(tags)){
client.say(channel, `${tags.username} eres un simple mortal, ten un dorito DoritosChip`);
return;
}
if(fn.esVip(tags)){
client.say(channel, `${tags.username} has sido bendecid@ por los dioses`);
return;
}
if(fn.esBroadcaster(tags)){
client.say(channel, `MercyWing1 ${tags.username} MercyWing2 eres el diosito o la diosita del olimpo del canal, aquí se hace tu voluntad`);
return;
}
if(fn.esMod(tags)){
client.say(channel, `${tags.username} eres un@ modsit@ <3`);
return;
}
}
catch(err){
console.error(channel, tags.username, tags, message, self, err);
client.say(channel, strErrMsg);
}
break;
case '!cuenta':
try{
if(!fn.esBroadcaster(tags) && !fn.esMod(tags)){
client.say(channel, `${tags.username} no puedes usar el comando !cuenta FootYellow`);
return;
}
let inicio = 5;
const max = 30;
const m = originalMsg.replace(/\s+/g,' ');
const partes = m.split(' ');
if(partes.length > 1 && !Number.isNaN(partes[1]*1) && Number.isInteger(eval(partes[1]))){
inicio = eval(partes[1]);
if(inicio > max){
client.say(channel, `No se puede iniciar la cuenta en ${inicio}, se iniciará en 5`);
}
inicio = (inicio <= max)? inicio : 5;
}
setTimeout(() => {fn.countdown(client, channel, inicio);}, 500);
}
catch(err){
console.error(channel, tags.username, tags, message, self, err);
client.say(channel, strErrMsg);
}
break;
case '!timer':
try{
if(!fn.esBroadcaster(tags) && !fn.esMod(tags)){
client.say(channel, `${tags.username} no puedes usar el comando !timer FootYellow`);
return;
}
const minutes = 5;
fn.setTimer(client, channel, minutes*60);
}
catch(err){
console.error(err);
client.say(channel, strErrMsg);
}
break;
case '!stoptimer':
try{
if(!fn.esBroadcaster(tags) && !fn.esMod(tags)){
client.say(channel, `${tags.username} no puedes usar el comando !stoptimer FootYellow`);
return;
}
fn.stopTimer(client, channel);
}
catch(err){
console.error(err);
client.say(channel, strErrMsg);
}
break;
case '!clip':
try{
if(!fn.esBroadcaster(tags) && !fn.esMod(tags)){
client.say(channel, `${tags.username} no puedes usar el comando !clip FootYellow`);
return;
}
fn.createClip(client, channel);
}
catch(err){
console.error(err);
client.say('bibi_watson', strErrMsg);
}
}
}
function onJoinHandler(channel, nick, anonymous) {
console.log('join', {channel, nick, anonymous});
if(process.env.NO_SALUDAR.indexOf(nick) >= 0){
console.log(`${nick} no quiere ser saludad@`);
return;
}
setTimeout(()=>{client.say(channel, `Bienvenid@ ${nick}`);}, 3000);
}
function onRitualHandler(ritualName, channel, username, tags, msg){
console.log({ritualName, channel, username, tags, msg});
}
function onNewChatterHandler(channel, username, tags, msg){
console.log('NEWCHATTER', {channel, username, tags, msg});
}
function onPingHandler(){
console.log('ping...');
}
module.exports = {
onMessageHandler,
onJoinHandler,
onPingHandler,
onRitualHandler,
onNewChatterHandler
}