Skip to content

Commit

Permalink
feat: add SESSION argument
Browse files Browse the repository at this point in the history
The SESSION argument accepts Telegram login credentials and is optional
and allows reusing the login credentials.
  • Loading branch information
malokhvii-eduard committed Oct 24, 2022
1 parent 91a8f93 commit 2d0804f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion raid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
from slack_sdk.webhook.async_client import AsyncWebhookClient
from telethon import TelegramClient, events
from telethon.sessions import StringSession
from telethon.tl.custom.message import Message

from raid.formatter import Locale, format_alert, load_translations
Expand Down Expand Up @@ -85,6 +86,9 @@ def main(
webhook_url: str = typer.Argument(
..., envvar="RAID_WEBHOOK_URL", help="Slack incoming webhook."
),
session: Optional[str] = typer.Argument(
None, envvar="RAID_SESSION", help="Telegram login credentials."
),
members: Optional[str] = typer.Option(
None,
help=(
Expand Down Expand Up @@ -184,8 +188,13 @@ def main(

load_translations(locale)

client = TelegramClient("raid", api_id, api_hash, auto_reconnect=True)
client = TelegramClient(
StringSession(session), api_id, api_hash, auto_reconnect=True
)
with client:
if session is None:
print(f"\n{client.session.save()}")

logger.info("client.connected", api_id=api_id, chat_id=chat_id)

client.add_event_handler(
Expand Down

0 comments on commit 2d0804f

Please sign in to comment.