2121
2222# --- Helper ---
2323async def get_account_id_from_client (client ) -> int | None :
24- return next ((acc_id for acc_id , c in ACTIVE_CLIENTS .items () if c == client ), None )
24+ # Access the override property directly
25+ return client .current_account_id if hasattr (client , 'current_account_id' ) else None
2526
2627# --- Module Management ---
2728async def load_account_modules (account_id : int , client_instance : TelegramClient , current_help_info : Dict [str , str ]):
@@ -75,7 +76,7 @@ async def list_accounts_handler(event: events.NewMessage.Event):
7576
7677async def add_account_handler (event : events .NewMessage .Event ):
7778 account_name : str = event .pattern_match .group (1 )
78- session_file : str = f"temp_add_{ account_name } .session"
79+ session_file_path : str = f"temp_add_{ account_name } .session"
7980 temp_client : Optional [TelegramClient ] = None
8081
8182 try :
@@ -86,7 +87,7 @@ async def add_account_handler(event: events.NewMessage.Event):
8687 api_hash_resp = await conv .get_response (); api_hash = api_hash_resp .text .strip ()
8788
8889 await conv .send_message (await event .client .get_string ("verifying_creds" ))
89- temp_client = TelegramClient (SQLiteSession (session_file ), int (api_id ), api_hash )
90+ temp_client = TelegramClient (SQLiteSession (session_file_path ), int (api_id ), api_hash )
9091
9192 await temp_client .connect ()
9293 if not await temp_client .is_user_authorized ():
@@ -141,23 +142,13 @@ async def add_account_handler(event: events.NewMessage.Event):
141142 return
142143
143144 # Now extract session data and save it
144- reader_session = SQLiteSession (session_file )
145- reader_session .load ()
146-
147- update_state = reader_session .get_update_state (0 )
148- pts , qts , date_ts , seq , _ = (None , None , None , None , None )
149- if update_state :
150- pts , qts , date_ts , seq , _ = update_state
151-
145+ with open (session_file_path , 'rb' ) as f :
146+ session_bytes : bytes = f .read ()
147+
152148 await db_manager .add_or_update_session (
153149 db ,
154150 account_id = new_acc .account_id ,
155- dc_id = reader_session .dc_id ,
156- server_address = reader_session .server_address ,
157- port = reader_session .port ,
158- auth_key_data = reader_session .auth_key .key ,
159- takeout_id = reader_session .takeout_id ,
160- pts = pts , qts = qts , date = date_ts , seq = seq
151+ session_file = session_bytes
161152 )
162153
163154 await conv .send_message (await event .client .get_string ("add_acc_success" , account_name = account_name ))
@@ -170,8 +161,8 @@ async def add_account_handler(event: events.NewMessage.Event):
170161 finally :
171162 if temp_client and temp_client .is_connected ():
172163 await temp_client .disconnect ()
173- if os .path .exists (session_file ):
174- os .remove (session_file )
164+ if os .path .exists (session_file_path ):
165+ os .remove (session_file_path )
175166
176167
177168async def delete_account_handler (event : events .NewMessage .Event ):
0 commit comments