patch 8d22777b1339caf300a5b2e9b76f7d791ff0ec76
Author: E. Bosch <presidev@AT@gmail.com>
Date: Wed Feb 16 23:22:04 CET 2022
* telegram: Add login code support entered by console during authorization
check, add phone number option in config, required by login code
diff -rN -u old-irgramd/irgramd new-irgramd/irgramd
--- old-irgramd/irgramd 2024-11-22 22:09:04.031715806 +0100
+++ new-irgramd/irgramd 2024-11-22 22:09:04.031715806 +0100
@@ -68,6 +68,7 @@
tornado.options.define('media_url', default=None, metavar='BASE_URL', help='Base URL for media files, should be configured in the external (to irgramd) webserver')
tornado.options.define('pam', default=False, help='Use PAM for IRC authentication, if not set you should set `irc_password`')
tornado.options.define('pam_group', default=None, metavar='GROUP', help='Unix group allowed if `pam` enabled, if empty any user is allowed')
+ tornado.options.define('phone', default=None, metavar='PHONE_NUMBER', help='Phone number associated with the Telegram account to receive the authorization codes if necessary')
tornado.options.define('port', default=None, metavar='PORT', help='Port to listen on. (default 6667, default with TLS 6697)')
tornado.options.define('tls', default=False, help='Use TLS/SSL encrypted connection for IRC server')
tornado.options.define('tls_cert', default=None, metavar='CERTFILE', help='IRC server certificate chain for TLS/SSL, also can contain private key if not defined with `tls_key`')
diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py
--- old-irgramd/telegram.py 2024-11-22 22:09:04.031715806 +0100
+++ new-irgramd/telegram.py 2024-11-22 22:09:04.031715806 +0100
@@ -3,6 +3,7 @@
import os
import datetime
import re
+import aioconsole
import telethon
from telethon import types as tgty
@@ -21,6 +22,7 @@
self.media_url = settings['media_url']
self.api_id = settings['api_id']
self.api_hash = settings['api_hash']
+ self.phone = settings['phone']
self.media_cn = 0
self.irc = irc
self.authorized = False
@@ -60,9 +62,19 @@
# Start Telegram client
await self.telegram_client.connect()
- if await self.telegram_client.is_user_authorized():
- self.authorized = True
- await self.init_mapping()
+ while not await self.telegram_client.is_user_authorized():
+ self.logger.info('Telegram account not authorized, you must provide the Login code '
+ 'that Telegram will sent you via SMS or another connected client')
+ await self.telegram_client.send_code_request(self.phone)
+ code = await aioconsole.ainput('Login code: ')
+ try:
+ await self.telegram_client.sign_in(code=code)
+ except:
+ pass
+
+ self.logger.info('Telegram account authorized')
+ self.authorized = True
+ await self.init_mapping()
async def init_mapping(self):
# Update IRC <-> Telegram mapping