Add StringSession support and generator
This commit is contained in:
42
scripts/generate-session-string.py
Normal file
42
scripts/generate-session-string.py
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate a Telethon StringSession for OverUB.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
from getpass import getpass
|
||||
|
||||
from telethon import TelegramClient
|
||||
from telethon.sessions import StringSession
|
||||
|
||||
|
||||
async def generate() -> None:
|
||||
api_id = os.getenv("OVERUB_API_ID") or os.getenv("API_ID")
|
||||
api_hash = os.getenv("OVERUB_API_HASH") or os.getenv("API_HASH")
|
||||
if not api_id or not api_hash:
|
||||
print("API_ID/API_HASH required (set OVERUB_API_ID/OVERUB_API_HASH or API_ID/API_HASH).")
|
||||
return
|
||||
try:
|
||||
api_id = int(api_id)
|
||||
except ValueError:
|
||||
print("API_ID must be an integer")
|
||||
return
|
||||
|
||||
print("Starting session generation. You will be prompted to log in.")
|
||||
client = TelegramClient(StringSession(), api_id, api_hash)
|
||||
await client.start()
|
||||
session_string = client.session.save()
|
||||
await client.disconnect()
|
||||
|
||||
print("\nSession string:")
|
||||
print(session_string)
|
||||
print("\nSet this in config/config.yml as bot.session_string or in env OVERUB_SESSION_STRING.")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
asyncio.run(generate())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user