-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.php
More file actions
98 lines (80 loc) · 3.43 KB
/
Copy pathbot.php
File metadata and controls
98 lines (80 loc) · 3.43 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
<?php
use TeleBot\InlineKeyboard;
use TeleBot\TeleBot;
use Bot\Models\User;
require './vendor/autoload.php';
$tg = new TeleBot(BOT_TOKEN);
if ($tg->chat->id != CHAT_ID) {
$tg->leaveChat(['chat_id' => $tg->chat->id]);
}
$userIsAdmin = in_array(($tg->getChatMember(['chat_id' => CHAT_ID, 'user_id' => $tg->user->id]))->status, ['creator', 'administrator']);
$dbUser = User::firstWhere('tg_id', $tg->user->id);
try {
if ($tg->message->new_chat_members && ! $dbUser) {
$u = 0;
foreach ($tg->message->new_chat_members as $newMember) {
if ($u == 11) exit;
$userFullName = '<a href="tg://user?id=' . $newMember->id . '">' . $newMember->first_name . ' ' . $newMember->last_name . '</a>';
$tg->sendMessage([
'chat_id' => CHAT_ID,
'text' => "سلام {$userFullName}، لطفاً با فشردن دکمهی زیر، ما را از اینکه ربات نیستید، مطمئن سازید.",
'parse_mode' => 'html',
'reply_markup' => (new InlineKeyboard(true))->addButton('من ربات نیستم!', null, null, $tg->user->id . '_' . 'notbot')->get()
]);
$u++;
}
}
$tg->listen('%d_notbot', function ($userId) use ($tg, $userIsAdmin) {
if ($userId == $tg->user->id || $userIsAdmin) {
User::create(['tg_id' => $userId]);
$tg->answerCallbackQuery([
'callback_query_id' => $tg->update->callback_query->id,
'text' => 'ممنون! حدس میزدم! 😀'
]);
$tg->deleteMessage(['chat_id' => CHAT_ID, 'message_id' => $tg->message->message_id]);
} else {
$tg->answerCallbackQuery([
'callback_query_id' => $tg->update->callback_query->id,
'text' => 'شما نمیتوانید به جای کاربری دیگر پاسخ دهید!'
]);
}
});
if (! $dbUser && ! $tg->update->callback_query && ! $userIsAdmin) {
$tg->deleteMessage(['chat_id' => CHAT_ID, 'message_id' => $tg->message->message_id]);
exit;
}
$tg->listen('!ban', function () use ($tg, $userIsAdmin) {
$user = $tg->message->reply_to_message->from;
if ($userIsAdmin) {
$tg->kickChatMember(['chat_id' => CHAT_ID, 'user_id' => $user->id]);
}
});
$tg->listen('!unban', function () use ($tg, $userIsAdmin) {
$user = $tg->message->reply_to_message->from;
if ($userIsAdmin) {
$tg->unbanChatMember(['chat_id' => CHAT_ID, 'user_id' => $user->id]);
}
});
$tg->listen('!mute', function () use ($tg, $userIsAdmin) {
$user = $tg->message->reply_to_message->from;
if ($userIsAdmin) {
$tg->restrictChatMember([
'chat_id' => CHAT_ID,
'user_id' => $user->id,
'permissions' => '{}'
]);
}
});
$tg->listen('!unmute', function () use ($tg, $userIsAdmin) {
$user = $tg->message->reply_to_message->from;
if ($userIsAdmin) {
$tg->restrictChatMember([
'chat_id' => CHAT_ID,
'user_id' => $user->id,
'permissions' => '{"can_send_messages": true, "can_send_media_messages": true, "can_send_polls": true, "can_send_other_messages": true, "can_invite_users": true}'
]);
}
});
} catch (Exception $e) {
tl($e->getMessage());
}