/
bimbot.php
336 lines (320 loc) · 9.12 KB
/
bimbot.php
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<?php
define('TOKEN', '152945078:AAHRok2HuvSYRXxs55RLvVWoa0t3Org8u9c');
define('API_URL', 'https://api.telegram.org/bot' . TOKEN . '/');
define('TEST', 0);
define('TEST_MESSAGE', 'hola');
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (TEST)
{
$update = array (
'message' => array (
'text' => TEST_MESSAGE,
'message_id' => 1,
'chat' => array ('id' => 1)
),
);
}
if (isset($update['message']))
{
$message = $update['message'];
$message_id = $message['message_id'];
$chat_id = $message['chat']['id'];
$text = strtolower($message['text']);
$from = $message['from']['first_name'];
$response = handleText($text, $from);
if ($response && !isMuted())
{
if (TEST)
{
echo $response;
}
else
{
$aux = explode(':', $response);
if (count($aux) === 2 && $aux[0] === 'sticker')
{
// NO ANDA
apiRequestJson("sendSticker", array (
'chat_id' => $chat_id,
'sticker' => $aux[1] // no se como mierda hay que pasarle el file_id del sticker ni de donde sacarlo
));
}
else
{
apiRequestJson("sendMessage", array (
'chat_id' => $chat_id,
'text' => $response
));
}
}
}
}
function handleTextWords($words, $from)
{
$needles = array (
'%mood%' => array ('como', 'te', 'sentis'),
'%setmood%' => array ('/setmood'),
'forro sos vos hijode putea' => array ('oso', 'forro'),
'dale men, hasta yo tengo foto de perfil' => array ('belilos', 'foto'),
'yo me re prendo a una hackathon eh' => array ('hackathon'),
'belilos es un cagón' => array ('belilos'),
"\xE2\x9D\xA4" => array ('tkm'),
'de nada ameo' => array ('gracias'),
'viva el mct' => array ('mct'),
'%hello%' => array ('bimbo'),
'%song%' => array ('cantate'),
'%love%' => array ('te', 'amo'),
'que te pasa con fargo pelotudo' => array ('fargo'),
'https://github.com/servani/bimbot' => array ('repo'),
'%pija%' => array ('pija'),
'vamo a lo de piche a fumar unos' => array ('droga'),
'vamo a lo de pichettoooo a fumar unos' => array ('porro'),
'denme un ak47 ' => array ('faso'),
'estoy re manija vamo a lo de facu a fumanchea' => array ('fumar'),
'la que le gusta a tu hermana' => array ('marihuana'),
'%name%' => array ('el', 'mas', 'puto'),
'mmmmmnnnnnnnnnmusaaaraña musaraña musaraña musaraña' => array ('musa'),
'que sera que sera de la vida del gran yamid' => array ('que', 'sera'),
'el tunel de monroe es una maaaaaasssssssaaa' => array ('monroe'),
'ipad? si el que se gano el hijo de puta de belilos' => array ('ipad'),
'aguante bluesmart' => array ('bluesmart'),
'con esta pelotudo' => array ('con', 'que'),
'sabes donde te podes meter el corazoncito?' => array ('❤'),
'nada re tranki aca en pija' => array ('que', 'pasando'),
'ni bigote ni manco, CRISTINA LOCO PORQUE NESTOR NO SE MURIO LO LLEVO EN EL CORAZON VIVA PERON HIJOS DE PUTA' => array ('macri', 'scioli'),
'no soy un oso de mierda, soy un oso barrilete y vendehumo iiiiiiiiiiiiaja' => array ('oso', 'mierda')
);
foreach ($needles as $message => $needle)
{
if (count(array_intersect($needle, $words)) === count($needle))
{
$names = array (
'beli', 'miola', 'pato', 'guille', 'santi',
'facu', 'fede', 'la musa', 'luigi', 'erni',
'el forro de schattenhofer'
);
shuffle($names);
if ($message === "%name%")
{
$message = $names[0];
}
elseif ($message === "%love%")
{
$message = 'yo te amo a vos ' . strtolower($from);
}
elseif ($message === "%pija%")
{
$message = 'pija? a ' . $names[0] . ' le gusta la pija';
}
elseif ($message === "%setmood%" && $words[0] === '/setmood')
{
unset($words[0]);
$mood = implode(' ', $words);
setMood($mood);
$message = 'ok';
}
elseif ($message === "%mood%")
{
$message = getMood();
}
elseif ($message === "%hello%")
{
$hellos = array (
'que onda wachos',
'que onda loco',
'que pasa',
'me llamaste? hijo de puta?',
'me tienen los huevos por el piso',
'uhmmm',
'que pesados q estan loco vayansen a la concha de su hermana',
'estaba pensando en ' . $names[0],
'ke',
'basta loco',
'che ' . $names[0] . ' necesito que me des una mano con algo',
'bimbbobim',
'shicos hishe un shcript en corshetes adivinen quein soy',
'dale loco mentanle mano al codigo que me hinche los huevos de decir siempre lo mismo'
);
shuffle($hellos);
$message = $hellos[0];
}
elseif ($message === "%song%")
{
$hellos = array (
'tu novia puta con mi pingo se ahooga y vos no decis nada pporque sooo un toga recatate giiiiil',
'vamoooos vamoos a bailaaaaar vamoos a bailar hasta la madrugada dejate llevaaaar',
'tetereré tere tete tetereré tere re re',
'tchê tcherere tchê tchê, tcherere tchê tchê, tcherere tchê tchê, tchereretchê tchê, tchê, tchê, el oso bimbo e você',
'nossa, nossa assim você me mata ai se eu te pego, ai ai se eu te pego',
'chora, me liga implora o meu beijo de novo me pede socorro'
);
shuffle($hellos);
$message = $hellos[0];
}
return $message;
}
}
return false;
}
function handleTextSingleWord($word)
{
$magic_words = array (
'jajaja' => '%haha%',
'JAJA' => 'JAJAJAJAJJA',
'bimbo' => 'que te pasa pelotudo',
'gracias' => 'de nada ameo',
'mct' => 'viva el mct',
'hola' => 'holis',
'holi' => 'holis',
'/unmute' => 'SOY LIBREEEEEEE',
'/mute' => '',
'nada' => 'AH BUENJO mejor asi hijo deputa',
'pelado' => 'sticker:260429632665289106',
'tkm' => "\xE2\x9D\xA4",
);
foreach ($magic_words as $needle => $message)
{
if (strpos($word, $needle) !== FALSE)
{
if ($needle === "/mute")
{
mute();
}
elseif ($needle === "/unmute")
{
unmute();
}
elseif ($message === "%haha%")
{
$haha = array (
'jajajaja',
'jjajajajaj',
'hahahahaha',
'jiji',
'JAJAJAJAJ AH RE LOKO',
'jajajaj ah re',
'haha',
'jajajjaj',
'basat',
'basta no es gracioso',
);
shuffle($haha);
$message = $haha[0];
}
return $message;
}
}
return false;
}
function handleText($text, $from)
{
if (strpos($text, "simon dice") === 0)
{
return substr($text, 11);
}
$words = explode(' ', $text);
if (count($words))
{
$response = handleTextWords($words, $from);
}
if (!$response)
{
$response = handleTextSingleWord($text);
}
return $response;
}
function apiRequestJson($method, $parameters)
{
if (!is_string($method))
{
error_log("Method name must be a string\n");
return false;
}
if (!$parameters)
{
$parameters = array();
}
else if (!is_array($parameters))
{
error_log("Parameters must be an array\n");
return false;
}
$parameters["method"] = $method;
$handle = curl_init(API_URL);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($parameters));
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
return exec_curl_request($handle);
}
function exec_curl_request($handle)
{
$response = curl_exec($handle);
if ($response === false)
{
$errno = curl_errno($handle);
$error = curl_error($handle);
error_log("Curl returned error $errno: $error\n");
curl_close($handle);
return false;
}
$http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
curl_close($handle);
if ($http_code >= 500)
{
sleep(10);
return false;
}
else if ($http_code != 200)
{
$response = json_decode($response, true);
error_log("Request has failed with error {$response['error_code']}: {$response['description']}\n");
if ($http_code == 401)
{
throw new Exception('Invalid access token provided');
}
return false;
}
else
{
$response = json_decode($response, true);
if (isset($response['description']))
{
error_log("Request was successfull: {$response['description']}\n");
}
$response = $response['result'];
}
return $response;
}
function isMuted()
{
$mem = new Memcached();
$mem->addServer("127.0.0.1", 11211);
return $mem->get('mute');
}
function mute()
{
$mem = new Memcached();
$mem->addServer("127.0.0.1", 11211);
return $mem->set('mute', 1);
}
function unmute()
{
$mem = new Memcached();
$mem->addServer("127.0.0.1", 11211);
return $mem->set('mute', 0);
}
function setMood($mood)
{
$mem = new Memcached();
$mem->addServer("127.0.0.1", 11211);
$mem->set('mood', $mood);
}
function getMood()
{
$mem = new Memcached();
$mem->addServer("127.0.0.1", 11211);
return $mem->get('mood') ?: 'bien';
}