patch 2dc409973eb2934cb273a0707b662b85959cf03d
Author: E. Bosch <presidev@AT@gmail.com>
Date: Thu Jan 28 00:13:48 CET 2021
* telegram: Replace telegram_client.start() with telegram_client.connect()
This will allow to set the verification code (if necessary) from IRC
diff -rN -u old-irgramd/irgramd new-irgramd/irgramd
--- old-irgramd/irgramd 2024-11-22 22:30:49.753650189 +0100
+++ new-irgramd/irgramd 2024-11-22 22:30:49.753650189 +0100
@@ -2,8 +2,8 @@
import logging
import os
+import asyncio
-import tornado.ioloop
import tornado.options
import tornado.tcpserver
@@ -31,7 +31,7 @@
async def handle_stream(self, stream, address):
await self.irc_handler.run(stream, address)
- def run(self):
+ async def run(self):
self.listen(self.port, self.address)
self.logger.info('irgramd listening on %s:%s', self.address, self.port)
self.logger.info('Configuration Directory: %s', self.config_dir)
@@ -39,9 +39,7 @@
self.irc_handler = IRCHandler(self.config_dir)
self.tg_handler = TelegramHandler(self.irc_handler, self.config_dir)
self.irc_handler.set_telegram(self.tg_handler)
- self.tg_handler.initialize_telegram()
-
- tornado.ioloop.IOLoop.current().start()
+ await self.tg_handler.initialize_telegram()
# Main Execution
@@ -54,4 +52,5 @@
options = tornado.options.options.as_dict()
irc_server = IRCTelegramd(**options)
- irc_server.run()
+ asyncio.get_event_loop().run_until_complete(irc_server.run())
+ asyncio.get_event_loop().run_forever()
diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py
--- old-irgramd/telegram.py 2024-11-22 22:30:49.753650189 +0100
+++ new-irgramd/telegram.py 2024-11-22 22:30:49.753650189 +0100
@@ -23,8 +23,9 @@
self.logger = logging.getLogger()
self.config_dir = config_dir
self.irc = irc
+ self.authorized = False
- def initialize_telegram(self):
+ async def initialize_telegram(self):
# Setup media folder
self.telegram_media_dir = os.path.join(self.config_dir, 'media')
if not os.path.exists(self.telegram_media_dir):
@@ -53,9 +54,15 @@
self.telegram_client.add_event_handler(handler, event)
# Start Telegram client
- self.telegram_client.start()
+ await self.telegram_client.connect()
+
+ if await self.telegram_client.is_user_authorized():
+ self.authorized = True
+ await self.init_mapping()
+
+ async def init_mapping(self):
# Update IRC <-> Telegram mapping
- for dialog in self.telegram_client.iter_dialogs():
+ async for dialog in self.telegram_client.iter_dialogs():
chat = dialog.entity
if isinstance(chat, telethon.types.User):
user = self.get_telegram_nick(chat)