Skip to content

Commit 995b4fa

Browse files
committed
fix: kwargs
1 parent 79f1fac commit 995b4fa

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

userbot/__init__.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ def _generate_random_device() -> Dict[str, str]:
3434

3535
class TelegramClient(TelethonTelegramClient):
3636
def __init__(self, *args, **kwargs):
37+
# Pop the custom argument before it's passed to the parent constructor
38+
self.account_id: Optional[int] = kwargs.pop('account_id', None)
3739
super().__init__(*args, **kwargs)
3840
self.lang_code: str = 'ru'
39-
self.account_id_override: Optional[int] = kwargs.get('account_id_override')
4041

4142
@property
4243
def current_account_id(self) -> Optional[int]:
43-
return self.account_id_override
44+
return self.account_id
4445

4546
async def get_string(self, key: str, module_name: Optional[str] = None, **kwargs) -> str:
4647
return translator.get_string(self.lang_code, key, module_name, **kwargs)
@@ -140,18 +141,17 @@ async def manage_clients() -> None:
140141
encryption_manager.decrypt(account.proxy_password).decode() if account.proxy_password else None
141142
)
142143

143-
session_instance: MemorySession
144-
if account.session and account.session.session_file:
145-
try:
146-
decrypted_session_bytes: bytes = encryption_manager.decrypt(account.session.session_file)
147-
session_instance = MemorySession(decrypted_session_bytes)
148-
except Exception as e:
149-
logger.error(f"Could not decrypt session for '{account.account_name}'. Skipping. Error: {e}")
150-
continue
151-
else:
152-
logger.warning(f"No session file found in DB for account '{account.account_name}'. A new login will be required if client is used directly.")
153-
session_instance = MemorySession(None)
144+
# Check for session existence before proceeding
145+
if not account.session or not account.session.session_file:
146+
logger.error(f"Session data is missing in the database for account '{account.account_name}'. Skipping.")
147+
continue
154148

149+
try:
150+
decrypted_session_bytes: bytes = encryption_manager.decrypt(account.session.session_file)
151+
session_instance = MemorySession(decrypted_session_bytes)
152+
except Exception as e:
153+
logger.error(f"Could not decrypt or load session for '{account.account_name}'. Skipping. Error: {e}")
154+
continue
155155

156156
new_client: TelegramClient = TelegramClient(
157157
session=session_instance,
@@ -161,7 +161,7 @@ async def manage_clients() -> None:
161161
system_version=account.system_version,
162162
app_version=account.app_version,
163163
proxy=proxy_details,
164-
account_id_override=account.account_id
164+
account_id=account.account_id # Pass custom arg here
165165
)
166166
ACTIVE_CLIENTS[account.account_id] = new_client
167167
tasks.append(start_individual_client(new_client, account))

userbot/src/core_handlers.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@
2020
logger: logging.Logger = logging.getLogger(__name__)
2121

2222
# --- Helper ---
23-
async def get_account_id_from_client(client) -> int | None:
24-
# Access the override property directly
25-
return client.current_account_id if hasattr(client, 'current_account_id') else None
23+
async def get_account_id_from_client(client: TelegramClient) -> Optional[int]:
24+
"""
25+
Safely retrieves the account_id associated with a client instance.
26+
27+
Args:
28+
client (TelegramClient): The client instance.
29+
30+
Returns:
31+
Optional[int]: The account ID if available, otherwise None.
32+
"""
33+
return client.current_account_id
2634

2735
# --- Module Management ---
2836
async def load_account_modules(account_id: int, client_instance: TelegramClient, current_help_info: Dict[str, str]):

0 commit comments

Comments
 (0)