-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.py
525 lines (498 loc) · 16.5 KB
/
settings.py
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
from pyrogram import filters
from pyrogram.errors import MessageNotModified
from pyrogram.types import (CallbackQuery, InlineKeyboardButton,
InlineKeyboardMarkup, Message)
from strings.filters import command
from config import (BANNED_USERS, CLEANMODE_DELETE_MINS,
MUSIC_BOT_NAME, OWNER_ID)
from strings import get_command
from AnonX import app
from AnonX.utils.database import (add_nonadmin_chat,
cleanmode_off, cleanmode_on,
commanddelete_off,
commanddelete_on,
get_aud_bit_name, get_authuser,
get_authuser_names,
get_playmode, get_playtype,
get_vid_bit_name,
is_cleanmode_on,
is_commanddelete_on,
is_nonadmin_chat,
remove_nonadmin_chat,
save_audio_bitrate,
save_video_bitrate,
set_playmode, set_playtype)
from AnonX.utils.decorators.admins import ActualAdminCB
from AnonX.utils.decorators.language import language, languageCB
from AnonX.utils.inline.settings import (
audio_quality_markup, auth_users_markup,
cleanmode_settings_markup, playmode_users_markup, setting_markup,
video_quality_markup)
from AnonX.utils.inline.start import private_panel
### Command
SETTINGS_COMMAND = get_command("SETTINGS_COMMAND")
@app.on_message(
command(SETTINGS_COMMAND)
& filters.group
& ~BANNED_USERS
)
@language
async def settings_mar(client, message: Message, _):
buttons = setting_markup(_)
await message.reply_text(
_["setting_1"].format(message.chat.title, message.chat.id),
reply_markup=InlineKeyboardMarkup(buttons),
)
@app.on_callback_query(
filters.regex("settings_helper") & ~BANNED_USERS
)
@languageCB
async def settings_cb(client, CallbackQuery, _):
try:
await CallbackQuery.answer(_["set_cb_8"])
except:
pass
buttons = setting_markup(_)
return await CallbackQuery.edit_message_text(
_["setting_1"].format(
CallbackQuery.message.chat.title,
CallbackQuery.message.chat.id,
),
reply_markup=InlineKeyboardMarkup(buttons),
)
@app.on_callback_query(
filters.regex("settingsback_helper") & ~BANNED_USERS
)
@languageCB
async def settings_back_markup(
client, CallbackQuery: CallbackQuery, _
):
try:
await CallbackQuery.answer()
except:
pass
if CallbackQuery.message.chat.type == "private":
try:
await app.resolve_peer(OWNER_ID[0])
OWNER = OWNER_ID[0]
except:
OWNER = None
buttons = private_panel(_, app.username, OWNER)
return await CallbackQuery.edit_message_text(
_["start_2"].format(MUSIC_BOT_NAME),
reply_markup=InlineKeyboardMarkup(buttons),
)
else:
buttons = setting_markup(_)
return await CallbackQuery.edit_message_reply_markup(
reply_markup=InlineKeyboardMarkup(buttons)
)
## Audio and Video Quality
async def gen_buttons_aud(_, aud):
if aud == "High":
buttons = audio_quality_markup(_, high=True)
elif aud == "Medium":
buttons = audio_quality_markup(_, medium=True)
elif aud == "Low":
buttons = audio_quality_markup(_, low=True)
return buttons
async def gen_buttons_vid(_, aud):
if aud == "High":
buttons = video_quality_markup(_, high=True)
elif aud == "Medium":
buttons = video_quality_markup(_, medium=True)
elif aud == "Low":
buttons = video_quality_markup(_, low=True)
return buttons
# without admin rights
@app.on_callback_query(
filters.regex(
pattern=r"^(SEARCHANSWER|PLAYMODEANSWER|PLAYTYPEANSWER|AUTHANSWER|CMANSWER|COMMANDANSWER|CM|AQ|VQ|PM|AU)$"
)
& ~BANNED_USERS
)
@languageCB
async def without_Admin_rights(client, CallbackQuery, _):
command = CallbackQuery.matches[0].group(1)
if command == "SEARCHANSWER":
try:
return await CallbackQuery.answer(
_["setting_3"], show_alert=True
)
except:
return
if command == "PLAYMODEANSWER":
try:
return await CallbackQuery.answer(
_["setting_10"], show_alert=True
)
except:
return
if command == "PLAYTYPEANSWER":
try:
return await CallbackQuery.answer(
_["setting_11"], show_alert=True
)
except:
return
if command == "AUTHANSWER":
try:
return await CallbackQuery.answer(
_["setting_4"], show_alert=True
)
except:
return
if command == "CMANSWER":
try:
return await CallbackQuery.answer(
_["setting_9"].format(CLEANMODE_DELETE_MINS),
show_alert=True,
)
except:
return
if command == "COMMANDANSWER":
try:
return await CallbackQuery.answer(
_["setting_14"], show_alert=True
)
except:
return
if command == "CM":
try:
await CallbackQuery.answer(_["set_cb_5"], show_alert=True)
except:
pass
sta = None
cle = None
if await is_cleanmode_on(CallbackQuery.message.chat.id):
cle = True
if await is_commanddelete_on(CallbackQuery.message.chat.id):
sta = True
buttons = cleanmode_settings_markup(
_, status=cle, dels=sta
)
if command == "AQ":
try:
await CallbackQuery.answer(_["set_cb_1"], show_alert=True)
except:
pass
aud = await get_aud_bit_name(CallbackQuery.message.chat.id)
buttons = await gen_buttons_aud(_, aud)
if command == "VQ":
try:
await CallbackQuery.answer(_["set_cb_2"], show_alert=True)
except:
pass
aud = await get_vid_bit_name(CallbackQuery.message.chat.id)
buttons = await gen_buttons_vid(_, aud)
if command == "PM":
try:
await CallbackQuery.answer(_["set_cb_4"], show_alert=True)
except:
pass
playmode = await get_playmode(CallbackQuery.message.chat.id)
if playmode == "Direct":
Direct = True
else:
Direct = None
is_non_admin = await is_nonadmin_chat(
CallbackQuery.message.chat.id
)
if not is_non_admin:
Group = True
else:
Group = None
playty = await get_playtype(CallbackQuery.message.chat.id)
if playty == "Everyone":
Playtype = None
else:
Playtype = True
buttons = playmode_users_markup(_, Direct, Group, Playtype)
if command == "AU":
try:
await CallbackQuery.answer(_["set_cb_3"], show_alert=True)
except:
pass
is_non_admin = await is_nonadmin_chat(
CallbackQuery.message.chat.id
)
if not is_non_admin:
buttons = auth_users_markup(_, True)
else:
buttons = auth_users_markup(_)
try:
return await CallbackQuery.edit_message_reply_markup(
reply_markup=InlineKeyboardMarkup(buttons)
)
except MessageNotModified:
return
# Audio Video Quality
@app.on_callback_query(
filters.regex(pattern=r"^(LQA|MQA|HQA|LQV|MQV|HQV)$")
& ~BANNED_USERS
)
@ActualAdminCB
async def aud_vid_cb(client, CallbackQuery, _):
command = CallbackQuery.matches[0].group(1)
try:
await CallbackQuery.answer(_["set_cb_6"], show_alert=True)
except:
pass
if command == "LQA":
await save_audio_bitrate(CallbackQuery.message.chat.id, "Low")
buttons = audio_quality_markup(_, low=True)
if command == "MQA":
await save_audio_bitrate(
CallbackQuery.message.chat.id, "Medium"
)
buttons = audio_quality_markup(_, medium=True)
if command == "HQA":
await save_audio_bitrate(
CallbackQuery.message.chat.id, "High"
)
buttons = audio_quality_markup(_, high=True)
if command == "LQV":
await save_video_bitrate(CallbackQuery.message.chat.id, "Low")
buttons = video_quality_markup(_, low=True)
if command == "MQV":
await save_video_bitrate(
CallbackQuery.message.chat.id, "Medium"
)
buttons = video_quality_markup(_, medium=True)
if command == "HQV":
await save_video_bitrate(
CallbackQuery.message.chat.id, "High"
)
buttons = video_quality_markup(_, high=True)
try:
return await CallbackQuery.edit_message_reply_markup(
reply_markup=InlineKeyboardMarkup(buttons)
)
except MessageNotModified:
return
# Play Mode Settings
@app.on_callback_query(
filters.regex(
pattern=r"^(|MODECHANGE|CHANNELMODECHANGE|PLAYTYPECHANGE)$"
)
& ~BANNED_USERS
)
@ActualAdminCB
async def playmode_ans(client, CallbackQuery, _):
command = CallbackQuery.matches[0].group(1)
if command == "CHANNELMODECHANGE":
is_non_admin = await is_nonadmin_chat(
CallbackQuery.message.chat.id
)
if not is_non_admin:
await add_nonadmin_chat(CallbackQuery.message.chat.id)
Group = None
else:
await remove_nonadmin_chat(CallbackQuery.message.chat.id)
Group = True
playmode = await get_playmode(CallbackQuery.message.chat.id)
if playmode == "Direct":
Direct = True
else:
Direct = None
playty = await get_playtype(CallbackQuery.message.chat.id)
if playty == "Everyone":
Playtype = None
else:
Playtype = True
buttons = playmode_users_markup(_, Direct, Group, Playtype)
if command == "MODECHANGE":
try:
await CallbackQuery.answer(_["set_cb_6"], show_alert=True)
except:
pass
playmode = await get_playmode(CallbackQuery.message.chat.id)
if playmode == "Direct":
await set_playmode(
CallbackQuery.message.chat.id, "Inline"
)
Direct = None
else:
await set_playmode(
CallbackQuery.message.chat.id, "Direct"
)
Direct = True
is_non_admin = await is_nonadmin_chat(
CallbackQuery.message.chat.id
)
if not is_non_admin:
Group = True
else:
Group = None
playty = await get_playtype(CallbackQuery.message.chat.id)
if playty == "Everyone":
Playtype = False
else:
Playtype = True
buttons = playmode_users_markup(_, Direct, Group, Playtype)
if command == "PLAYTYPECHANGE":
try:
await CallbackQuery.answer(_["set_cb_6"], show_alert=True)
except:
pass
playty = await get_playtype(CallbackQuery.message.chat.id)
if playty == "Everyone":
await set_playtype(CallbackQuery.message.chat.id, "Admin")
Playtype = False
else:
await set_playtype(
CallbackQuery.message.chat.id, "Everyone"
)
Playtype = True
playmode = await get_playmode(CallbackQuery.message.chat.id)
if playmode == "Direct":
Direct = True
else:
Direct = None
is_non_admin = await is_nonadmin_chat(
CallbackQuery.message.chat.id
)
if not is_non_admin:
Group = True
else:
Group = None
buttons = playmode_users_markup(_, Direct, Group, Playtype)
try:
return await CallbackQuery.edit_message_reply_markup(
reply_markup=InlineKeyboardMarkup(buttons)
)
except MessageNotModified:
return
# Auth Users Settings
@app.on_callback_query(
filters.regex(pattern=r"^(AUTH|AUTHLIST)$") & ~BANNED_USERS
)
@ActualAdminCB
async def authusers_mar(client, CallbackQuery, _):
command = CallbackQuery.matches[0].group(1)
if command == "AUTHLIST":
_authusers = await get_authuser_names(
CallbackQuery.message.chat.id
)
if not _authusers:
try:
return await CallbackQuery.answer(
_["setting_5"], show_alert=True
)
except:
return
else:
try:
await CallbackQuery.answer(
_["set_cb_7"], show_alert=True
)
except:
pass
j = 0
await CallbackQuery.edit_message_text(_["auth_6"])
msg = _["auth_7"]
for note in _authusers:
_note = await get_authuser(
CallbackQuery.message.chat.id, note
)
user_id = _note["auth_user_id"]
admin_id = _note["admin_id"]
admin_name = _note["admin_name"]
try:
user = await client.get_users(user_id)
user = user.first_name
j += 1
except Exception:
continue
msg += f"{j}➤ {user}[`{user_id}`]\n"
msg += (
f" {_['auth_8']} {admin_name}[`{admin_id}`]\n\n"
)
upl = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text=_["BACK_BUTTON"], callback_data=f"AU"
),
InlineKeyboardButton(
text=_["CLOSE_BUTTON"],
callback_data=f"close",
),
]
]
)
try:
return await CallbackQuery.edit_message_text(
msg, reply_markup=upl
)
except MessageNotModified:
return
try:
await CallbackQuery.answer(_["set_cb_6"], show_alert=True)
except:
pass
if command == "AUTH":
is_non_admin = await is_nonadmin_chat(
CallbackQuery.message.chat.id
)
if not is_non_admin:
await add_nonadmin_chat(CallbackQuery.message.chat.id)
buttons = auth_users_markup(_)
else:
await remove_nonadmin_chat(CallbackQuery.message.chat.id)
buttons = auth_users_markup(_, True)
try:
return await CallbackQuery.edit_message_reply_markup(
reply_markup=InlineKeyboardMarkup(buttons)
)
except MessageNotModified:
return
## Clean Mode
@app.on_callback_query(
filters.regex(
pattern=r"^(CLEANMODE|COMMANDELMODE)$"
)
& ~BANNED_USERS
)
@ActualAdminCB
async def cleanmode_mark(client, CallbackQuery, _):
command = CallbackQuery.matches[0].group(1)
try:
await CallbackQuery.answer(_["set_cb_6"], show_alert=True)
except:
pass
if command == "CLEANMODE":
sta = None
if await is_commanddelete_on(CallbackQuery.message.chat.id):
sta = True
cle = None
if await is_cleanmode_on(CallbackQuery.message.chat.id):
await cleanmode_off(CallbackQuery.message.chat.id)
else:
await cleanmode_on(CallbackQuery.message.chat.id)
cle = True
buttons = cleanmode_settings_markup(
_, status=cle, dels=sta
)
return await CallbackQuery.edit_message_reply_markup(
reply_markup=InlineKeyboardMarkup(buttons)
)
if command == "COMMANDELMODE":
cle = None
sta = None
if await is_cleanmode_on(CallbackQuery.message.chat.id):
cle = True
if await is_commanddelete_on(CallbackQuery.message.chat.id):
await commanddelete_off(CallbackQuery.message.chat.id)
else:
await commanddelete_on(CallbackQuery.message.chat.id)
sta = True
buttons = cleanmode_settings_markup(
_, status=cle, dels=sta
)
try:
return await CallbackQuery.edit_message_reply_markup(
reply_markup=InlineKeyboardMarkup(buttons)
)
except MessageNotModified:
return