|
1 | 1 | import asyncio |
2 | 2 | import logging |
3 | 3 | import sys |
| 4 | +import tempfile |
4 | 5 | from typing import Dict, Optional, Any, List |
5 | 6 |
|
6 | 7 | from faker import Faker |
7 | 8 | from telethon import TelegramClient as TelethonTelegramClient, events |
| 9 | +from telethon.sessions import SQLiteSession |
8 | 10 | from telethon.tl.functions.channels import JoinChannelRequest |
9 | 11 | from telethon.errors.rpcerrorlist import UserAlreadyParticipantError |
10 | 12 | from python_socks import ProxyType |
11 | 13 |
|
12 | 14 | from userbot.src.config import API_ID, API_HASH, LOG_LEVEL |
13 | 15 | 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 |
16 | 17 | from userbot.src.encrypt import encryption_manager |
17 | 18 | import userbot.src.db_manager as db_manager |
18 | 19 | from userbot.src.log_handler import DBLogHandler |
@@ -148,7 +149,16 @@ async def manage_clients() -> None: |
148 | 149 |
|
149 | 150 | try: |
150 | 151 | 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 | + |
152 | 162 | except Exception as e: |
153 | 163 | logger.error(f"Could not decrypt or load session for '{account.account_name}'. Skipping. Error: {e}") |
154 | 164 | continue |
|
0 commit comments