-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
46 lines (35 loc) · 1.7 KB
/
index.php
File metadata and controls
46 lines (35 loc) · 1.7 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
<?php
use Botify\Events\EventHandler;
use Botify\Events\Handler;
use Botify\TelegramAPI;
use Botify\Types\Map\Message;
use function Botify\gather;
require_once __DIR__ .'/bootstrap/app.php';
$bot = TelegramAPI::factory();
$bot->setEventHandler(new class extends EventHandler {
public function onUpdateNewMessage(Message $message)
{
$chat = $message->chat;
if (isset($chat['type']) && in_array($chat['type'], ['supergroup', 'group'])) {
if ($message->regex('/^(?:clean|پاکسازی) (\d+)$/ui')) {
[$me, $user] = yield gather([
$chat->getMember('me'),
$chat->getMember($message['from']),
]);
if (in_array($user['status'], ['creator', 'administrator'])) {
if ($me['status'] === 'administrator') {
$replied = yield $message->reply('درحال پاکسازی پیامها، لطفا کمی صبر کنید...');
$responses = yield $message->delete($message['matches'][1]);
return yield $replied->edit(sprintf(
'%d پیام با موفقیت پاکسازی شد.',
count(array_filter($responses, fn ($response) => $response === true))
));
}
return yield $message->reply('برای انجام این دستور من باید در گروه ادمین باشم.');
}
return yield $message->reply('برای ارسال این دستور، باید در گروه ادمین باشید.');
}
}
}
});
$bot->loopAndHear(Handler::UPDATE_TYPE_WEBHOOK);