d4rktg 0.5.3__py3-none-any.whl → 0.5.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- d4rk/Handlers/_bot.py +0 -2
- d4rk/Utils/__init__.py +1 -1
- d4rk/Utils/_decorators.py +53 -59
- d4rk/Utils/_round.py +33 -0
- {d4rktg-0.5.3.dist-info → d4rktg-0.5.4.dist-info}/METADATA +1 -1
- {d4rktg-0.5.3.dist-info → d4rktg-0.5.4.dist-info}/RECORD +8 -8
- {d4rktg-0.5.3.dist-info → d4rktg-0.5.4.dist-info}/WHEEL +0 -0
- {d4rktg-0.5.3.dist-info → d4rktg-0.5.4.dist-info}/top_level.txt +0 -0
d4rk/Handlers/_bot.py
CHANGED
@@ -51,8 +51,6 @@ class BotManager(Client):
|
|
51
51
|
if self._loop:asyncio.run_coroutine_threadsafe(coro_func(), self._loop)
|
52
52
|
else:logger.error("Event loop is not set for _safe_async")
|
53
53
|
|
54
|
-
|
55
|
-
|
56
54
|
async def powerup(self,appname):
|
57
55
|
if hasattr(self, "db"):
|
58
56
|
self.font = self.db.Settings.get(key="font",datatype=str)
|
d4rk/Utils/__init__.py
CHANGED
d4rk/Utils/_decorators.py
CHANGED
@@ -3,7 +3,7 @@ import asyncio
|
|
3
3
|
import functools
|
4
4
|
|
5
5
|
from typing import Union
|
6
|
-
from pyrogram import Client
|
6
|
+
from pyrogram import Client , filters
|
7
7
|
from d4rk.Logs import setup_logger
|
8
8
|
from pyrogram.types import Message , CallbackQuery , ChatPrivileges
|
9
9
|
|
@@ -16,63 +16,57 @@ logger = setup_logger(__name__)
|
|
16
16
|
|
17
17
|
OWNER = int(os.getenv("OWNER", 7859877609))
|
18
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
|
-
if not authorized:
|
60
|
-
logger.warning(f"Unauthorized {func.__name__} request from user {user.id} @{user.username}")
|
61
|
-
if alert:
|
62
|
-
m = await client.send_alert(message=message,text="❌ Unauthorized access.")
|
63
|
-
if react and isinstance(message, Message):
|
64
|
-
await message.react(Reacts.shit)
|
65
|
-
if m:await delete(client, message.chat.id, m.id, timeout=5)
|
66
|
-
|
19
|
+
|
20
|
+
def authorize(
|
21
|
+
sudo=True,
|
22
|
+
admin=False,
|
23
|
+
permission=None,
|
24
|
+
owner_id: int = None
|
25
|
+
):
|
26
|
+
async def func(flt, client: Client, message: Union[Message, CallbackQuery]):
|
27
|
+
try:
|
28
|
+
user = message.from_user
|
29
|
+
if not user:
|
30
|
+
logger.warning(f"Unauthorized access attempt from non-user message: {message}")
|
31
|
+
return False
|
32
|
+
|
33
|
+
me = await client.get_me()
|
34
|
+
is_admin = False
|
35
|
+
|
36
|
+
if admin:
|
37
|
+
if message.chat.type.name.lower() in ["group", "supergroup"]:
|
38
|
+
role = await client.get_chat_member(message.chat.id, user.id)
|
39
|
+
myrole = await client.get_chat_member(message.chat.id, me.id)
|
40
|
+
|
41
|
+
role_status = getattr(role.status, "name", role.status).lower()
|
42
|
+
myrole_status = getattr(myrole.status, "name", myrole.status).lower()
|
43
|
+
|
44
|
+
if role_status in ["creator", "administrator"] and \
|
45
|
+
myrole_status in ["creator", "administrator"]:
|
46
|
+
|
47
|
+
if permission:
|
48
|
+
privileges = getattr(role, "privileges", None)
|
49
|
+
myprivileges = getattr(myrole, "privileges", None)
|
50
|
+
if privileges and myprivileges:
|
51
|
+
has_permission = getattr(privileges, permission, False)
|
52
|
+
has_my_permission = getattr(myprivileges, permission, False)
|
53
|
+
if has_permission and has_my_permission:
|
54
|
+
is_admin = True
|
55
|
+
else:
|
56
|
+
return False
|
57
|
+
else:
|
58
|
+
is_admin = True
|
67
59
|
else:
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
return
|
76
|
-
|
77
|
-
|
60
|
+
return False
|
61
|
+
|
62
|
+
authorized = (
|
63
|
+
(owner_id and user.id == owner_id)
|
64
|
+
or (sudo and user.id in getattr(client, "sudo_users", []))
|
65
|
+
or is_admin
|
66
|
+
)
|
67
|
+
return bool(authorized)
|
68
|
+
except Exception as e:
|
69
|
+
logger.error(f"Error in authorize filter: {e}")
|
70
|
+
return bool(owner_id and user.id == user.id)
|
78
71
|
|
72
|
+
return filters.create(func, name="AuthorizeFilter")
|
d4rk/Utils/_round.py
CHANGED
@@ -11,6 +11,39 @@ responded_messages = {}
|
|
11
11
|
# Lock per chat to prevent race conditions
|
12
12
|
chat_locks = {}
|
13
13
|
|
14
|
+
def round():
|
15
|
+
async def func(flt, client: Client, message: Union[Message, CallbackQuery]):
|
16
|
+
chat_id = message.chat.id
|
17
|
+
msg_id = message.id
|
18
|
+
|
19
|
+
if message.chat.type.name.lower() == "private":
|
20
|
+
return True
|
21
|
+
|
22
|
+
if chat_id not in bot_order_per_chat:
|
23
|
+
bot_order_per_chat[chat_id] = [client.me.id]
|
24
|
+
last_index_per_chat[chat_id] = 0
|
25
|
+
responded_messages[chat_id] = set()
|
26
|
+
chat_locks[chat_id] = asyncio.Lock()
|
27
|
+
|
28
|
+
if client.me.id not in bot_order_per_chat[chat_id]:
|
29
|
+
bot_order_per_chat[chat_id].append(client.me.id)
|
30
|
+
|
31
|
+
async with chat_locks[chat_id]:
|
32
|
+
# Skip if message already responded
|
33
|
+
if msg_id in responded_messages[chat_id]:
|
34
|
+
return False
|
35
|
+
|
36
|
+
# Decide which bot should respond
|
37
|
+
current_index = last_index_per_chat[chat_id]
|
38
|
+
selected_bot_id = bot_order_per_chat[chat_id][current_index]
|
39
|
+
|
40
|
+
if client.me.id == selected_bot_id:
|
41
|
+
# Mark message as responded
|
42
|
+
responded_messages[chat_id].add(msg_id)
|
43
|
+
# Rotate for next message
|
44
|
+
last_index_per_chat[chat_id] = (current_index + 1) % len(bot_order_per_chat[chat_id])
|
45
|
+
return True
|
46
|
+
|
14
47
|
def round_robin():
|
15
48
|
def decorator(func):
|
16
49
|
@wraps(func)
|
@@ -2,23 +2,23 @@ d4rk/__init__.py,sha256=Xq5qqX-FwosTJBLrSPF53FPD6fEISH750hbImZpSu5k,202
|
|
2
2
|
d4rk/Database/__init__.py,sha256=TQB5D8PBDCq80jPq6rsC2G939yYYKTh_bCcOWsZ-nA8,18
|
3
3
|
d4rk/Database/db.py,sha256=5T-dbHPQp9JF2rQb707SLSSkAaz8ghX4lO7g_Siy7oA,1870
|
4
4
|
d4rk/Handlers/__init__.py,sha256=lO1b7Tnu3GWgwcJmX5qepiNqaBBi6qTgjj0SlzVUyEA,63
|
5
|
-
d4rk/Handlers/_bot.py,sha256=
|
5
|
+
d4rk/Handlers/_bot.py,sha256=FaWw5EHx4GFGjJikrno_fNxxDp2gBEQVH0bnD3O1kbk,9066
|
6
6
|
d4rk/Handlers/_scheduler.py,sha256=AyqexO4nxZlIzRfU9vWTfJtTWQVQmP4de7GRPg-3JkA,1236
|
7
7
|
d4rk/Logs/__init__.py,sha256=mXWD5jXnyH3_AvS7K_ki3iw5BpoEAvrDFbmr-iEFNnY,22
|
8
8
|
d4rk/Logs/_logger.py,sha256=lqfVvCO0vZ_IaGOdIE4HA2KAUQZh7yW2iAHZcBz7F4o,4120
|
9
9
|
d4rk/Models/__init__.py,sha256=7bYM2c5Uk_VEg7NxIGH2EcEXGcAguwxvH23-Gy1orMM,100
|
10
10
|
d4rk/Models/_commands.py,sha256=U831pYCQbAYxyn3t6f49Wlk7vWycynR0sjxIOy0xjS8,2816
|
11
11
|
d4rk/Models/_movie_title.py,sha256=Xp8eafBP-kD3MxAdeNcb7EyiAojn5fDQ18la7vxrg10,812
|
12
|
-
d4rk/Utils/__init__.py,sha256=
|
13
|
-
d4rk/Utils/_decorators.py,sha256=
|
12
|
+
d4rk/Utils/__init__.py,sha256=nWnDrvTJ8BgbqEE9aiVOcT8JoxK6P4XvP9_rgUwEHXs,333
|
13
|
+
d4rk/Utils/_decorators.py,sha256=BDxTvsDpbmWQuTIMkgR0GsAC2AjqPdNOtAEzQcfEw7g,2708
|
14
14
|
d4rk/Utils/_delete.py,sha256=gSmQAENGmM5XCCJfPuJ4vRMSxtixYG0vYdocU-2TSFg,581
|
15
15
|
d4rk/Utils/_fonts.py,sha256=CQsDqPgvp27t3f75Cxod0EmZogEssLwIpyesH-YY5KM,7518
|
16
16
|
d4rk/Utils/_ip.py,sha256=KJJW2QSngshIVWCO5YPXF1wj4IPQzVN5oFofpfzlU5w,559
|
17
17
|
d4rk/Utils/_movie_parser.py,sha256=QEPd3z04p4pk2vxZ-2fYlRxHmQbmwQd2mCIlBsBM5AY,7039
|
18
18
|
d4rk/Utils/_ractions.py,sha256=wOVPyoFnbDuMgoP6NF_gLO1DYcfhERC0trdAK1jWSE8,2170
|
19
|
-
d4rk/Utils/_round.py,sha256=
|
19
|
+
d4rk/Utils/_round.py,sha256=8mWNKfCSlN8-ClcG8MG1NydyDH3trGInFwV-Ede2bjA,3425
|
20
20
|
d4rk/Utils/_terminal.py,sha256=Anu4OcffY3v6LMOrCskP1cHrJIliomo1Hjownbhh2sQ,125
|
21
|
-
d4rktg-0.5.
|
22
|
-
d4rktg-0.5.
|
23
|
-
d4rktg-0.5.
|
24
|
-
d4rktg-0.5.
|
21
|
+
d4rktg-0.5.4.dist-info/METADATA,sha256=8QjqlkoEHkRLEdbPIgDeqjVHQlo7fGlp-5OdIvyZMjA,652
|
22
|
+
d4rktg-0.5.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
23
|
+
d4rktg-0.5.4.dist-info/top_level.txt,sha256=qs1qTnKWImmGi7E0FoJS0OAEOHoVZA9vHRS3Pm6ncAo,5
|
24
|
+
d4rktg-0.5.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|