This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.php
138 lines (114 loc) · 2.87 KB
/
cli.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
<?php
/* Only Command-line Execution Allowed */
if (!isset($argv[1]))
exit;
require('utils.php');
require('database.php');
require_once('telegram-bot/class.php');
$db = new MyDB();
$TG = new Telegram();
switch ($argv[1]) {
case 'dump':
$data = [];
$posts = [];
$tables = ['posts', 'votes', 'users', 'tg_msg'];
foreach ($tables as $table) {
$sql = "SELECT * FROM $table ORDER BY created_at DESC";
$stmt = $db->pdo->prepare($sql);
$stmt->execute();
$data[$table] = [];
while ($item = $stmt->fetch()) {
if (isset($item['stuid']))
$item['stuid'] = idToDep($item['stuid']) . ' ' . $item['stuid'];
if ($table == 'posts')
$posts[ $item['uid'] ] = $item;
if ($table == 'votes') {
$item['uid'] .= ' ' . mb_substr($posts[ $item['uid'] ]['body'], 0, 20) . '..';
$item['voter'] = idToDep($item['voter']) . ' ' . $item['voter'];
$item['vote'] = ($item['vote'] == '1' ? '✅ 通過' : '❌ 駁回');
}
$data[$table][] = $item;
}
}
echo json_encode($data, JSON_PRETTY_PRINT);
break;
case 'reject':
$posts = $db->getSubmissions(0);
foreach ($posts as $post) {
/* Prevent reject demo post */
if ($post['status'] != 3)
continue;
$uid = $post['uid'];
$dt = time() - strtotime($post['created_at']);
if (strpos($post['author_name'], '境外') !== false) {
if ($post['rejects'] < 2)
continue;
} else {
/* Before 2 hour */
if ($dt < 2*60*60)
if ($post['rejects'] < 5)
continue;
/* 2 hour - 12 hour*/
if ($dt < 12*60*60)
if ($post['rejects'] < 3)
continue;
}
$db->deleteSubmission($uid, -2, '已駁回');
/* Remove vote keyboard in Telegram */
$msgs = $db->getTgMsgsByUid($uid);
foreach ($msgs as $item) {
$TG->deleteMsg($item['chat_id'], $item['msg_id']);
$db->deleteTgMsg($uid, $item['chat_id']);
}
}
$sql = "SELECT * FROM posts WHERE status = 0";
$stmt = $db->pdo->prepare($sql);
$stmt->execute();
while ($post = $stmt->fetch()) {
$dt = time() - strtotime($post['created_at']);
/* Not within 3 - 4 min */
if ($dt < 3*60 || $dt > 4*60)
continue;
$uid = $post['uid'];
$msg = "<未確認投稿>\n\n";
$msg .= $post['body'];
$keyboard = [
'inline_keyboard' => [
[
[
'text' => '✅ 確認投稿',
'callback_data' => "confirm_$uid"
],
[
'text' => '❌ 刪除投稿',
'callback_data' => "delete_$uid"
]
],
[
[
'text' => '開啟審核頁面',
'login_url' => [
'url' => 'https://' . DOMAIN . "/login-tg?r=%2Freview%2F$uid"
]
]
]
]
];
if (!$post['has_img'])
$TG->sendMsg([
'chat_id' => LOG_GROUP,
'text' => $msg,
'reply_markup' => $keyboard,
]);
else
$TG->sendPhoto([
'chat_id' => LOG_GROUP,
'photo' => 'https://' . DOMAIN . "/img/$uid.jpg",
'caption' => $msg,
'reply_markup' => $keyboard,
]);
}
break;
default:
echo "Unknown argument: {$argv[1]}";
}