-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
347 lines (339 loc) · 17.2 KB
/
main.py
File metadata and controls
347 lines (339 loc) · 17.2 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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import method
mt = method.mt
client = method.cli
@client.on_message(method.Filters.group & method.Filters.text)
def _cli_process_msgs(cli: method.Client, msg: method.Message):
cid = msg.chat.id
uid = msg.from_user.id
txt = method.cmd(msg.text.lower())
method.Timer(120, method.check_expire, args=[msg]).start()
try:
if method.is_manager(uid):
if method.search(r'^(add sudo)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$', txt):
sudo_id = method.search(r'^(add sudo)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$',
txt).group(3)
if sudo_id:
if sudo_id.isnumeric():
try:
method.add_sudo(
user_id=sudo_id,
answer_to=msg
)
except Exception as error:
print('{}'.format(error))
else:
try:
method.send_msg(
msg.chat.id,
method.returns[6]
)
except Exception as error:
print('{}'.format(error))
elif msg.reply_to_message:
try:
method.add_sudo(
user_id=msg.reply_to_message.from_user.id,
answer_to=msg
)
except Exception as error:
print('{}'.format(error))
elif method.search(r'^(rem sudo)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$', txt):
sudo_id = method.search(r'^(rem sudo)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$',
txt).group(3)
if sudo_id:
if sudo_id.isnumeric():
try:
method.rem_sudo(sudo_id, msg)
except Exception as error:
print('{}'.format(error))
else:
try:
method.send_msg(
msg.chat.id,
method.returns[6]
)
except Exception as error:
print('{}'.format(error))
elif msg.reply_to_message:
try:
method.rem_sudo(msg.reply_to_message.from_user.id, msg)
except Exception as error:
print('{}'.format(error))
if method.is_sudo(uid):
if method.search(r'^sudo list$', txt):
text = "\n".join(list(method.redis.smembers('{}:sudo'.format(method.api.get_me().id)))) or 'List Is Empty.'
method.send_msg(
chat_id=msg.chat.id,
text=text
)
elif method.search(r'^rem$', txt):
method.rem_group(msg.chat.id, msg)
elif method.search(r'^charge(\s(\d+)([smhd]))?$', txt):
if not method.is_group(msg.chat.id):
method.add_group(msg.chat.id, msg)
count = str(method.search(r'charge(\s(\d+)([smhd]))?', txt).group(2))
mode = str(method.search(r'charge(\s(\d+)([smhd]))?', txt).group(3))
if mode.lower() == 's':
exp = int(count)
method.redis.setex('{0}:{1}:expire'.format(method.api.get_me().id, cid), int(exp), 'enable')
txt = 'ربات به مدت {0} ثانیه برای گروه {1} فعال شد.'.format(count, msg.chat.id)
elif mode.lower() == 'm':
exp = int(count) * 60
method.redis.setex('{0}:{1}:expire'.format(method.api.get_me().id, cid), int(exp), 'enable')
txt = 'ربات به مدت {0} دقیقه برای گروه {1} فعال شد.'.format(count, msg.chat.id)
elif mode.lower() == 'h':
exp = int(count) * 60 * 60
method.redis.setex('{0}:{1}:expire'.format(method.api.get_me().id, cid), int(exp), 'enable')
txt = 'ربات به مدت {0} ساعت برای گروه {1} فعال شد.'.format(count, msg.chat.id)
for user in method.manager:
try:
method.send_msg(int(user), 'ربات به مدت {0} ساعت برای گروه {1} شارژ شد.'.format(count, msg.chat.id))
except:
pass
elif mode.lower() == 'd':
exp = int(count) * 60 * 60 * 24
method.redis.setex('{0}:{1}:expire'.format(method.api.get_me().id, cid), int(exp), 'enable')
txt = 'ربات به مدت {0} روز برای گروه {1} فعال شد.'.format(count, msg.chat.id)
else:
method.redis.set('{0}:{1}:expire'.format(method.api.get_me().id, cid), 'enable')
txt = 'ربات برای همیشه برای گروه {1} فعال شد.'.format(count, msg.chat.id)
method.send_msg(msg.chat.id, txt)
for user in method.manager:
try:
method.send_msg(int(user), txt)
except:
pass
elif method.search(r'^(add owner)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$', txt):
sudo_id = method.search(r'^(add owner)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$', txt).group(3)
if sudo_id:
if sudo_id.isnumeric():
try:
method.add_owner(
chat_id=msg.chat.id,
user_id=sudo_id,
answer_to=msg
)
except Exception as error:
print('{}'.format(error))
else:
try:
method.send_msg(
msg.chat.id,
method.returns[6]
)
except Exception as error:
print('{}'.format(error))
elif msg.reply_to_message:
try:
method.add_owner(
chat_id=msg.chat.id,
user_id=msg.reply_to_message.from_user.id,
answer_to=msg
)
except Exception as error:
print('{}'.format(error))
elif method.search(r'^(rem owner)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$', txt):
sudo_id = method.search(r'^(rem owner)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$', txt).group(3)
if sudo_id:
if sudo_id.isnumeric():
try:
method.rem_owner(
chat_id=msg.chat.id,
user_id=sudo_id,
answer_to=msg
)
except Exception as error:
print('{}'.format(error))
else:
try:
method.send_msg(
msg.chat.id,
method.returns[6]
)
except Exception as error:
print('{}'.format(error))
elif msg.reply_to_message:
try:
method.rem_owner(
chat_id=msg.chat.id,
user_id=msg.reply_to_message.from_user.id,
answer_to=msg
)
except Exception as error:
print('{}'.format(error))
if method.is_owner(cid, uid):
if method.search(r'^(add admin)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$', txt):
sudo_id = method.search(r'^(add admin)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$', txt).group(3)
if sudo_id:
if sudo_id.isnumeric():
try:
method.add_admin(
chat_id=msg.chat.id,
user_id=sudo_id,
answer_to=msg
)
except Exception as error:
print('{}'.format(error))
else:
try:
method.send_msg(
msg.chat.id,
method.returns[6]
)
except Exception as error:
print('{}'.format(error))
elif msg.reply_to_message:
try:
method.add_admin(
chat_id=msg.chat.id,
user_id=msg.reply_to_message.from_user.id,
answer_to=msg
)
except Exception as error:
print('{}'.format(error))
elif method.search(r'^(rem admin)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$', txt):
sudo_id = method.search(r'^(rem admin)(\s(\d+|@[a-zA-Z](?!.*[_]{2})[a-zA-Z0-9_]{3,30}[a-zA-Z0-9]))?$', txt).group(3)
if sudo_id:
if sudo_id.isnumeric():
try:
method.rem_admin(
chat_id=msg.chat.id,
user_id=sudo_id,
answer_to=msg
)
except Exception as error:
print('{}'.format(error))
else:
try:
method.send_msg(
msg.chat.id,
method.returns[6]
)
except Exception as error:
print('{}'.format(error))
elif msg.reply_to_message:
try:
method.rem_admin(
chat_id=msg.chat.id,
user_id=msg.reply_to_message.from_user.id,
answer_to=msg
)
except Exception as error:
print('{}'.format(error))
elif method.search(r'^owner list$', txt):
text = "\n".join(list(method.redis.smembers('{}:{}:owner'.format(method.api.get_me().id, cid))))
method.send_msg(
chat_id=msg.chat.id,
text=text
)
if method.is_admin(cid, uid):
if method.is_group(msg.chat.id):
if method.search(r'^id$', txt):
txt = '**Group Id** **:** `{}`\n'.format(msg.chat.id)
txt += '**Personal Id** **:** `{}`\n'.format(msg.from_user.id)
if msg.forward_from:
txt += '**Fwd Personal Id** **:** `{}`\n'.format(msg.forward_from.id)
elif msg.forward_from_chat:
txt += '**Fwd Channel Id** **:** `{}`\n'.format(msg.forward_from_chat.id)
if msg.reply_to_message:
txt += '**Reply User Id** **:** `{}`\n'.format(msg.reply_to_message.from_user.id)
if msg.reply_to_message.forward_from:
txt += '**Reply Fwd Personal Id** **:** `{}`\n'.format(msg.reply_to_message.forward_from.id)
elif msg.reply_to_message.forward_from_chat:
txt += '**Reply Fwd Channel Id** **:** `{}`\n'.format(
msg.reply_to_message.forward_from_chat.id)
cli.send_message(
chat_id=msg.chat.id,
text=txt,
parse_mode='markdown'
)
elif method.search(r'^admin list$', txt):
text = "\n".join(list(method.redis.smembers('{}:{}:admin'.format(method.api.get_me().id, cid))))
method.send_msg(
chat_id=msg.chat.id,
text=text
)
elif method.search(r'^clean$', txt):
try:
th = method.Thread(target=method.rem_all_msgs, args=(msg,))
th.start()
except Exception as error:
method.send_msg(method.log_channel, '{}'.format(error))
elif method.search(r'^del (\d+)$', txt):
try:
count = method.search(r'del (\d+)', txt).group(1)
if (not method.is_sudo(msg.from_user.id)) and (int(count) not in range(1, 101)):
text = 'لطفا عددی بین 0 تا 101 وارد نمایید.'
method.send_msg(msg.chat.id, text)
return
th = method.Thread(target=method.rem_msg_by_number, args=(cid, int(count), msg))
th.start()
except Exception as error:
method.send_msg(method.log_channel, '{}'.format(error))
elif method.search(r'^del all', txt) and msg.reply_to_message:
reply_msg = client.get_messages(cid, msg.reply_to_message.message_id)
print('{}'.format(reply_msg))
try:
client.send(
method.functions.channels.DeleteUserHistory(
client.resolve_peer(msg.chat.id),
client.resolve_peer(reply_msg.from_user.id)
)
)
txt = '**All Messages From** {0} **Has Been Deleted**'.format(method.mention(reply_msg.from_user.id))
mt.send_message(msg.chat.id, txt, parse_mode='markdown')
except Exception as error:
print('{}'.format(error))
elif method.search(r'^del$', txt) and msg.reply_to_message:
try:
cli.delete_messages(msg.chat.id, [msg.message_id, msg.reply_to_message.message_id])
except Exception as error:
method.send_msg(method.log_channel, '{}'.format(error))
elif method.search(r'^ping$', txt):
method.send_msg(msg.chat.id, '**Pong**', parse_mode='markdown')
elif method.search(r'^help$', txt):
text = """⚠️نکته⚠️
〽️مقام ها از بالا به پایین میباشد یعنی مقام بالا تمامی اختیارات مقام پایین تر را دارا میباشد.
🔰**manager (صاحبان ربات)**
`add sudo`
`rem sudo`
🔰**sudo (مدیران ربات)**
`sudo list`
`add`
`rem`
`charge (n)[d/h/m/s]`
`add owner`
`rem owner`
🔰**owner (صاحبان گروه)**
`add admin`
`rem admin`
`owner list`
🔰**admin (مدیران گروه)**
`admin list`
`clean`
`del (n)`
`del all`
`info`
`ping`
"""
method.send_msg(msg.chat.id, text)
elif method.search(r'^info$', txt):
expire = method.get_expire(msg.chat.id)
if expire == 'limited':
method.check_expire(msg)
return
elif expire == 'unlimited':
expire = 'نامحدود'
else:
expire = expire.replace('d', ' روز و ').replace('h', ' ساعت و ').replace('m', ' دقیقه و ').replace('s', ' ثانیه ')
method.send_msg(cid, expire)
elif method.search(r'clean delete', txt):
result = cli.get_chat_members(
msg.chat.id,
filter='kicked'
)
print(result)
except Exception as error:
print('{}'.format(error))
if __name__ == '__main__':
method.run()