Loading all sessions from folder
This commit is contained in:
@@ -16,7 +16,7 @@ async def create_session_callback():
|
|||||||
await (client := GeneratedClient(name=session_name)).start()
|
await (client := GeneratedClient(name=session_name)).start()
|
||||||
sessions[session_name] = SessionConfig(
|
sessions[session_name] = SessionConfig(
|
||||||
id=client.me.id,
|
id=client.me.id,
|
||||||
phone=client.phone_number,
|
phone=client.me.phone_number,
|
||||||
profile_name=client.me.first_name + (f' {client.me.last_name}' if client.me.last_name else ''),
|
profile_name=client.me.first_name + (f' {client.me.last_name}' if client.me.last_name else ''),
|
||||||
username=client.me.username
|
username=client.me.username
|
||||||
).json()
|
).json()
|
||||||
@@ -27,8 +27,3 @@ async def create_session_callback():
|
|||||||
except OperationalError:
|
except OperationalError:
|
||||||
print('[red]Cannot create session file.[/] Try using different name...')
|
print('[red]Cannot create session file.[/] Try using different name...')
|
||||||
input()
|
input()
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f'[red]Error:[/] {e}...')
|
|
||||||
input()
|
|
||||||
return
|
|
||||||
|
|||||||
1
modules/menu/callbacks/load_sessions/__init__.py
Normal file
1
modules/menu/callbacks/load_sessions/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .callbacks import load_sessions_callback
|
||||||
37
modules/menu/callbacks/load_sessions/callbacks.py
Normal file
37
modules/menu/callbacks/load_sessions/callbacks.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
from modules.decorators.callback import async_callback
|
||||||
|
from modules.config import sessions
|
||||||
|
from modules.client import GeneratedClient
|
||||||
|
from modules.config.models import SessionConfig
|
||||||
|
from rich import print
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
@async_callback
|
||||||
|
async def load_sessions_callback():
|
||||||
|
if input('Do you really want to load all .session files that are not in database? '
|
||||||
|
'It may cause bans of your accounts, because logging to many sessions from one IP at once may seem'
|
||||||
|
'suspicious for Telegram (y/N) ') not in ['y', 'Y']:
|
||||||
|
return
|
||||||
|
print('Loading...')
|
||||||
|
loaded = 0
|
||||||
|
for file in os.listdir():
|
||||||
|
if not file.endswith('.session'):
|
||||||
|
continue
|
||||||
|
file = file.replace('.session', '')
|
||||||
|
if file not in sessions.keys():
|
||||||
|
try:
|
||||||
|
await (client := GeneratedClient(name=file)).start()
|
||||||
|
sessions[file] = SessionConfig(
|
||||||
|
id=client.me.id,
|
||||||
|
phone=client.me.phone_number,
|
||||||
|
profile_name=client.me.first_name + (f' {client.me.last_name}' if client.me.last_name else ''),
|
||||||
|
username=client.me.username
|
||||||
|
).json()
|
||||||
|
print(f'[green]Created[/] session {file}...')
|
||||||
|
await client.stop()
|
||||||
|
loaded += 1
|
||||||
|
except Exception as e:
|
||||||
|
print(f'[red]Error[/] loading {file} ({e}), skipping...')
|
||||||
|
|
||||||
|
print(f'[green]Created[/] {loaded} records...')
|
||||||
|
input()
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
from cursesmenu import CursesMenu
|
from cursesmenu import CursesMenu
|
||||||
from cursesmenu.items import FunctionItem
|
from cursesmenu.items import FunctionItem
|
||||||
from ...callbacks.overkill import overkill_callback
|
from ...callbacks.overkill import overkill_callback
|
||||||
|
from ...callbacks.load_sessions import load_sessions_callback
|
||||||
from ...dynamic import update
|
from ...dynamic import update
|
||||||
from ...dynamic import delete
|
from ...dynamic import delete
|
||||||
|
|
||||||
@@ -9,6 +10,7 @@ def get_items_list(menu: CursesMenu):
|
|||||||
_ = [
|
_ = [
|
||||||
update.get_submenu_item,
|
update.get_submenu_item,
|
||||||
delete.get_submenu_item,
|
delete.get_submenu_item,
|
||||||
lambda _: FunctionItem('Delete overkill sessions', function=overkill_callback)
|
lambda _: FunctionItem('Delete overkill sessions', function=overkill_callback),
|
||||||
|
lambda _: FunctionItem('Load new sessions in folder', function=load_sessions_callback)
|
||||||
]
|
]
|
||||||
return [x(menu) for x in _]
|
return [x(menu) for x in _]
|
||||||
|
|||||||
Reference in New Issue
Block a user