This repository was archived by the owner on Dec 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
209 lines (200 loc) · 5.38 KB
/
functions.php
File metadata and controls
209 lines (200 loc) · 5.38 KB
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
<?php
function sendMsg($options, $blackbox = False) {
global $chatID;
$default = Array(
'chat_id' => $chatID,
'disable_web_page_preview' => True,
);
$options = array_merge($default, $options);
$field = http_build_query($options);
$url = 'https://api.telegram.org/bot' . botID . ':' . botToken . '/sendMessage?' . $field;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
$data = curl_exec($curl);
curl_close($curl);
if (!$blackbox) {
$data = json_decode($data, True);
sendLog($data);
}
return $data;
}
function getProPic() {
global $userID;
$url = 'https://api.telegram.org/bot' . botID . ':' . botToken . '/getUserProfilePhotos?user_id=' . $userID;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
$data = curl_exec($curl);
curl_close($curl);
$data = json_decode($data, True);
return $data['result'];
}
function newQust() {
global $userID;
$field = Array(
'token' => API_TOKEN,
'user_id' => $userID,
);
$field = http_build_query($field);
$url = API_URL . 'random_question?' . $field;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
$data = curl_exec($curl);
curl_close($curl);
$data = json_decode($data, True);
sendQust($data);
}
function sendQust($data) {
if (!isset($data['question'])) {
$text = '您已經回答完所有題目了 Orz' . "\n" . '該起床了喔,肥宅';
$options = Array(
'text' => $text,
);
} else {
$text = '[' . $data['class'] . ']' . "\n";
$text .= '本題目由 ' . $data['author'] . ' 提供' . "\n\n";
$text .= $data['question'] . "\n\n";
foreach (range(1, 4) as $i) {
$text .= $i . '. ' . $data['option'][$i] . "\n";
}
$answer = $data['option'];
$ans = Array(
'keyboard' => Array(
Array(
'1. ' . $answer[1],
'2. ' . $answer[2],
),
Array(
'3. ' . $answer[3],
'4. ' . $answer[4],
),
),
'resize_keyboard' => True,
'one_time_keyboard' => True,
);
$ans = json_encode($ans);
$options = Array(
'text' => $text,
'reply_markup' => $ans,
);
}
sendMsg($options, True);
}
function sendInGroup($user, $status) {
$field = Array(
'token' => API_TOKEN,
'user_id' => $user,
'ingroup' => $status,
);
$url = API_URL . 'user_status';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, True);
curl_setopt($curl, CURLOPT_POSTFIELDS, $field);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
$data = curl_exec($curl);
curl_close($curl);
$data = json_decode($data, True);
}
function sendAction() {
global $userID;
$options = Array(
'chat_id' => $userID,
'action' => 'typing',
);
$field = http_build_query($options);
$url = 'https://api.telegram.org/bot' . botID . ':' . botToken . '/sendChatAction?' . $field;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
curl_exec($curl);
curl_close($curl);
}
function getMe($user) {
$field = Array(
'token' => API_TOKEN,
'user_id' => $user,
);
$field = http_build_query($field);
$url = API_URL . 'user_status?' . $field;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
$data = curl_exec($curl);
curl_close($curl);
$data = json_decode($data, True);
return $data;
}
function showUserStatus($user) {
$data = getMe($user);
$text = '';
$text .= '答對題數: *' . $data['correct'] . '*' . "\n";
$text .= '錯誤題數: *' . $data['incorrect'] . '*' . "\n";
if (!$data['ingroup']) {
$text .= '您尚未加入群組喔!誠摯的邀請您點擊下方連結加入' . "\n";
$text .= '[Click Me](https://telegram.me/joinchat/' . group_joinlink . ')';
}
$options = Array(
'text' => $text,
'parse_mode' => 'Markdown',
);
sendMsg($options, True);
}
function sendAns($ans) {
global $userID;
$field = Array(
'token' => API_TOKEN,
'user_id' => $userID,
'answer' => $ans,
);
$url = API_URL . 'post_answer';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, True);
curl_setopt($curl, CURLOPT_POSTFIELDS, $field);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
$data = curl_exec($curl);
curl_close($curl);
$data = json_decode($data, True);
if ($data['result']) {
$text = '恭喜您答對了!' . "\n";
if (rand(1, 2) == 1) {
$text .= '您尚未加入群組喔!誠摯的邀請您點擊下方連結加入' . "\n";
}
} else {
$text = '答錯了喔!';
}
$options = Array(
'text' => $text,
'chat_id' => $userID,
);
sendMsg($options, True);
}
function sendLog($data = '') {
if ($data == '') {
global $data;
$options = Array(
'chat_id' => Log_ChatID,
'from_chat_id' => $data['chat']['id'],
'message_id' => $data['message_id'],
);
$field = http_build_query($options);
$url = 'https://api.telegram.org/bot' . botID . ':' . botToken . '/forwardMessage?' . $field;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
curl_exec($curl);
curl_close($curl);
} elseif (isset($data['result']['chat'])) {
$data = $data['result'];
$text = 'to @' . $data['chat']['username'] . ' (' . $data['chat']['id'] . ')' . "\n";
$text .= $data['text'];
$options = Array(
'text' => $text,
'chat_id' => Log_ChatID,
);
sendMsg($options, True);
}
}