d4rktg 0.5.2__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 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)
@@ -169,8 +167,10 @@ class BotManager(Client):
169
167
  except Exception as e:logger.error(f"Failed to send restart notification: {e}")
170
168
  try:await self.edit_message_text(chat_id=chat_id,message_id=Message_id, text="Bot restarted successfully!")
171
169
  except:
172
- await self.send_message(chat_id=chat_id, text="Bot restarted successfully!",reply_to_message_id=Message_id-1,)
173
- await self.delete_messages(chat_id=chat_id,message_ids=Message_id)
170
+ try:
171
+ await self.send_message(chat_id=chat_id, text="Bot restarted successfully!",reply_to_message_id=Message_id-1,)
172
+ await self.delete_messages(chat_id=chat_id,message_ids=Message_id)
173
+ except:pass
174
174
  os.remove('restart.txt')
175
175
  else:
176
176
  try:await self.send_message(chat_id=self.LOGS, text=f"{self._bot_info.mention} started successfully!")
d4rk/Utils/__init__.py CHANGED
@@ -5,4 +5,4 @@ from ._delete import delete
5
5
  from ._ractions import Reacts
6
6
  from ._fonts import FontMessageMixin , get_font , web_app_data
7
7
  from ._movie_parser import parser
8
- from ._round import round_robin
8
+ from ._round import round_robin , round
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
- def authorize(sudo=True,admin=False,delete_command=True, react=True,react_emoji:Reacts=Reacts.fire,alert=True,permission=None):
20
- def decorator(func):
21
- @functools.wraps(func)
22
- async def wrapper(client: Client, message: Union[Message,CallbackQuery]):
23
- try:
24
- user = message.from_user
25
- if not user:
26
- logger.warning(f"Unauthorized access attempt from non-user message: {message}")
27
- me = await client.get_me()
28
- is_admin = False
29
- if admin:
30
- if message.chat.type.name.lower() in ["group","supergroup"]:
31
- role = await client.get_chat_member(message.chat.id, user.id)
32
- myrole = await client.get_chat_member(message.chat.id, me.id)
33
- if (user_admin:= role.status.name.lower() in ["creator", "administrator","owner"]) and (i_am_admin:=myrole.status.name.lower() in ["creator", "administrator","owner"]):
34
- if permission:
35
- privileges = getattr(role, "privileges", None)
36
- myprivileges = getattr(myrole, "privileges", None)
37
- if privileges and myprivileges:
38
- has_permission = getattr(privileges, permission, False)
39
- has_my_permission = getattr(myprivileges, permission, False)
40
- if has_permission and has_my_permission:
41
- is_admin = True
42
- else:
43
- msg = ""
44
- if not has_permission and not has_my_permission:msg = f" Neither you nor I "
45
- elif not has_permission:msg = f" You don't"
46
- elif not has_my_permission:msg = f"❌ I don't"
47
- msg += f" have the required permission: `{permission}`."
48
- return await client.send_alert(message=message,text=msg)
49
- else:is_admin = True
50
- else:
51
- if alert:
52
- return await client.send_alert(message=message,text="❌ This command can only be used in groups.")
53
-
54
- authorized = user.id == OWNER or (sudo and user.id in client.sudo_users) or is_admin
55
- if react and isinstance(message, Message):
56
- try:await message.react(react_emoji)
57
- except:pass
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
- logger.info(f"Authorized user {user.id} executing {func.__name__}")
69
- await func(client, message)
70
- if delete_command:
71
- try:await delete(client, message.chat.id, message.id, timeout=5)
72
- except:pass
73
- except Exception as e:
74
- logger.error(f"Error in {func.__name__}: {e}")
75
- return
76
- return wrapper
77
- return decorator
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: d4rktg
3
- Version: 0.5.2
3
+ Version: 0.5.4
4
4
  Summary: A module for create with easy and fast
5
5
  Author: D4rkShell
6
6
  Author-email: premiumqtrst@gmail.com
@@ -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=zQgo3NTofTMgDNV2YE-VDbJyq05ajJetuimfd7kR2zQ,9015
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=uOF0bJacA7Lv944I4qHLtC-vKrgs7B7QFfmnKRfSVzw,325
13
- d4rk/Utils/_decorators.py,sha256=G5gGayvcpZRRVo6ondbRqQYDN4yVczlEdSHwaOQ_TLI,4145
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=jMFTG0eLcL3RVQZrgdSpKhLLus0Nc1WZFgJCET5Fdaw,2100
19
+ d4rk/Utils/_round.py,sha256=8mWNKfCSlN8-ClcG8MG1NydyDH3trGInFwV-Ede2bjA,3425
20
20
  d4rk/Utils/_terminal.py,sha256=Anu4OcffY3v6LMOrCskP1cHrJIliomo1Hjownbhh2sQ,125
21
- d4rktg-0.5.2.dist-info/METADATA,sha256=FlotNejt4GX6EIWcQb68jZBehFZ9-JwU-RgvCHsQUrM,652
22
- d4rktg-0.5.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- d4rktg-0.5.2.dist-info/top_level.txt,sha256=qs1qTnKWImmGi7E0FoJS0OAEOHoVZA9vHRS3Pm6ncAo,5
24
- d4rktg-0.5.2.dist-info/RECORD,,
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