d4rktg 0.4.9__py3-none-any.whl → 0.5.1__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/Utils/_round.py CHANGED
@@ -1,39 +1,54 @@
1
1
  from functools import wraps
2
2
  from pyrogram.types import Message
3
+ import asyncio
3
4
 
4
5
  # Track last bot index per chat
5
6
  last_index_per_chat = {}
6
- # Track all bot IDs dynamically
7
- active_bot_ids = []
7
+ # Track bot order per chat
8
+ bot_order_per_chat = {}
9
+ # Track messages already responded to: chat_id -> set of message_ids
10
+ responded_messages = {}
11
+ # Lock per chat to prevent race conditions
12
+ chat_locks = {}
8
13
 
9
14
  def round_robin():
10
15
  def decorator(func):
11
16
  @wraps(func)
12
17
  async def wrapper(client, message: Message, *args, **kwargs):
13
18
  chat_id = message.chat.id
19
+ msg_id = message.id
14
20
 
15
21
  # Private chats: all bots respond
16
22
  if message.chat.type.name.lower() == "private":
17
23
  return await func(client, message, *args, **kwargs)
18
24
 
19
- # Add bot ID to active list dynamically
20
- if client.me.id not in active_bot_ids:
21
- active_bot_ids.append(client.me.id)
22
-
23
- # Initialize last_index for this chat
24
- if chat_id not in last_index_per_chat:
25
+ # Initialize tracking for this chat
26
+ if chat_id not in bot_order_per_chat:
27
+ bot_order_per_chat[chat_id] = [client.me.id]
25
28
  last_index_per_chat[chat_id] = 0
26
-
27
- current_index = last_index_per_chat[chat_id]
28
- selected_bot_id = active_bot_ids[current_index]
29
-
30
- # Only the selected bot responds
31
- if client.me.id == selected_bot_id:
32
- result = await func(client, message, *args, **kwargs)
33
-
34
- # Rotate to next bot index
35
- last_index_per_chat[chat_id] = (current_index + 1) % len(active_bot_ids)
36
- return result
29
+ responded_messages[chat_id] = set()
30
+ chat_locks[chat_id] = asyncio.Lock()
31
+
32
+ # Add new bot if not in the chat
33
+ if client.me.id not in bot_order_per_chat[chat_id]:
34
+ bot_order_per_chat[chat_id].append(client.me.id)
35
+
36
+ async with chat_locks[chat_id]:
37
+ # Skip if message already responded
38
+ if msg_id in responded_messages[chat_id]:
39
+ return
40
+
41
+ # Decide which bot should respond
42
+ current_index = last_index_per_chat[chat_id]
43
+ selected_bot_id = bot_order_per_chat[chat_id][current_index]
44
+
45
+ if client.me.id == selected_bot_id:
46
+ result = await func(client, message, *args, **kwargs)
47
+ # Mark message as responded
48
+ responded_messages[chat_id].add(msg_id)
49
+ # Rotate for next message
50
+ last_index_per_chat[chat_id] = (current_index + 1) % len(bot_order_per_chat[chat_id])
51
+ return result
37
52
 
38
53
  return wrapper
39
- return decorator
54
+ return decorator
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: d4rktg
3
- Version: 0.4.9
3
+ Version: 0.5.1
4
4
  Summary: A module for create with easy and fast
5
5
  Author: D4rkShell
6
6
  Author-email: premiumqtrst@gmail.com
@@ -16,9 +16,9 @@ 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=PSvQGViHXiWX7Ly7MX-p0HlxKdIswngqWeowFTgWQcU,1356
19
+ d4rk/Utils/_round.py,sha256=jMFTG0eLcL3RVQZrgdSpKhLLus0Nc1WZFgJCET5Fdaw,2100
20
20
  d4rk/Utils/_terminal.py,sha256=Anu4OcffY3v6LMOrCskP1cHrJIliomo1Hjownbhh2sQ,125
21
- d4rktg-0.4.9.dist-info/METADATA,sha256=OgP5aTWAzsyOJbUudUI_ylg3iXz2QB3DolusW_cNdb0,652
22
- d4rktg-0.4.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- d4rktg-0.4.9.dist-info/top_level.txt,sha256=qs1qTnKWImmGi7E0FoJS0OAEOHoVZA9vHRS3Pm6ncAo,5
24
- d4rktg-0.4.9.dist-info/RECORD,,
21
+ d4rktg-0.5.1.dist-info/METADATA,sha256=aSUzke8cuqx_rrCsIEPw30LDd4xKFnLgWJ62L8htUz0,652
22
+ d4rktg-0.5.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ d4rktg-0.5.1.dist-info/top_level.txt,sha256=qs1qTnKWImmGi7E0FoJS0OAEOHoVZA9vHRS3Pm6ncAo,5
24
+ d4rktg-0.5.1.dist-info/RECORD,,
File without changes