-
Notifications
You must be signed in to change notification settings - Fork 4
/
bot_listeners.php
39 lines (32 loc) · 1.51 KB
/
bot_listeners.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
<?php
use App\Event;
// Filter User if spammer
Event::listen('text', function ($text, $bot, $update) {
if ($text === 'ping') {
$bot->sendMessage($update['message']['chat']['id'], 'pong!');
}
});
Event::listen('new_chat_member', function ($member, $bot, $update) {
echo 'Event New Member fired!\n';
$chat_id = $update['message']['chat']['id'];
$user_id = $update['message']['new_chat_member']['id'];
$str = $update['message']['new_chat_member']['first_name'];
$re = '/\p{Han}+/miu';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
if (count($matches) > 0) {
// if the user has chinese characters the bot kick that user
// $until = time()+(366 * 24 * 60 * 60);
$res = $bot->kickChatMember($chat_id, $user_id);
} else {
// Say Hi to new member
$first_name = $update['message']['new_chat_member']['first_name'];
$username = ($update['message']['new_chat_member']['username']) ? '( @'.$update['message']['new_chat_member']['username'].' )' : '';
$welcome_text = "📢 Bienvenido/a <b>$first_name</b> $username a <a href='https://telegram.me/PHP_Ve'>PHP.ve</a>, te invitamos a que leas la <a href='http://telegra.ph/PHPve-11-24'>Descripción y Normas del Grupo</a>";
$chat_id = $update['message']['chat']['id'];
$bot->sendMessage($chat_id, $welcome_text, [
'parse_mode' => 'HTML',
]);
}
// Delete join message...
$bot->deleteMessage($chat_id, $update['message']['message_id']);
});