This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncs.php
223 lines (172 loc) · 6.19 KB
/
funcs.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
function import_contact($MadelineProto, $id, $tg, $day = NULL, $month = NULL) {
try {
$inputPhoneContact = ['_' => 'inputPhoneContact', 'client_id' => $id, 'phone' => $tg, 'first_name' => $id, 'last_name' => "До $day $month"];
$contacts_ImportedContacts = $MadelineProto->contacts->importContacts(['contacts' => [$inputPhoneContact], ]);
var_dump($contacts_ImportedContacts);
$user = $contacts_ImportedContacts["imported"][0]["user_id"];
return $user;
if (!$contacts_ImportedContacts) {
throw new Exception('#32');
}
} catch (Exception $e) {
$exc = 'import_contact: ' . $e->getMessage() . "\n";
echo($exc);
}
}
function kick_user($MadelineProto, $chnl, $user) {
try {
$rights = ['_' => 'channelBannedRights', 'view_messages' => true, 'until_date' => "0"];
$Updates = $MadelineProto->channels->editBanned(['channel' => $chnl, 'user_id' => $user, 'banned_rights' => $rights, ]);
if (!$Updates) {
throw new Exception('#23');
}
} catch (Exception $e) {
$exc = 'delete_user: ' . $e->getMessage() . "\n";
return $exc;
}
}
function delete_contact($MadelineProto, $user) {
try {
$contacts_Link = $MadelineProto->contacts->deleteContact(['id' => $user, ]);
if (!$contacts_Link) {
throw new Exception('#23');
}
} catch (Exception $e) {
$exc = 'delete_contact: ' . $e->getMessage() . "\n";
echo($exc);
}
}
function unban_user($MadelineProto, $user) {
try {
$Bool = $MadelineProto->contacts->unblock(['id' => $user, ]);
if (!$Bool) {
throw new Exception('#23');
}
} catch (Exception $e) {
$exc = 'unban_user: ' . $e->getMessage() . "\n";
echo($exc);
}
}
function create_invite($MadelineProto, $chnl) {
try {
$ChatInvite = $MadelineProto->channels->exportInvite(['channel' => $chnl, ]);
return $link = $ChatInvite["link"];
if (!$ChatInvite) {
throw new Exception('#57');
}
} catch (Exception $e) {
$exc = 'create_invite: ' . $e->getMessage() . "\n";
echo($exc);
}
}
function invite_user($MadelineProto, $link, $user) {
try {
$update = $MadelineProto->channels->inviteToChannel(['channel' => $link, 'users' => [$user,],]);
if (!$update) {
throw new Exception('Error #32');
}
} catch (Exception $e) {
$exc = 'invite_user: ' . $e->getMessage() . "\n";
return $exc;
}
}
function send_message($MadelineProto, $user, $msg, $parse_mode, array $buttons = NULL, $reply = NULL) {
if (!empty($buttons)) {
$row = [
'_' => 'keyboardButtonRow',
'buttons' => [$buttons,],
];
$reply = [
'_' => 'replyInlineMarkup',
'rows' => [$row,],
];
}
try {
$MadelineProto->messages->sendMessage(['peer' => $user, 'message' => $msg, 'reply_markup' => $reply, 'parse_mode' => $parse_mode]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
$MadelineProto->messages->sendMessage(['peer' => 565324826, 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
}
}
function calendar($date) {
$date2o = date_parse_from_format("Y-m-d", $date);
$datez = array(
"1" => "Января",
"2" => "Февраля",
"3" => "Марта",
"4" => "Апреля",
"5" => "Мая",
"6" => "Июня",
"7" => "Июля",
"8" => "Августа",
"9" => "Сентября",
"10" => "Октября",
"11" => "Ноября",
"12" => "Декабря",
);
$day = $date2o["day"];
$month = $datez[$date2o["month"]];
$year = $date2o["year"];
return array(
"day" => $day,
"month" => $month,
"year" => $year,
);
}
// database
function wu($conn, $user, $method, $step = NULL, $message = NULL, $data = NULL) {
switch ($method) {
case "check":
try {
$result = $conn->query("SELECT * FROM bot WHERE user = '$user'");
$bot = $result->fetch_assoc(); $result->close();
return $bot;
} catch (Exception $e) {
$exc = 'check_user: ' . $e->getMessage() . "\n";
return $exc;
}
break;
case "update":
try {
$conn->query("UPDATE bot SET step = '$step' WHERE user = '$user'");
} catch (Exception $e) {
$exc = 'update_user: ' . $e->getMessage() . "\n";
return $exc;
}
break;
case "end":
try {
$conn->query("DELETE FROM bot WHERE user = '$user'");
} catch (Exception $e) {
$exc = 'end_user: ' . $e->getMessage() . "\n";
return $exc;
}
break;
case "add":
if ($step != NULL && $message == NULL) {
$message = $step;
$step = 0;
}
try {
$conn->query("INSERT INTO bot VALUES ('', '$user', '$message', '$step', '$data')");
} catch (Exception $e) {
$exc = 'add_user: ' . $e->getMessage() . "\n";
return $exc;
}
break;
case "data":
if ($step != NULL && $message != NULL && $data == NULL) $data = $message;
if ($step != NULL && $message == NULL) {
$message = $step;
$step = 0;
}
try {
$conn->query("UPDATE bot SET step = '$step', data = '$data' WHERE user = '$user'");
} catch (Exception $e) {
$exc = 'data_user: ' . $e->getMessage() . "\n";
return $exc;
}
break;
}
}
?>