forked from hbashton/BruhhBot-Madeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
promote.php
164 lines (159 loc) · 7.07 KB
/
promote.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?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 promoteme($update, $MadelineProto, $msg = '')
{
if (is_supergroup($update, $MadelineProto)) {
$msg_id = $update['update']['message']['id'];
$mods = $MadelineProto->responses['promoteme']['mods'];
$chat = parse_chat_data($update, $MadelineProto);
$peer = $chat['peer'];
$title = htmlentities($chat['title']);
$ch_id = $chat['id'];
$fromid = cache_from_user_info($update, $MadelineProto);
if (!isset($fromid['bot_api_id'])) {
return;
}
$fromid = $fromid['bot_api_id'];
$from_name = catch_id($update, $MadelineProto, $fromid)[2];
$default = [
'peer' => $peer,
'reply_to_msg_id' => $msg_id,
'parse_mode' => 'html',
];
if (is_moderated($ch_id)) {
if (from_admin($update, $MadelineProto, $mods, true)) {
if (!empty($msg) or array_key_exists('reply_to_msg_id', $update['update']['message'])) {
$id = catch_id($update, $MadelineProto, $msg);
if ($id[0]) {
$userid = $id[1];
$username = $id[2];
$mention = html_mention($username, $userid);
$channelAdminRights = ['_' => 'channelAdminRights', 'change_info' => true, 'delete_messages' => true, 'ban_users' => true, 'invite_users' => true, 'pin_messages' => true, 'add_admins' => true];
try {
$editAdmin = $MadelineProto->
channels->editAdmin(
['channel' => $peer,
'user_id' => $userid,
'admin_rights' => $channelAdminRights]
);
\danog\MadelineProto\Logger::log($editAdmin);
} catch (Exception $e) {
var_dump($e->getMessage());
var_dump($e->rpc);
}
$str = $MadelineProto->responses['promoteme']['success'];
$repl = [
'mention' => $mention,
'title' => $title,
];
$message = $MadelineProto->engine->render($str, $repl);
$default['message'] = $message;
$alert = "<code>$from_name promoted $username to a moderator in $title</code>";
} else {
$str = $MadelineProto->responses['promoteme']['idk'];
$repl = [
'msg' => $msg,
];
$message = $MadelineProto->engine->render($str, $repl);
$default['message'] = $message;
}
} else {
$message = $MadelineProto->responses['promoteme']['help'];
$default['message'] = $message;
}
}
}
if (isset($default['message'])) {
$sentMessage = $MadelineProto->messages->sendMessage(
$default
);
}
if (isset($sentMessage)) {
\danog\MadelineProto\Logger::log($sentMessage);
}
if (isset($alert)) {
alert_moderators($MadelineProto, $ch_id, $alert);
}
}
}
function demoteme($update, $MadelineProto, $msg = '')
{
if (is_supergroup($update, $MadelineProto)) {
$msg_id = $update['update']['message']['id'];
$mods = "Wow. Mr. I'm not admin over here is trying to DEMOTE people.";
$chat = parse_chat_data($update, $MadelineProto);
$peer = $chat['peer'];
$title = htmlentities($chat['title']);
$ch_id = $chat['id'];
$fromid = cache_from_user_info($update, $MadelineProto);
if (!isset($fromid['bot_api_id'])) {
return;
}
$fromid = $fromid['bot_api_id'];
$from_name = catch_id($update, $MadelineProto, $fromid)[2];
$default = [
'peer' => $peer,
'reply_to_msg_id' => $msg_id,
'parse_mode' => 'html',
];
if (from_admin($update, $MadelineProto, $mods, true)) {
if (!empty($msg) or array_key_exists('reply_to_msg_id', $update['update']['message'])) {
$id = catch_id($update, $MadelineProto, $msg);
if ($id[0]) {
$userid = $id[1];
$username = $id[2];
$mention = html_mention($username, $userid);
$channelAdminRights = ['_' => 'channelAdminRights', 'change_info' => false, 'delete_messages' => false, 'ban_users' => false, 'invite_users' => false, 'pin_messages' => false, 'add_admins' => false];
$editAdmin = $MadelineProto->
channels->editAdmin(
['channel' => $peer,
'user_id' => $userid,
'admin_rights' => $channelAdminRights ]
);
$str = $MadelineProto->responses['demoteme']['success'];
$repl = [
'mention' => $mention,
'title' => $title,
];
$message = $MadelineProto->engine->render($str, $repl);
$default['message'] = $message;
$alert = "<code>$from_name demoted $username in $title</code>";
} else {
$str = $MadelineProto->responses['demoteme']['idk'];
$repl = [
'msg' => $msg,
];
$message = $MadelineProto->engine->render($str, $repl);
$default['message'] = $message;
}
} else {
$message = $MadelineProto->responses['demoteme']['help'];
$default['message'] = $message;
}
}
if (isset($default['message'])) {
$sentMessage = $MadelineProto->messages->sendMessage(
$default
);
}
if (isset($sentMessage)) {
\danog\MadelineProto\Logger::log($sentMessage);
}
if (isset($alert)) {
alert_moderators($MadelineProto, $ch_id, $alert);
}
}
}