-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
116 lines (93 loc) · 2.61 KB
/
lib.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
<?php
class Message {
private $data;
public function __construct($json) {
$this->data = json_decode($json, true);
}
public function get($key) {
$arr = explode(".", $key);
$ret = $this->data;
foreach ($arr as $k => $v) {
if (! isset($ret[$v])) {
return null;
}
$ret = $ret[$v];
}
return $ret;
}
public function text() {
return $this->get("text");
}
public function sender() {
$this->get("from");
}
public function senderID() {
return $this->get("from.id");
}
public function json() {
return json_encode($this->data);
}
public static function fromJson($json) {
return new self($json);
}
}
class SendOptions {
private $reply;
private $markup;
private $noPreview;
public function __construct() {
$this->markup = array("place_holder" => null);
$this->noPreview = false;
}
public function replyTo(Message $msg) {
$this->reply = $msg->json();
}
public function preview($bool) {
$this->noPreview = !$bool;
}
public function forceReply($bool) {
$this->markup['force_reply'] = $bool == true;
}
public function customKeyboard(array $keyboard) {
$this->markup['keyboard'] = $keyboard;
}
public function resizeKeyboard($bool) {
$this->markup['resize_keyboard'] = $bool == true;
}
public function onetime($bool) {
$this->markup['one_time_keyboard'] = $bool == true;
}
public function hideKeyboard($bool) {
$this->markup['hide_keyboard'] = $bool == true;
}
public function selective($boole) {
$this->markup['selective'] = $bool == true;
}
public function json()
{
$data = array(
"ReplyTo" => json_decode($this->reply, true),
"ReplyMarkup" => $this->markup,
"DisableWebPagePreview" => $this->noPreview,
);
$ret = json_encode($data);
return $ret;
}
public static function fromJson($json) {
$data = json_decode($json, true);
$ret = new self;
$ret->reply = json_encode($data['ReplyTo']);
$ret->markup = $data['ReplyMarkup'];
$ret->noPreview = $data['DisableWebPagePreview'];
return $ret;
}
}
function send_message($uid, $msg, SendOptions $options = null) {
if ($options == null) {
$options = new SendOptions;
}
raw_send_message($uid, $msg, $options->json());
}
function timed_task($milisec, $data) {
raw_timed_task($milisec, json_encode($data));
}