-
Notifications
You must be signed in to change notification settings - Fork 2
/
funcs.php
644 lines (596 loc) · 22.5 KB
/
funcs.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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
<?php
function buildDatabaseConnection($config) {
//Connect to DB only here to save response time on other commands
try {
$dbConnection = new PDO('mysql:dbname=' . $config['dbname'] . ';host=' . $config['dbserver'] . ';charset=utf8mb4', $config['dbuser'], $config['dbpassword'], array(PDO::ATTR_TIMEOUT => 25));
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
notifyOnException('Database Connection', $config, '', $e);
}
return $dbConnection;
}
function notifyOnException($subject, $config, $sql = '', $e = '') {
global $chatId;
sendMessage(175933892, 'Bruv, sometin in da database is ded, innit? Check it out G. ' . $e);
$to = $config['mail'];
$txt = __FILE__ . ' ' . $sql . ' Error: ' . $e;
$headers = 'From: ' . $config['mail'];
mail($to, $subject, $txt, $headers);
http_response_code(200);
die();
}
function sendMessage($chatId, $text, $replyTo = '', $replyMarkup = '') {
if (mb_strlen($text) > 4096) {
sendMessage($chatId, substr($text, 0, 4096), $replyTo, $replyMarkup);
return sendMessage($chatId, substr($text, 4096), $replyTo, $replyMarkup);
} else {
$data = array(
'disable_web_page_preview' => true,
'parse_mode' => 'html',
'chat_id' => $chatId,
'text' => $text,
'reply_to_message_id' => $replyTo,
'reply_markup' => $replyMarkup
);
return makeApiRequest('sendMessage', $data);
}
}
function answerCallbackQuery($queryId, $text = '') {
$data = array(
'callback_query_id' => $queryId,
'text' => $text
);
return makeApiRequest('answerCallbackQuery', $data);
}
function makeApiRequest($method, $data) {
global $config, $client;
if (!($client instanceof \GuzzleHttp\Client)) {
$client = new \GuzzleHttp\Client(['base_uri' => $config['url']]);
}
try {
$response = $client->request('POST', $method, array('json' => $data));
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
$body = $e->getResponse()->getBody();
mail($config['mail'], 'Error', print_r($body->getContents(), true) . "\n" . print_r($data, true) . "\n" . __FILE__);
return false;
}
return json_decode($response->getBody(), true)['result'];
}
function sendChatAction($chatId, $action) {
$actionList = array(
"typing",
"upload_photo",
"record_video",
"upload_video",
"record_audio",
"upload_audio",
"upload_document",
"find_location",
"record_video_note",
"upload_video_note"
);
if (in_array($action, $actionList)) {
$data = array(
'chat_id' => $chatId,
'action' => $action
);
return makeApiRequest('sendChatAction', $data);
}
}
function createPoll($userId, $userName, $userMessageId, $feedbackMessageId, $title) {
global $dbConnection, $config;
try {
$sql = "INSERT INTO polls(user_id, user_name, user_message_id, feedback_message_id, title) VALUES ('$userId', '$userName', '$userMessageId', '$feedbackMessageId', $title)";
$stmt = $dbConnection->prepare('INSERT INTO polls(user_id, user_name, user_message_id, feedback_message_id, title) VALUES (:userId, :userName, :userMessageId, :feedbackMessageId, :title)');
$stmt->bindParam(':userId', $userId);
$stmt->bindParam(':userName', $userName);
$stmt->bindParam(':userMessageId', $userMessageId);
$stmt->bindParam(':feedbackMessageId', $feedbackMessageId);
$stmt->bindParam(':title', $title);
$stmt->execute();
} catch (PDOException $e) {
notifyOnException('Database Insert', $config, $sql, $e);
}
}
function getPoll($userId, $feedbackMessageId, $inlineQueryMessageId = '') {
global $dbConnection, $config;
if (empty($inlineQueryMessageId)) {
try {
$sql = "SELECT id, status, title, text, max FROM polls WHERE user_id = $userId AND feedback_message_id = $feedbackMessageId";
$stmt = $dbConnection->prepare('SELECT id, status, title, text, max FROM polls WHERE user_id = :userId AND feedback_message_id = :feedbackMessageId');
$stmt->bindParam(':userId', $userId);
$stmt->bindParam(':feedbackMessageId', $feedbackMessageId);
$stmt->execute();
if ($stmt->rowCount() > 0) {
return $stmt->fetch();
}
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
return [
false,
false,
false,
false,
false
];
} else {
try {
$sql = "SELECT id, status, title, text, max FROM polls INNER JOIN messages m on polls.id = m.poll_id WHERE m.inline_message_id = $inlineQueryMessageId";
$stmt = $dbConnection->prepare('SELECT id, status, title, text, max FROM polls INNER JOIN messages m on polls.id = m.poll_id WHERE m.inline_message_id = :inlineQueryMessageId');
$stmt->bindParam(':inlineQueryMessageId', $inlineQueryMessageId);
$stmt->execute();
if ($stmt->rowCount() > 0) {
return $stmt->fetch();
}
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
return [
false,
false,
false,
false,
false
];
}
}
function answerInlineQuery($inlineQueryId, $results, $offset) {
$data = array(
'inline_query_id' => $inlineQueryId,
'results' => $results,
'cache_time' => 10,
'is_personal' => true,
'next_offset' => $offset + 50
);
return makeApiRequest('answerInlineQuery', $data);
}
function getAllPolls($userId, $search = '', $offset = 0) {
global $dbConnection, $config;
if (empty($search)) {
try {
//$sql = "SELECT polls.id, title, text, count(attendees.user_id) as attendees FROM polls INNER JOIN attendees ON attendees.poll_id = polls.id WHERE polls.user_id = $userId GROUP BY attendees.poll_id";
//$stmt = $dbConnection->prepare('SELECT polls.id, title, text, count(attendees.user_id) as attendees FROM polls INNER JOIN attendees ON attendees.poll_id = polls.id WHERE polls.user_id = :userId GROUP BY attendees.poll_id');
$sql = "SELECT id, title, text FROM polls WHERE user_id = $userId AND status = 1 ORDER BY id DESC LIMIT $offset, 50";
$stmt = $dbConnection->prepare('SELECT id, title, text FROM polls WHERE user_id = :userId AND status = 1 ORDER BY id DESC LIMIT ' . $offset . ', 50');
$stmt->bindParam(':userId', $userId);
$stmt->execute();
return $stmt->fetchAll();
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
return false;
} else {
$search = '%' . $search . '%';
try {
//$sql = "SELECT polls.id, title, text, count(attendees.user_id) as attendees FROM polls INNER JOIN attendees ON attendees.poll_id = polls.id WHERE polls.user_id = $userId GROUP BY attendees.poll_id";
//$stmt = $dbConnection->prepare('SELECT polls.id, title, text, count(attendees.user_id) as attendees FROM polls INNER JOIN attendees ON attendees.poll_id = polls.id WHERE polls.user_id = :userId GROUP BY attendees.poll_id');
$sql = "SELECT id, title, text FROM polls WHERE user_id = $userId AND status = 1 AND title LIKE $search ORDER BY id DESC LIMIT $offset, 50";
$stmt = $dbConnection->prepare('SELECT id, title, text FROM polls WHERE user_id = :userId AND status = 1 AND title LIKE :search ORDER BY id DESC LIMIT ' . $offset . ', 50');
$stmt->bindParam(':userId', $userId);
$stmt->bindParam(':search', $search);
$stmt->execute();
return $stmt->fetchAll();
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
return false;
}
}
function getPollAttendees($pollId) {
global $dbConnection, $config;
try {
//$sql = "SELECT polls.id, title, text, count(attendees.user_id) as attendees FROM polls INNER JOIN attendees ON attendees.poll_id = polls.id WHERE polls.user_id = $userId GROUP BY attendees.poll_id";
//$stmt = $dbConnection->prepare('SELECT polls.id, title, text, count(attendees.user_id) as attendees FROM polls INNER JOIN attendees ON attendees.poll_id = polls.id WHERE polls.user_id = :userId GROUP BY attendees.poll_id');
$sql = "SELECT
sum(CASE WHEN status = 1 THEN 1 ELSE 0 END) AS yes,
sum(CASE WHEN status = 2 THEN 1 ELSE 0 END) AS maybe,
/*sum(CASE WHEN status = 3 THEN 1 ELSE 0 END) AS no*/
0 AS no
FROM attendees WHERE poll_id = $pollId";
$stmt = $dbConnection->prepare('SELECT
sum(CASE WHEN status = 1 THEN 1 ELSE 0 END) AS yes,
sum(CASE WHEN status = 2 THEN 1 ELSE 0 END) AS maybe,
/*sum(CASE WHEN status = 3 THEN 1 ELSE 0 END) AS no*/
0 AS no
FROM attendees WHERE poll_id = :pollId');
$stmt->bindParam(':pollId', $pollId);
$stmt->execute();
return $stmt->fetch();
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
return false;
}
function updateMax($pollId, $max) {
global $dbConnection, $config;
try {
$sql = 'UPDATE polls SET max = :max WHERE id = :pollId';
$stmt = $dbConnection->prepare($sql);
$stmt->bindParam(':max', $max);
$stmt->bindParam(':pollId', $pollId);
$stmt->execute();
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
}
function buildPollAttendees($pollId, $yes, $maybe, $no, $link = false) {
global $dbConnection, $config;
$return = "
<b>Anmeldung - [$yes]</b>
";
/*try {
//$sql = "SELECT polls.id, title, text, count(attendees.user_id) as attendees FROM polls INNER JOIN attendees ON attendees.poll_id = polls.id WHERE polls.user_id = $userId GROUP BY attendees.poll_id";
//$stmt = $dbConnection->prepare('SELECT polls.id, title, text, count(attendees.user_id) as attendees FROM polls INNER JOIN attendees ON attendees.poll_id = polls.id WHERE polls.user_id = :userId GROUP BY attendees.poll_id');
$status = 1;
$sql = "SELECT user_id, nickname FROM attendees WHERE poll_id = $pollId AND status = $status ORDER BY time";
$stmt = $dbConnection->prepare('SELECT user_id, nickname FROM attendees WHERE poll_id = :pollId AND status = :status ORDER BY time');
$stmt->bindParam(':pollId', $pollId);
$stmt->bindParam(':status', $status);
$stmt->execute();
$rows = $stmt->fetchAll();
if ($link) {
foreach ($rows as $row) {
$return .= '<a href="tg://user?id=' . $row['user_id'] . '">' . $row['nickname'] . '</a>
';
}
} else {
foreach ($rows as $row) {
$return .= $row['nickname'] . '
';
}
}
$return .= "
<b>Vielleicht - [$maybe]</b>
";
$status = 2;
$stmt->bindParam(':status', $status);
$stmt->execute();
$rows = $stmt->fetchAll();
if ($link) {
foreach ($rows as $row) {
$return .= '<a href="tg://user?id=' . $row['user_id'] . '">' . $row['nickname'] . '</a>
';
}
} else {
foreach ($rows as $row) {
$return .= $row['nickname'] . '
';
}
}
$return .= "
<b>Abmeldung - [$no]</b>
";
$status = 3;
$stmt->bindParam(':status', $status);
$stmt->execute();
$rows = $stmt->fetchAll();
if ($link) {
foreach ($rows as $row) {
$return .= '<a href="tg://user?id=' . $row['user_id'] . '">' . $row['nickname'] . '</a>
';
}
} else {
foreach ($rows as $row) {
$return .= $row['nickname'] . '
';
}
}
return $return;
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}*/
try {
$sql = "SELECT user_id, nickname, status FROM attendees WHERE poll_id = $pollId AND (status = 1 OR status = 2) ORDER BY status, time";
$stmt = $dbConnection->prepare('SELECT user_id, nickname, status FROM attendees WHERE poll_id = :pollId AND (status = 1 OR status = 2) ORDER BY status, time');
$stmt->bindParam(':pollId', $pollId);
$stmt->execute();
$rows = $stmt->fetchAll();
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
return false;
}
$lastStatus = 1;
$return = "
<b>Anmeldung - [$yes]</b>
";
/*
* Keep links if character limit not met
*/
if ($link) {
foreach ($rows as $row) {
if ($lastStatus != $row['status']) {
if ($row['status'] === 2) {
$return .= "
<b>Vielleicht - [$maybe]</b>
";
}
if ($row['status'] === 3) {
$return .= "
<b>Abmeldung - [$no]</b>
";
}
$lastStatus = $row['status'];
}
$return .= '<a href="tg://user?id=' . $row['user_id'] . '">' . htmlspecialchars($row['nickname']) . '</a>
';
}
} /*
* If character limit is reached, disable links
*/ else {
foreach ($rows as $row) {
if ($lastStatus != $row['status']) {
if ($row['status'] === 2) {
$return .= "
<b>Vielleicht - [$maybe]</b>
";
}
if ($row['status'] === 3) {
$return .= "
<b>Abmeldung - [$no]</b>
";
}
$lastStatus = $row['status'];
}
$return .= htmlspecialchars($row['nickname']) . '
';
}
}
/*
*
*/
return $return;
}
function setPollContent($userId, $feedbackMessageId, $text) {
global $dbConnection, $config;
try {
$sql = "UPDATE polls SET text = $text, status = 1 WHERE user_id = $userId AND feedback_message_id = $feedbackMessageId";
$stmt = $dbConnection->prepare('UPDATE polls SET text = :text, status = 1 WHERE user_id = :userId AND feedback_message_id = :feedbackMessageId');
$stmt->bindParam(':text', $text);
$stmt->bindParam(':userId', $userId);
$stmt->bindParam(':feedbackMessageId', $feedbackMessageId);
$stmt->execute();
return true;
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
return false;
}
function setPollNewContent($userId, $feedbackMessageId, $text) {
global $dbConnection, $config;
try {
$sql = "UPDATE polls SET text_new = $text WHERE user_id = $userId AND feedback_message_id = $feedbackMessageId";
$stmt = $dbConnection->prepare('UPDATE polls SET text_new = :text WHERE user_id = :userId AND feedback_message_id = :feedbackMessageId');
$stmt->bindParam(':text', $text);
$stmt->bindParam(':userId', $userId);
$stmt->bindParam(':feedbackMessageId', $feedbackMessageId);
$stmt->execute();
return true;
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
return false;
}
function newPollPost($inlineQueryMessageId, $pollId) {
global $dbConnection, $config;
try {
$sql = "INSERT INTO messages(inline_message_id, poll_id) VALUES ('$inlineQueryMessageId', '$pollId')";
$stmt = $dbConnection->prepare('INSERT INTO messages(inline_message_id, poll_id) VALUES (:inlineQueryMessageId, :pollId)');
$stmt->bindParam(':inlineQueryMessageId', $inlineQueryMessageId);
$stmt->bindParam(':pollId', $pollId);
$stmt->execute();
return true;
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
return false;
}
function closePoll($pollId) {
global $dbConnection, $config;
try {
$sql = "UPDATE polls SET status = 2 WHERE id = $pollId";
$stmt = $dbConnection->prepare('UPDATE polls SET status = 2 WHERE id = :pollId');
$stmt->bindParam(':pollId', $pollId);
$stmt->execute();
return true;
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
return false;
}
function setAttendanceStatus($pollId, $userId, $nickname, $status) {
global $dbConnection, $config;
try {
$sql = "SELECT id, status FROM attendees WHERE poll_id = $pollId AND user_id = $userId";
$stmt = $dbConnection->prepare('SELECT id, status FROM attendees WHERE poll_id = :pollId AND user_id = :userId');
$stmt->bindParam(':pollId', $pollId);
$stmt->bindParam(':userId', $userId);
$stmt->execute();
$row = $stmt->fetch();
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
if ($stmt->rowCount() > 0) {
//Update
if ($row['status'] != $status) {
try {
$sql = "UPDATE attendees SET status = $status, nickname = $nickname, time = UNIX_TIMESTAMP() WHERE poll_id = $pollId AND user_id = $userId";
$stmt = $dbConnection->prepare('UPDATE attendees SET status = :status, nickname = :nickname, time = UNIX_TIMESTAMP() WHERE poll_id = :pollId AND user_id = :userId');
$stmt->bindParam(':status', $status);
$stmt->bindParam(':nickname', $nickname);
$stmt->bindParam(':pollId', $pollId);
$stmt->bindParam(':userId', $userId);
$stmt->execute();
} catch (PDOException $e) {
notifyOnException('Database Update', $config, $sql, $e);
}
return true;
}
} else {
//Insert
try {
$sql = "INSERT INTO attendees(poll_id, user_id, nickname, status, time) VALUES ($pollId, $userId, $nickname, $status, UNIX_TIMESTAMP())";
$stmt = $dbConnection->prepare('INSERT INTO attendees(poll_id, user_id, nickname, status, time) VALUES (:pollId, :userId, :nickname, :status, UNIX_TIMESTAMP())');
$stmt->bindParam(':pollId', $pollId);
$stmt->bindParam(':userId', $userId);
$stmt->bindParam(':nickname', $nickname);
$stmt->bindParam(':status', $status);
$stmt->execute();
} catch (PDOException $e) {
notifyOnException('Database Insert', $config, $sql, $e);
}
return ($status != 3) ? true : false;
}
return false;
}
function updatePoll($pollId, $close = false) {
global $dbConnection, $config;
try {
$sql = "SELECT inline_message_id, text, title FROM messages INNER JOIN polls p on messages.poll_id = p.id WHERE poll_id = $pollId";
$stmt = $dbConnection->prepare('SELECT inline_message_id, text, title FROM messages INNER JOIN polls p on messages.poll_id = p.id WHERE poll_id = :pollId');
$stmt->bindParam(':pollId', $pollId);
$stmt->execute();
$rows = $stmt->fetchAll();
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
foreach ($rows as $row) {
$pollText = $row['text'];
$pollTitle = $row['title'];
$pollInlineMessageId = $row['inline_message_id'];
list($attendeesYes, $attendeesMaybe, $attendeesNo) = getPollAttendees($pollId);
$text = $pollText . buildPollAttendees($pollId, $attendeesYes, $attendeesMaybe, $attendeesNo, true);
/*if(mb_strlen($text) > 4000){
$text = "<a href=\"https://t.me/gaestebuch_bot?start=$pollInlineMessageId\">$pollTitle</a>" . buildPollAttendees($pollId, $attendeesYes, $attendeesMaybe, $attendeesNo, true);
if(mb_strlen($text) > 4000){
$text = "<a href=\"https://t.me/gaestebuch_bot?start=$pollInlineMessageId\">$pollTitle</a>" . buildPollAttendees($pollId, $attendeesYes, $attendeesMaybe, $attendeesNo);
if(mb_strlen($text) > 4000){
$text = $pollText;
}
}
}*/
if (mb_strlen($text) > 4000) {
$text = $pollText . buildPollAttendees($pollId, $attendeesYes, $attendeesMaybe, $attendeesNo);
if (mb_strlen($text) > 4000) {
$text = $pollText;
}
}
if (!$close) {
$replyMarkup = array(
'inline_keyboard' => array(
array(
array(
'text' => 'Anmeldung - ' . $attendeesYes,
'callback_data' => 'vote|0|1|0'
)
),
array(
array(
'text' => 'Vielleicht - ' . $attendeesMaybe,
'callback_data' => 'vote|0|2|0'
)
),
array(
array(
/*'text' => 'Abmeldung - ' . $attendeesNo,*/
'text' => 'Abmeldung',
'callback_data' => 'vote|0|3|0'
)
)
)
);
} else {
$replyMarkup = '';
}
$edited = editMessageText('', '', $text, $replyMarkup, $row['inline_message_id']);
if ($edited === false) {
//Too many false positives, gotta think about something else
//deletePollMessage($row['inline_message_id'], $pollId);
}
}
}
function deletePollMessage($inlineMessageId, $pollId) {
global $dbConnection, $config;
try {
$sql = "INSERT INTO messagesDEL(inline_message_id, poll_id) VALUES ($inlineMessageId, $pollId)";
$stmt = $dbConnection->prepare('INSERT INTO messagesDEL(inline_message_id, poll_id) VALUES (:inlineMessageId, :pollId)');
$stmt->bindParam(':inlineMessageId', $inlineMessageId);
$stmt->bindParam(':pollId', $pollId);
$stmt->execute();
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
try {
$sql = "DELETE FROM messages WHERE inline_message_id = $inlineMessageId";
$stmt = $dbConnection->prepare('DELETE FROM messages WHERE inline_message_id = :inlineMessageId');
$stmt->bindParam(':inlineMessageId', $inlineMessageId);
$stmt->execute();
} catch (PDOException $e) {
notifyOnException('Database Select', $config, $sql, $e);
}
}
function updatePollText($pollId) {
global $dbConnection, $config;
try {
$sql = "UPDATE polls SET text = text_new, text_new = NULL WHERE id = $pollId AND text_new IS NOT NULL";
$stmt = $dbConnection->prepare('UPDATE polls SET text = text_new, text_new = NULL WHERE id = :pollId AND text_new IS NOT NULL');
$stmt->bindParam(':pollId', $pollId);
$stmt->execute();
} catch (PDOException $e) {
notifyOnException('Database Update', $config, $sql, $e);
return false;
}
return true;
}
function editMessageText($chatId, $messageId, $text, $replyMarkup = '', $inlineMessageId = '') {
if (empty($inlineMessageId)) {
$data = array(
'chat_id' => $chatId,
'message_id' => $messageId,
'text' => $text,
'parse_mode' => 'html',
'disable_web_page_preview' => true,
'reply_markup' => $replyMarkup
);
} else {
$data = array(
'inline_message_id' => $inlineMessageId,
'text' => $text,
'parse_mode' => 'html',
'disable_web_page_preview' => true,
'reply_markup' => $replyMarkup
);
}
return makeApiRequest('editMessageText', $data);
}
function checkLastExecute($timeouts, $command, $type, $id) {
if ($type === 'private') {
return $timeouts;
}
global $config;
$now = time();
if (isset($timeouts[$id])) {
$lastExecute = $timeouts[$id][$command];
if ($now < $lastExecute + $config['commandInterval']) {
return false;
}
}
$timeouts[$id][$command] = $now;
return $timeouts;
}
function mb_substr_replace($original, $replacement, $position, $length) {
$startString = mb_substr($original, 0, $position, "UTF-8");
$endString = mb_substr($original, $position + $length, mb_strlen($original), "UTF-8");
$out = $startString . $replacement . $endString;
return $out;
}
function filterSymbols($input, $clear = false) {
if ($clear) {
$input = str_replace(['<', '>'], '', $input);
} else {
$input = str_replace('<', '<', $input);
$input = str_replace('>', '>', $input);
}
return $input;
}