forked from hbashton/BruhhBot-Madeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invite.php
108 lines (106 loc) · 4.72 KB
/
invite.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
<?php
/**
* Copyright (C) 2016-2017 Hunter Ashton
* This file is part of BruhhBot.
* BruhhBot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* BruhhBot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with BruhhBot. If not, see <http://www.gnu.org/licenses/>.
*/
function export_new_invite($update, $MadelineProto)
{
if (is_supergroup($update, $MadelineProto)) {
$msg_id = $update['update']['message']['id'];
$mods = $MadelineProto->responses['export_new_invite']['mods'];
$chat = parse_chat_data($update, $MadelineProto);
$peer = $chat['peer'];
$title = htmlentities($chat['title']);
$ch_id = $chat['id'];
$default = [
'peer' => $peer,
'reply_to_msg_id' => $msg_id,
'parse_mode' => 'html',
];
if (is_moderated($ch_id)) {
if (is_bot_admin($update, $MadelineProto)) {
if (from_admin_mod($update, $MadelineProto, $mods, true)) {
try {
$exportInvite = $MadelineProto->channels->exportInvite(
['channel' => $peer]
);
$link = $exportInvite['link'];
$str = $MadelineProto->responses['export_new_invite']['link'];
$repl = [
'link' => $link,
];
$message = $MadelineProto->engine->render($str, $repl);
$default['message'] = $message;
$sentMessage = $MadelineProto->messages->sendMessage(
$default
);
\danog\MadelineProto\Logger::log($sentMessage);
} catch (Exception $e) {
$message = $MadelineProto->responses['export_new_invite']['exception'];
$default['message'] = $message;
$sentMessage = $MadelineProto->messages->sendMessage(
$default
);
\danog\MadelineProto\Logger::log($sentMessage);
}
}
}
}
}
}
function welcome_toggle($update, $MadelineProto)
{
if (is_supergroup($update, $MadelineProto)) {
$msg_id = $update['update']['message']['id'];
$mods = $MadelineProto->responses['welcome_toggle']['mods'];
$chat = parse_chat_data($update, $MadelineProto);
$peer = $chat['peer'];
$ch_id = $chat['id'];
$userid = cache_from_user_info($update, $MadelineProto);
if (isset($userid['bot_api_id'])) {
$userid = $userid['bot_api_id'];
} else {
return;
}
$default = [
'peer' => $peer,
'reply_to_msg_id' => $msg_id,
'parse_mode' => 'html',
];
if (is_moderated($ch_id)) {
if (is_bot_admin($update, $MadelineProto)) {
if (from_admin_mod($update, $MadelineProto, $mods, true)) {
$default['message'] = 'Would you like to welcome users when they join this group?';
$welcomeon = ['_' => 'keyboardButtonCallback', 'text' => 'Welcome new users', 'data' => json_encode([
'q' => 'welcome', // query
'v' => 'on', // value
'u' => $userid, ])]; // userid
$welcomeoff = ['_' => 'keyboardButtonCallback', 'text' => "Don't welcome new users", 'data' => json_encode([
'q' => 'welcome',
'v' => 'off',
'u' => $userid, ])];
$row1 = ['_' => 'keyboardButtonRow', 'buttons' => [$welcomeon]];
$row2 = ['_' => 'keyboardButtonRow', 'buttons' => [$welcomeoff]];
$replyInlineMarkup = ['_' => 'replyInlineMarkup', 'rows' => [$row1, $row2]];
$default['reply_markup'] = $replyInlineMarkup;
}
}
}
if (isset($default['message'])) {
$sentMessage = $MadelineProto->messages->sendMessage(
$default
);
\danog\MadelineProto\Logger::log($sentMessage);
}
}
}