/
index-offline.php
77 lines (62 loc) · 1.98 KB
/
index-offline.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
<?php
function apiRequestWebhook($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;
header("Content-Type: application/json");
echo json_encode($parameters);
return true;
}
function talk($chat_id, $text)
{
apiRequestWebhook("sendMessage", array('chat_id' => $chat_id, "text" => $text));
}
function emoji($string)
{
return iconv('UCS-4LE', 'UTF-8', pack('V', intval($string, 0)));
}
function processMessage($message)
{
$chat_id = $message['chat']['id'];
if (isset($message['text'])) $text = $message['text'];
else return;
if (isset($text) && (stripos($text, 'shitbot') !== false)) {
talk($chat_id, emoji(0x1F527) . " My head hurts.");
} elseif ($text[0] == '/') {
if ($text == '/roll') {
t_roll($text, $chat_id);
} elseif (mt_rand(0, 9) > 7) {
talk($chat_id, emoji(0x1F634) . " m8 stop bugging me I'm sleeping");
}
}
}
function t_roll($text, $chat_id)
{
$out = mt_rand(0, 999999999);
$dubs = array(9 => "nines", 8 => "eights", 7 => "sevens", 6 => "sixes", 5 => "quints", 4 => "quads", 3 => "trips", 2 => "dubs");
foreach ($dubs as $key => $value) {
$test = substr(strval($out), 0 - $key);
if (preg_match('/^(.)\1*$/', $test)) {
$text = str_repeat(emoji(0x1F389), $key - 1) . sprintf('%09d', $out) . "\nnice " . $value . " brah" . str_repeat("!", $key - 1);
talk($chat_id, $text);
return true;
}
}
talk($chat_id, sprintf('%09d', $out));
return true;
}
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (!$update)
exit;
if (isset($update["message"]))
processMessage($update["message"]);