Initial commit
This commit is contained in:
33
modules/menu/callbacks/create_session/callbacks.py
Normal file
33
modules/menu/callbacks/create_session/callbacks.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from sqlite3 import OperationalError
|
||||
from rich import print
|
||||
from modules.decorators.callback import async_callback
|
||||
from modules.client import GeneratedClient
|
||||
from modules.config import sessions
|
||||
from modules.config.models import SessionConfig
|
||||
|
||||
|
||||
@async_callback
|
||||
async def create_session_callback():
|
||||
session_name = input('New session name: ')
|
||||
while session_name in sessions.keys():
|
||||
session_name = input('Session with this name is already saved. Try another name: ')
|
||||
|
||||
try:
|
||||
await (client := GeneratedClient(name=session_name)).start()
|
||||
sessions[session_name] = SessionConfig(
|
||||
id=client.me.id,
|
||||
phone=client.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 {session_name}...')
|
||||
input()
|
||||
|
||||
except OperationalError:
|
||||
print('[red]Cannot create session file.[/] Try using different name...')
|
||||
input()
|
||||
|
||||
except Exception as e:
|
||||
print(f'[red]Error:[/] {e}...')
|
||||
input()
|
||||
return
|
||||
Reference in New Issue
Block a user