randydev commited on
Commit
3655a2b
·
verified ·
1 Parent(s): 2acfa60

Upload 3 files

Browse files
Akeno/utils/database.py ADDED
@@ -0,0 +1,583 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import time
3
+
4
+ from motor import motor_asyncio
5
+ from motor.core import AgnosticClient
6
+
7
+ from config import MONGO_URL
8
+ from Akeno.utils.logger import LOGS
9
+
10
+
11
+ class Database:
12
+ def __init__(self, uri: str) -> None:
13
+ self.client: AgnosticClient = motor_asyncio.AsyncIOMotorClient(uri)
14
+ self.db = self.client["Akeno"]
15
+
16
+ self.afk = self.db["afk"]
17
+ self.antiflood = self.db["antiflood"]
18
+ self.autopost = self.db["autopost"]
19
+ self.blacklist = self.db["blacklist"]
20
+ self.echo = self.db["echo"]
21
+ self.env = self.db["env"]
22
+ self.filter = self.db["filter"]
23
+ self.forcesub = self.db["forcesub"]
24
+ self.gachabots = self.db["gachabots"]
25
+ self.gban = self.db["gban"]
26
+ self.gmute = self.db["gmute"]
27
+ self.greetings = self.db["greetings"]
28
+ self.mute = self.db["mute"]
29
+ self.pmpermit = self.db["pmpermit"]
30
+ self.session = self.db["session"]
31
+ self.snips = self.db["snips"]
32
+ self.stan_users = self.db["stan_users"]
33
+
34
+ async def connect(self):
35
+ try:
36
+ await self.client.admin.command("ping")
37
+ LOGS.info(
38
+ f"{Symbols.bullet * 3} Database Connection Established! {Symbols.bullet * 3}"
39
+ )
40
+ except Exception as e:
41
+ LOGS.info(f"{Symbols.cross_mark} DatabaseErr: {e} ")
42
+ quit(1)
43
+
44
+ def get_datetime(self) -> str:
45
+ return datetime.datetime.now().strftime("%d/%m/%Y - %H:%M")
46
+
47
+ async def set_env(self, name: str, value: str) -> None:
48
+ await self.env.update_one(
49
+ {"name": name}, {"$set": {"value": value}}, upsert=True
50
+ )
51
+
52
+ async def get_env(self, name: str) -> str | None:
53
+ if await self.is_env(name):
54
+ data = await self.env.find_one({"name": name})
55
+ return data["value"]
56
+ return None
57
+
58
+ async def rm_env(self, name: str) -> None:
59
+ await self.env.delete_one({"name": name})
60
+
61
+ async def is_env(self, name: str) -> bool:
62
+ if await self.env.find_one({"name": name}):
63
+ return True
64
+ return False
65
+
66
+ async def get_all_env(self) -> list:
67
+ return [i async for i in self.env.find({})]
68
+
69
+ async def is_stan(self, client: int, user_id: int) -> bool:
70
+ if await self.stan_users.find_one({"client": client, "user_id": user_id}):
71
+ return True
72
+ return False
73
+
74
+ async def add_stan(self, client: int, user_id: int) -> bool:
75
+ if await self.is_stan(client, user_id):
76
+ return False
77
+ await self.stan_users.insert_one(
78
+ {"client": client, "user_id": user_id, "date": self.get_datetime()}
79
+ )
80
+ return True
81
+
82
+ async def rm_stan(self, client: int, user_id: int) -> bool:
83
+ if not await self.is_stan(client, user_id):
84
+ return False
85
+ await self.stan_users.delete_one({"client": client, "user_id": user_id})
86
+ return True
87
+
88
+ async def get_stans(self, client: int) -> list:
89
+ return [i async for i in self.stan_users.find({"client": client})]
90
+
91
+ async def get_all_stans(self) -> list:
92
+ return [i async for i in self.stan_users.find({})]
93
+
94
+ async def is_session(self, user_id: int) -> bool:
95
+ if await self.session.find_one({"user_id": user_id}):
96
+ return True
97
+ return False
98
+
99
+ async def update_session(self, user_id: int, session: str) -> None:
100
+ await self.session.update_one(
101
+ {"user_id": user_id},
102
+ {"$set": {"session": session, "date": self.get_datetime()}},
103
+ upsert=True,
104
+ )
105
+
106
+ async def rm_session(self, user_id: int) -> None:
107
+ await self.session.delete_one({"user_id": user_id})
108
+
109
+ async def get_session(self, user_id: int):
110
+ if not await self.is_session(user_id):
111
+ return False
112
+ data = await self.session.find_one({"user_id": user_id})
113
+ return data
114
+
115
+ async def get_all_sessions(self) -> list:
116
+ return [i async for i in self.session.find({})]
117
+
118
+ async def is_gbanned(self, user_id: int) -> bool:
119
+ if await self.gban.find_one({"user_id": user_id}):
120
+ return True
121
+ return False
122
+
123
+ async def add_gban(self, user_id: int, reason: str) -> bool:
124
+ if await self.is_gbanned(user_id):
125
+ return False
126
+ await self.gban.insert_one(
127
+ {"user_id": user_id, "reason": reason, "date": self.get_datetime()}
128
+ )
129
+ return True
130
+
131
+ async def rm_gban(self, user_id: int):
132
+ if not await self.is_gbanned(user_id):
133
+ return None
134
+ reason = (await self.gban.find_one({"user_id": user_id}))["reason"]
135
+ await self.gban.delete_one({"user_id": user_id})
136
+ return reason
137
+
138
+ async def get_gban(self) -> list:
139
+ return [i async for i in self.gban.find({})]
140
+
141
+ async def get_gban_user(self, user_id: int) -> dict | None:
142
+ if not await self.is_gbanned(user_id):
143
+ return None
144
+ return await self.gban.find_one({"user_id": user_id})
145
+
146
+ async def is_gmuted(self, user_id: int) -> bool:
147
+ if await self.gmute.find_one({"user_id": user_id}):
148
+ return True
149
+ return False
150
+
151
+ async def add_gmute(self, user_id: int, reason: str) -> bool:
152
+ if await self.is_gmuted(user_id):
153
+ return False
154
+ await self.gmute.insert_one(
155
+ {"user_id": user_id, "reason": reason, "date": self.get_datetime()}
156
+ )
157
+ return True
158
+
159
+ async def rm_gmute(self, user_id: int):
160
+ if not await self.is_gmuted(user_id):
161
+ return None
162
+ reason = (await self.gmute.find_one({"user_id": user_id}))["reason"]
163
+ await self.gmute.delete_one({"user_id": user_id})
164
+ return reason
165
+
166
+ async def get_gmute(self) -> list:
167
+ return [i async for i in self.gmute.find({})]
168
+
169
+ async def add_mute(self, client: int, user_id: int, chat_id: int, reason: str):
170
+ await self.mute.update_one(
171
+ {"client": client, "user_id": user_id, "chat_id": chat_id},
172
+ {"$set": {"reason": reason, "date": self.get_datetime()}},
173
+ upsert=True,
174
+ )
175
+
176
+ async def rm_mute(self, client: int, user_id: int, chat_id: int) -> str:
177
+ reason = (await self.get_mute(client, user_id, chat_id))["reason"]
178
+ await self.mute.delete_one({"client": client, "user_id": user_id, "chat_id": chat_id})
179
+ return reason
180
+
181
+ async def is_muted(self, client: int, user_id: int, chat_id: int) -> bool:
182
+ if await self.get_mute(client, user_id, chat_id):
183
+ return True
184
+ return False
185
+
186
+ async def get_mute(self, client: int, user_id: int, chat_id: int):
187
+ data = await self.mute.find_one({"client": client, "user_id": user_id, "chat_id": chat_id})
188
+ return data
189
+
190
+ async def set_afk(
191
+ self, user_id: int, reason: str, media: int, media_type: str
192
+ ) -> None:
193
+ await self.afk.update_one(
194
+ {"user_id": user_id},
195
+ {
196
+ "$set": {
197
+ "reason": reason,
198
+ "time": time.time(),
199
+ "media": media,
200
+ "media_type": media_type,
201
+ }
202
+ },
203
+ upsert=True,
204
+ )
205
+
206
+ async def get_afk(self, user_id: int):
207
+ data = await self.afk.find_one({"user_id": user_id})
208
+ return data
209
+
210
+ async def is_afk(self, user_id: int) -> bool:
211
+ if await self.afk.find_one({"user_id": user_id}):
212
+ return True
213
+ return False
214
+
215
+ async def rm_afk(self, user_id: int) -> None:
216
+ await self.afk.delete_one({"user_id": user_id})
217
+
218
+ async def set_flood(self, client_chat: tuple[int, int], settings: dict):
219
+ await self.antiflood.update_one(
220
+ {"client": client_chat[0], "chat": client_chat[1]},
221
+ {"$set": settings},
222
+ upsert=True,
223
+ )
224
+
225
+ async def get_flood(self, client_chat: tuple[int, int]):
226
+ data = await self.antiflood.find_one(
227
+ {"client": client_chat[0], "chat": client_chat[1]}
228
+ )
229
+ return data or {}
230
+
231
+ async def is_flood(self, client_chat: tuple[int, int]) -> bool:
232
+ data = await self.get_flood(client_chat)
233
+
234
+ if not data:
235
+ return False
236
+
237
+ if data["limit"] == 0:
238
+ return False
239
+
240
+ return True
241
+
242
+ async def get_all_floods(self) -> list:
243
+ return [i async for i in self.antiflood.find({})]
244
+
245
+ async def set_autopost(self, client: int, from_channel: int, to_channel: int):
246
+ await self.autopost.update_one(
247
+ {"client": client},
248
+ {
249
+ "$push": {
250
+ "autopost": {
251
+ "from_channel": from_channel,
252
+ "to_channel": to_channel,
253
+ "date": self.get_datetime(),
254
+ }
255
+ }
256
+ },
257
+ upsert=True,
258
+ )
259
+
260
+ async def get_autopost(self, client: int, from_channel: int):
261
+ data = await self.autopost.find_one(
262
+ {
263
+ "client": client,
264
+ "autopost": {"$elemMatch": {"from_channel": from_channel}},
265
+ }
266
+ )
267
+ return data
268
+
269
+ async def is_autopost(
270
+ self, client: int, from_channel: int, to_channel: int = None
271
+ ) -> bool:
272
+ if to_channel:
273
+ data = await self.autopost.find_one(
274
+ {
275
+ "client": client,
276
+ "autopost": {
277
+ "$elemMatch": {
278
+ "from_channel": from_channel,
279
+ "to_channel": to_channel,
280
+ }
281
+ },
282
+ }
283
+ )
284
+ else:
285
+ data = await self.autopost.find_one(
286
+ {
287
+ "client": client,
288
+ "autopost": {"$elemMatch": {"from_channel": from_channel}},
289
+ }
290
+ )
291
+ return True if data else False
292
+
293
+ async def rm_autopost(self, client: int, from_channel: int, to_channel: int):
294
+ await self.autopost.update_one(
295
+ {"client": client},
296
+ {
297
+ "$pull": {
298
+ "autopost": {
299
+ "from_channel": from_channel,
300
+ "to_channel": to_channel,
301
+ }
302
+ }
303
+ },
304
+ )
305
+
306
+ async def get_all_autoposts(self, client: int) -> list:
307
+ return [i async for i in self.autopost.find({"client": client})]
308
+
309
+ async def add_blacklist(self, client: int, chat: int, blacklist: str):
310
+ await self.blacklist.update_one(
311
+ {"client": client, "chat": chat},
312
+ {"$push": {"blacklist": blacklist}},
313
+ upsert=True,
314
+ )
315
+
316
+ async def rm_blacklist(self, client: int, chat: int, blacklist: str):
317
+ await self.blacklist.update_one(
318
+ {"client": client, "chat": chat},
319
+ {"$pull": {"blacklist": blacklist}},
320
+ )
321
+
322
+ async def is_blacklist(self, client: int, chat: int, blacklist: str) -> bool:
323
+ blacklists = await self.get_all_blacklists(client, chat)
324
+ if blacklist in blacklists:
325
+ return True
326
+ return False
327
+
328
+ async def get_all_blacklists(self, client: int, chat: int) -> list:
329
+ data = await self.blacklist.find_one({"client": client, "chat": chat})
330
+
331
+ if not data:
332
+ return []
333
+
334
+ return data["blacklist"]
335
+
336
+ async def get_blacklist_clients(self) -> list:
337
+ return [i async for i in self.blacklist.find({})]
338
+
339
+ async def set_echo(self, client: int, chat: int, user: int):
340
+ await self.echo.update_one(
341
+ {"client": client, "chat": chat},
342
+ {"$push": {"echo": user}},
343
+ upsert=True,
344
+ )
345
+
346
+ async def rm_echo(self, client: int, chat: int, user: int):
347
+ await self.echo.update_one(
348
+ {"client": client, "chat": chat},
349
+ {"$pull": {"echo": user}},
350
+ )
351
+
352
+ async def is_echo(self, client: int, chat: int, user: int) -> bool:
353
+ data = await self.get_all_echo(client, chat)
354
+ if user in data:
355
+ return True
356
+ return False
357
+
358
+ async def get_all_echo(self, client: int, chat: int) -> list:
359
+ data = await self.echo.find_one({"client": client, "chat": chat})
360
+
361
+ if not data:
362
+ return []
363
+
364
+ return data["echo"]
365
+
366
+ async def set_filter(self, client: int, chat: int, keyword: str, msgid: int):
367
+ await self.filter.update_one(
368
+ {"client": client, "chat": chat},
369
+ {"$push": {"filter": {"keyword": keyword, "msgid": msgid}}},
370
+ upsert=True,
371
+ )
372
+
373
+ async def rm_filter(self, client: int, chat: int, keyword: str):
374
+ await self.filter.update_one(
375
+ {"client": client, "chat": chat},
376
+ {"$pull": {"filter": {"keyword": keyword}}},
377
+ )
378
+
379
+ async def rm_all_filters(self, client: int, chat: int):
380
+ await self.filter.delete_one({"client": client, "chat": chat})
381
+
382
+ async def is_filter(self, client: int, chat: int, keyword: str) -> bool:
383
+ data = await self.get_filter(client, chat, keyword)
384
+ return True if data else False
385
+
386
+ async def get_filter(self, client: int, chat: int, keyword: str):
387
+ data = await self.filter.find_one(
388
+ {
389
+ "client": client,
390
+ "chat": chat,
391
+ "filter": {"$elemMatch": {"keyword": keyword}},
392
+ }
393
+ )
394
+ return data
395
+
396
+ async def get_all_filters(self, client: int, chat: int) -> list:
397
+ data = await self.filter.find_one({"client": client, "chat": chat})
398
+
399
+ if not data:
400
+ return []
401
+
402
+ return data["filter"]
403
+
404
+ async def set_snip(self, client: int, chat: int, keyword: str, msgid: int):
405
+ await self.snips.update_one(
406
+ {"client": client, "chat": chat},
407
+ {"$push": {"snips": {"keyword": keyword, "msgid": msgid}}},
408
+ upsert=True,
409
+ )
410
+
411
+ async def rm_snip(self, client: int, chat: int, keyword: str):
412
+ await self.snips.update_one(
413
+ {"client": client, "chat": chat},
414
+ {"$pull": {"snips": {"keyword": keyword}}},
415
+ )
416
+
417
+ async def rm_all_snips(self, client: int, chat: int):
418
+ await self.snips.delete_one({"client": client, "chat": chat})
419
+
420
+ async def is_snip(self, client: int, chat: int, keyword: str) -> bool:
421
+ data = await self.get_snip(client, chat, keyword)
422
+ return True if data else False
423
+
424
+ async def get_snip(self, client: int, chat: int, keyword: str):
425
+ data = await self.snips.find_one(
426
+ {
427
+ "client": client,
428
+ "chat": chat,
429
+ "snips": {"$elemMatch": {"keyword": keyword}},
430
+ }
431
+ )
432
+ return data
433
+
434
+ async def get_all_snips(self, client: int, chat: int) -> list:
435
+ data = await self.snips.find_one({"client": client, "chat": chat})
436
+
437
+ if not data:
438
+ return []
439
+
440
+ return data["snips"]
441
+
442
+ async def add_pmpermit(self, client: int, user: int):
443
+ await self.pmpermit.update_one(
444
+ {"client": client, "user": user},
445
+ {"$set": {"date": self.get_datetime()}},
446
+ upsert=True,
447
+ )
448
+
449
+ async def rm_pmpermit(self, client: int, user: int):
450
+ await self.pmpermit.delete_one({"client": client, "user": user})
451
+
452
+ async def is_pmpermit(self, client: int, user: int) -> bool:
453
+ data = await self.get_pmpermit(client, user)
454
+ return True if data else False
455
+
456
+ async def get_pmpermit(self, client: int, user: int):
457
+ data = await self.pmpermit.find_one({"client": client, "user": user})
458
+ return data
459
+
460
+ async def get_all_pmpermits(self, client: int) -> list:
461
+ return [i async for i in self.pmpermit.find({"client": client})]
462
+
463
+ async def set_welcome(self, client: int, chat: int, message: int):
464
+ await self.greetings.update_one(
465
+ {"client": client, "chat": chat, "welcome": True},
466
+ {"$set": {"message": message}},
467
+ upsert=True,
468
+ )
469
+
470
+ async def rm_welcome(self, client: int, chat: int):
471
+ await self.greetings.delete_one(
472
+ {"client": client, "chat": chat, "welcome": True}
473
+ )
474
+
475
+ async def is_welcome(self, client: int, chat: int) -> bool:
476
+ data = await self.get_welcome(client, chat)
477
+ return True if data else False
478
+
479
+ async def get_welcome(self, client: int, chat: int):
480
+ data = await self.greetings.find_one(
481
+ {"client": client, "chat": chat, "welcome": True}
482
+ )
483
+ return data
484
+
485
+ async def set_goodbye(self, client: int, chat: int, message: int):
486
+ await self.greetings.update_one(
487
+ {"client": client, "chat": chat, "welcome": False},
488
+ {"$set": {"message": message}},
489
+ upsert=True,
490
+ )
491
+
492
+ async def rm_goodbye(self, client: int, chat: int):
493
+ await self.greetings.delete_one(
494
+ {"client": client, "chat": chat, "welcome": False}
495
+ )
496
+
497
+ async def is_goodbye(self, client: int, chat: int) -> bool:
498
+ data = await self.get_goodbye(client, chat)
499
+ return True if data else False
500
+
501
+ async def get_goodbye(self, client: int, chat: int):
502
+ data = await self.greetings.find_one(
503
+ {"client": client, "chat": chat, "welcome": False}
504
+ )
505
+ return data
506
+
507
+ async def get_all_greetings(self, client: int) -> list:
508
+ return [i async for i in self.greetings.find({"client": client})]
509
+
510
+ async def add_forcesub(self, chat: int, must_join: int):
511
+ await self.forcesub.update_one(
512
+ {"chat": chat},
513
+ {"$push": {"must_join": must_join}},
514
+ upsert=True,
515
+ )
516
+
517
+ async def rm_forcesub(self, chat: int, must_join: int) -> int:
518
+ await self.forcesub.update_one(
519
+ {"chat": chat},
520
+ {"$pull": {"must_join": must_join}},
521
+ )
522
+ data = await self.forcesub.find_one({"chat": chat})
523
+ return len(data["must_join"])
524
+
525
+ async def rm_all_forcesub(self, in_chat: int):
526
+ await self.forcesub.delete_one({"chat": in_chat})
527
+
528
+ async def is_forcesub(self, chat: int, must_join: int) -> bool:
529
+ data = await self.get_forcesub(chat)
530
+ if must_join in data["must_join"]:
531
+ return True
532
+ return False
533
+
534
+ async def get_forcesub(self, in_chat: int):
535
+ data = await self.forcesub.find_one({"chat": in_chat})
536
+ return data
537
+
538
+ async def get_all_forcesubs(self) -> list:
539
+ return [i async for i in self.forcesub.find({})]
540
+
541
+ async def add_gachabot(
542
+ self, client: int, bot: tuple[int, str], catch_command: str, chat_id: int
543
+ ):
544
+ await self.gachabots.update_one(
545
+ {"client": client, "bot": bot[0]},
546
+ {
547
+ "$set": {
548
+ "username": bot[1],
549
+ "catch_command": catch_command,
550
+ "chat_id": chat_id,
551
+ "date": self.get_datetime(),
552
+ }
553
+ },
554
+ upsert=True,
555
+ )
556
+
557
+ async def rm_gachabot(self, client: int, bot: int, chat_id: int = None):
558
+ if chat_id:
559
+ await self.gachabots.delete_one(
560
+ {"client": client, "bot": bot, "chat_id": chat_id}
561
+ )
562
+ else:
563
+ await self.gachabots.delete_one({"client": client, "bot": bot})
564
+
565
+ async def is_gachabot(self, client: int, bot: int, chat_id: int) -> bool:
566
+ data = await self.get_gachabot(client, bot, chat_id)
567
+ return True if data else False
568
+
569
+ async def get_gachabot(self, client: int, bot: int, chat_id: int):
570
+ data = await self.gachabots.find_one(
571
+ {"client": client, "bot": bot, "chat_id": chat_id}
572
+ )
573
+
574
+ return data
575
+
576
+ async def get_all_gachabots(self, client: int) -> list:
577
+ return [i async for i in self.gachabots.find({"client": client})]
578
+
579
+ async def get_all_gachabots_id(self) -> list:
580
+ data = await self.gachabots.distinct("bot")
581
+ return data
582
+
583
+ db = Database(MONGO_URL)
Akeno/utils/formatter.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ import re
3
+
4
+
5
+ def format_text(text: str) -> str:
6
+ emoji_pattern = re.compile(
7
+ "["
8
+ "\U0001F600-\U0001F64F" # emoticons
9
+ "\U0001F300-\U0001F5FF" # symbols & pictographs
10
+ "\U0001F680-\U0001F6FF" # transport & map symbols
11
+ "\U0001F700-\U0001F77F" # alchemical symbols
12
+ "\U0001F780-\U0001F7FF" # Geometric Shapes Extended
13
+ "\U0001F800-\U0001F8FF" # Supplemental Arrows-C
14
+ "\U0001F900-\U0001F9FF" # Supplemental Symbols and Pictographs
15
+ "\U0001FA00-\U0001FA6F" # Chess Symbols
16
+ "\U0001FA70-\U0001FAFF" # Symbols and Pictographs Extended-A
17
+ "\U00002702-\U000027B0" # Dingbats
18
+ "\U000024C2-\U0001F251" # enclosed characters
19
+ "]+",
20
+ flags=re.UNICODE,
21
+ )
22
+
23
+ return re.sub(emoji_pattern, "", text)
24
+
25
+
26
+ def superscript(text: str) -> str:
27
+ superscript_digits = str.maketrans("0123456789", "⁰¹²³⁴⁵⁶⁷⁸⁹")
28
+ return text.translate(superscript_digits)
29
+
30
+
31
+ def subscript(text: str) -> str:
32
+ subscript_digits = str.maketrans("0123456789", "₀₁₂₃₄₅₆₇₈₉")
33
+ return text.translate(subscript_digits)
34
+
35
+
36
+ def readable_time(seconds: int) -> str:
37
+ count = 0
38
+ out_time = ""
39
+ time_list = []
40
+ time_suffix_list = ["secs", "mins", "hrs", "days"]
41
+
42
+ while count < 4:
43
+ count += 1
44
+ remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24)
45
+ if seconds == 0 and remainder == 0:
46
+ break
47
+ time_list.append(int(result))
48
+ seconds = int(remainder)
49
+
50
+ for x in range(len(time_list)):
51
+ time_list[x] = str(time_list[x]) + time_suffix_list[x]
52
+
53
+ if len(time_list) == 4:
54
+ out_time += time_list.pop() + ", "
55
+
56
+ time_list.reverse()
57
+ out_time += " ".join(time_list)
58
+
59
+ return out_time or "0 secs"
60
+
61
+
62
+ def humanbytes(size: int):
63
+ if not size:
64
+ return ""
65
+ power = 2**10
66
+ number = 0
67
+ dict_power_n = {0: " ", 1: "Ki", 2: "Mi", 3: "Gi", 4: "Ti"}
68
+ while size > power:
69
+ size /= power
70
+ number += 1
71
+ return str(round(size, 2)) + " " + dict_power_n[number] + "B"
72
+
73
+
74
+ def add_to_dict(data: dict, keys: list, value: str | int | bool = None) -> None:
75
+ current_level = data
76
+ for key in keys[:-1]:
77
+ current_level = current_level.setdefault(key, {})
78
+ current_level[keys[-1]] = value
79
+
80
+
81
+ def get_from_dict(data: dict, key: list):
82
+ current_level = data
83
+ for k in key:
84
+ current_level = current_level[k]
85
+ return current_level
86
+
87
+
88
+ def limit_per_page(limit: int) -> int:
89
+ return math.ceil(limit / 10)
90
+
91
+
92
+ def secs_to_mins(secs: int) -> str:
93
+ mins, secs = divmod(secs, 60)
94
+ return f"{mins}:{secs}"
Akeno/utils/handler.py CHANGED
@@ -1,4 +1,9 @@
1
  from pyrogram import Client, filters
 
 
 
 
2
 
 
3
  Akeno = Client.on_message
4
  Akeno_chat_member_updated = Client.on_chat_member_updated()
 
1
  from pyrogram import Client, filters
2
+ from pyrogram import Client, filters
3
+ from pyrogram.enums import ChatType
4
+ from pyrogram.handlers import MessageHandler
5
+ from pyrogram.types import Message
6
 
7
+ group_only = [ChatType.GROUP, ChatType.SUPERGROUP]
8
  Akeno = Client.on_message
9
  Akeno_chat_member_updated = Client.on_chat_member_updated()