Skip to content

Commit b7a3834

Browse files
committed
feat: moved to temporal sessions
1 parent 995b4fa commit b7a3834

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

userbot/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import asyncio
22
import logging
33
import sys
4+
import tempfile
45
from typing import Dict, Optional, Any, List
56

67
from faker import Faker
78
from telethon import TelegramClient as TelethonTelegramClient, events
9+
from telethon.sessions import SQLiteSession
810
from telethon.tl.functions.channels import JoinChannelRequest
911
from telethon.errors.rpcerrorlist import UserAlreadyParticipantError
1012
from python_socks import ProxyType
1113

1214
from userbot.src.config import API_ID, API_HASH, LOG_LEVEL
1315
from userbot.src.db.session import initialize_database, get_db
14-
from userbot.src.db.models import Account, Session
15-
from userbot.src.memory_session import MemorySession
16+
from userbot.src.db.models import Account
1617
from userbot.src.encrypt import encryption_manager
1718
import userbot.src.db_manager as db_manager
1819
from userbot.src.log_handler import DBLogHandler
@@ -148,7 +149,16 @@ async def manage_clients() -> None:
148149

149150
try:
150151
decrypted_session_bytes: bytes = encryption_manager.decrypt(account.session.session_file)
151-
session_instance = MemorySession(decrypted_session_bytes)
152+
153+
# Create a temporary file to hold the session for Telethon
154+
# delete=False ensures the file is not deleted when the 'with' block exits.
155+
# It will be cleaned up automatically when the Docker container stops.
156+
with tempfile.NamedTemporaryFile(suffix=".session", delete=False) as tmp:
157+
tmp.write(decrypted_session_bytes)
158+
session_path: str = tmp.name
159+
160+
session_instance = SQLiteSession(session_path)
161+
152162
except Exception as e:
153163
logger.error(f"Could not decrypt or load session for '{account.account_name}'. Skipping. Error: {e}")
154164
continue

0 commit comments

Comments
 (0)