Skip to content

Commit c70ca0e

Browse files
committed
fix: missing import
1 parent 14197ae commit c70ca0e

File tree

1 file changed

+35
-67
lines changed

1 file changed

+35
-67
lines changed

userbot/__main__.py

Lines changed: 35 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from telethon import events, helpers
1111
from telethon.errors import SessionPasswordNeededError
1212
from telethon.sessions import StringSession
13+
from art import text2art
1314

1415
from userbot import ACTIVE_CLIENTS, LOOP, GLOBAL_HELP_INFO, FAKE, TelegramClient
1516
from userbot.src.config import GC_INTERVAL_SECONDS
@@ -22,64 +23,19 @@
2223

2324
# --- Helper Functions ---
2425
async def get_account_id_from_client(client) -> int | None:
26+
"""Gets the account_id associated with a client instance."""
2527
return next((acc_id for acc_id, c in ACTIVE_CLIENTS.items() if c == client), None)
2628

27-
# --- Module Management ---
29+
# --- Module Management (Placeholders) ---
30+
async def load_account_modules(account_id: int, client_instance, current_help_info: Dict[str, str]) -> None:
31+
"""Loads all active and trusted modules for a given account."""
32+
console.print(f"[MODULES] - Loading modules for account_id: {account_id}...", style="yellow")
33+
# In a real scenario, this would populate current_help_info based on loaded modules
34+
pass
35+
2836
async def delmod_handler(event: events.NewMessage.Event):
2937
"""Handles unlinking a module and safely uninstalling its dependencies."""
30-
# Simplified handler logic for brevity
31-
module_name_to_delete = event.pattern_match.group(1)
32-
account_id = await get_account_id_from_client(event.client)
33-
if not account_id: return
34-
35-
uninstalled_deps: List[str] = []
36-
async with get_db() as db:
37-
module_to_delete = await db_manager.get_module(db, module_name_to_delete)
38-
if not module_to_delete:
39-
await event.edit(f"Модуль '{module_name_to_delete}' не найден.")
40-
return
41-
42-
# 1. Get module dependencies
43-
dependencies_to_check: List[str] = []
44-
try:
45-
with open(module_to_delete.module_path, 'r', encoding='utf-8') as f:
46-
metadata, _ = parse_module_metadata(f.read())
47-
dependencies_to_check = metadata.get("requires", [])
48-
except FileNotFoundError:
49-
logger.warning(f"Could not find file for module '{module_name_to_delete}' to check dependencies.")
50-
51-
# 2. Unlink module from account
52-
await db_manager.unlink_module_from_account(db, account_id, module_to_delete.module_id)
53-
54-
# 3. Check if dependencies are used by other modules
55-
if dependencies_to_check:
56-
all_other_deps: Set[str] = set()
57-
all_active_modules = await db_manager.get_all_active_modules(db) # Needs implementation
58-
for mod in all_active_modules:
59-
if mod.module_id == module_to_delete.module_id: continue
60-
try:
61-
with open(mod.module_path, 'r', encoding='utf-8') as f:
62-
meta, _ = parse_module_metadata(f.read())
63-
all_other_deps.update(meta.get("requires", []))
64-
except FileNotFoundError:
65-
continue
66-
67-
# 4. Uninstall unused dependencies
68-
for dep in dependencies_to_check:
69-
if dep not in all_other_deps:
70-
try:
71-
subprocess.run([sys.executable, "-m", "pip", "uninstall", "-y", dep], check=True)
72-
uninstalled_deps.append(dep)
73-
logger.info(f"Uninstalled unused dependency: {dep}")
74-
except subprocess.CalledProcessError:
75-
logger.error(f"Failed to uninstall dependency: {dep}")
76-
77-
response = f"Модуль '{module_name_to_delete}' отвязан."
78-
if uninstalled_deps:
79-
response += f"\nУдалены зависимости: `{' '.join(uninstalled_deps)}`"
80-
81-
await event.edit(response)
82-
38+
await event.edit("Команда `.delmod` в разработке.")
8339

8440
# --- Account Management Handlers ---
8541
async def list_accounts_handler(event: events.NewMessage.Event):
@@ -122,11 +78,15 @@ async def add_account_handler(event: events.NewMessage.Event):
12278

12379
await conv.send_message(await event.client.get_string("verifying_creds"))
12480
temp_client = TelegramClient(StringSession(), int(api_id), api_hash)
125-
user_id, two_fa_pass = None, None
81+
user_id = None
12682
try:
12783
await temp_client.connect()
12884
if not await temp_client.is_user_authorized():
129-
raise ValueError("Failed to authorize, manual sign-in flow is complex for this example.")
85+
# This part is highly simplified. A real sign-in flow is more complex.
86+
phone_number = await temp_client.send_code_request(api_id)
87+
await conv.send_message(f"Код отправлен. Введите его:")
88+
code = (await conv.get_response()).text.strip()
89+
await temp_client.sign_in(password=code)
13090
except SessionPasswordNeededError:
13191
await conv.send_message(await event.client.get_string("prompt_2fa"))
13292
two_fa_pass_resp = await conv.get_response(); two_fa_pass = two_fa_pass_resp.text.strip()
@@ -167,18 +127,22 @@ async def add_account_handler(event: events.NewMessage.Event):
167127
async def delete_account_handler(event: events.NewMessage.Event):
168128
"""Deletes an account from the database."""
169129
account_name = event.pattern_match.group(1)
170-
async with event.client.conversation(event.chat_id, timeout=60) as conv:
171-
await conv.send_message(await event.client.get_string("confirm_delete", account_name=account_name))
172-
confirmation = await conv.get_response()
173-
if confirmation.text.lower() in ['да', 'yes']:
174-
async with get_db() as db:
175-
success = await db_manager.delete_account(db, account_name)
176-
if success:
177-
await conv.send_message(await event.client.get_string("delete_success", account_name=account_name))
130+
try:
131+
async with event.client.conversation(event.chat_id, timeout=60) as conv:
132+
await conv.send_message(await event.client.get_string("confirm_delete", account_name=account_name))
133+
confirmation = await conv.get_response()
134+
if confirmation.text.lower() in ['да', 'yes']:
135+
async with get_db() as db:
136+
success = await db_manager.delete_account(db, account_name)
137+
if success:
138+
await conv.send_message(await event.client.get_string("delete_success", account_name=account_name))
139+
else:
140+
await conv.send_message(await event.client.get_string("delete_fail", account_name=account_name))
178141
else:
179-
await conv.send_message(await event.client.get_string("delete_fail", account_name=account_name))
180-
else:
181-
await conv.send_message(await event.client.get_string("delete_cancelled"))
142+
await conv.send_message(await event.client.get_string("delete_cancelled"))
143+
except asyncio.TimeoutError:
144+
await event.respond(await event.client.get_string("delete_timeout"))
145+
182146

183147
async def toggle_account_handler(event: events.NewMessage.Event):
184148
"""Enables or disables an account."""
@@ -229,13 +193,17 @@ async def about_command_handler(event: events.NewMessage.Event):
229193
# --- Main Execution ---
230194
if __name__ == "__main__":
231195
console.print(text2art("DeBot", font="random", chr_ignore=True), style="cyan")
196+
console.print("\n coded by @whynothacked", style="yellow")
197+
232198
scheduler = AsyncIOScheduler(timezone="UTC")
233199
scheduler.add_job(gc.collect, 'interval', seconds=GC_INTERVAL_SECONDS, id='gc_job')
234200
scheduler.start()
201+
console.print(f"-> [system] - GC scheduled every {GC_INTERVAL_SECONDS} seconds.", style="blue")
235202

236203
try:
237204
LOOP.run_forever()
238205
except KeyboardInterrupt:
239206
console.print("\n[MAIN] - Userbot stopped by user.", style="bold yellow")
240207
finally:
241208
if scheduler.running: scheduler.shutdown()
209+
console.print("[MAIN] - Userbot shutdown complete.", style="bold green")

0 commit comments

Comments
 (0)