d4rktg 0.5.0__py3-none-any.whl → 0.5.2__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 +23 -7
- d4rk/Utils/_round.py +21 -16
- {d4rktg-0.5.0.dist-info → d4rktg-0.5.2.dist-info}/METADATA +1 -1
- {d4rktg-0.5.0.dist-info → d4rktg-0.5.2.dist-info}/RECORD +6 -6
- {d4rktg-0.5.0.dist-info → d4rktg-0.5.2.dist-info}/WHEEL +0 -0
- {d4rktg-0.5.0.dist-info → d4rktg-0.5.2.dist-info}/top_level.txt +0 -0
d4rk/Handlers/_bot.py
CHANGED
@@ -12,6 +12,9 @@ from pyrogram.errors.exceptions.bad_request_400 import AccessTokenExpired
|
|
12
12
|
|
13
13
|
from d4rk.Logs import setup_logger
|
14
14
|
|
15
|
+
logs_sent = False
|
16
|
+
logs_lock = asyncio.Lock()
|
17
|
+
|
15
18
|
logger = setup_logger(__name__)
|
16
19
|
|
17
20
|
class BotManager(Client):
|
@@ -98,22 +101,35 @@ class BotManager(Client):
|
|
98
101
|
await self.setup_webserver()
|
99
102
|
|
100
103
|
async def powerdown(self, *args):
|
104
|
+
global logs_sent, logs_lock
|
101
105
|
logger.info("Initiating APP to stop...")
|
102
106
|
if self._rename:await super().set_bot_info(lang_code='en',name=self.app_name + " (Offline)")
|
103
107
|
self.stop_scheduler()
|
104
108
|
today = self.TZ_now.strftime("%Y-%m-%d")
|
105
109
|
if hasattr(self, '_web_runner') and self._web_runner:
|
106
110
|
await self.web_server.cleanup()
|
107
|
-
|
108
|
-
|
111
|
+
|
112
|
+
logger.info("Stopping bot client...")
|
113
|
+
if self._is_connected and self.LOGS:
|
109
114
|
try:
|
110
|
-
|
111
|
-
|
115
|
+
await self.send_message(chat_id=self.LOGS, text=f"{self._bot_info.mention} stopping...")
|
116
|
+
except Exception as e:
|
117
|
+
logger.error(f"Error sending stop message for {self._bot_info.first_name}: {e}")
|
118
|
+
|
119
|
+
async with logs_lock:
|
120
|
+
if not logs_sent and self._is_connected:
|
121
|
+
logs_sent = True
|
122
|
+
try:
|
112
123
|
await self.send_document(chat_id=self.LOGS, document=f"logs/log-{today}.txt")
|
113
|
-
|
124
|
+
logger.info("Log document sent successfully")
|
125
|
+
except Exception as e:
|
126
|
+
logger.error(f"Error sending log document: {e}")
|
127
|
+
|
128
|
+
if self._is_connected and self.LOGS:
|
129
|
+
try:
|
130
|
+
await self.send_message(chat_id=self.LOGS, text=f"{self._bot_info.mention} stopped successfully!")
|
114
131
|
except Exception as e:
|
115
|
-
logger.error(f"Error sending stop
|
116
|
-
logger.info(f"{self._bot_info.first_name} - @{self._bot_info.username} Stoped")
|
132
|
+
logger.error(f"Error sending stop confirmation for {self._bot_info.first_name}: {e}")
|
117
133
|
await super().stop()
|
118
134
|
sys.exit(0)
|
119
135
|
|
d4rk/Utils/_round.py
CHANGED
@@ -1,5 +1,6 @@
|
|
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 = {}
|
@@ -7,6 +8,8 @@ last_index_per_chat = {}
|
|
7
8
|
bot_order_per_chat = {}
|
8
9
|
# Track messages already responded to: chat_id -> set of message_ids
|
9
10
|
responded_messages = {}
|
11
|
+
# Lock per chat to prevent race conditions
|
12
|
+
chat_locks = {}
|
10
13
|
|
11
14
|
def round_robin():
|
12
15
|
def decorator(func):
|
@@ -24,26 +27,28 @@ def round_robin():
|
|
24
27
|
bot_order_per_chat[chat_id] = [client.me.id]
|
25
28
|
last_index_per_chat[chat_id] = 0
|
26
29
|
responded_messages[chat_id] = set()
|
30
|
+
chat_locks[chat_id] = asyncio.Lock()
|
27
31
|
|
28
|
-
#
|
29
|
-
if msg_id in responded_messages[chat_id]:
|
30
|
-
return
|
31
|
-
|
32
|
-
# Add new bots if not in the chat
|
32
|
+
# Add new bot if not in the chat
|
33
33
|
if client.me.id not in bot_order_per_chat[chat_id]:
|
34
34
|
bot_order_per_chat[chat_id].append(client.me.id)
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
47
52
|
|
48
53
|
return wrapper
|
49
54
|
return decorator
|
@@ -2,7 +2,7 @@ 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=zQgo3NTofTMgDNV2YE-VDbJyq05ajJetuimfd7kR2zQ,9015
|
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
|
@@ -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=
|
19
|
+
d4rk/Utils/_round.py,sha256=jMFTG0eLcL3RVQZrgdSpKhLLus0Nc1WZFgJCET5Fdaw,2100
|
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.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,,
|
File without changes
|
File without changes
|