service: Add code command, add ask_code option
patch a9bce1e704e2e0a7c711e4b984e87b2919384554
Author: E. Bosch <presidev@AT@gmail.com>
Date: Tue Mar 8 22:58:55 CET 2022
* service: Add code command, add ask_code option
hunk ./irc.py 111
+ self.service = service(self.conf, self.tg)
hunk ./irc.py 146
- self.service = service()
hunk ./irc.py 383
- reply = self.service.parse_command(message)
+ reply = await self.service.parse_command(message)
hunk ./irc.py 418
+ await self.check_telegram_auth(user)
hunk ./irc.py 507
+ async def check_telegram_auth(self, user):
+ if not self.tg.authorized and not self.tg.ask_code:
+ for line in (
+ '----',
+ 'Your Telegram account is not authorized yet,',
+ 'you must supply the code that Telegram sent to your phone',
+ 'or another client that is currently connected',
+ 'use /msg {} code <code>'.format(self.service_user.irc_nick),
+ 'e.g. /msg {} code 12345'.format(self.service_user.irc_nick),
+ ):
+ await self.send_msg(self.service_user, user.irc_nick, line)
+
hunk ./irgramd 71
+ tornado.options.define('ask_code', default=False, help='Ask authentication code (sent by Telegram) in console instead of "code" service command in IRC')
hunk ./service.py 10
- def __init__(self):
+ def __init__(self, settings, telegram):
hunk ./service.py 13
+ 'code': (self.handle_command_code, 1, 1),
hunk ./service.py 16
-
- def parse_command(self, line):
+ self.ask_code = settings['ask_code']
+ self.tg = telegram
+
+ async def parse_command(self, line):
hunk ./service.py 29
- reply = handler(*words)
+ reply = await handler(*words)
hunk ./service.py 35
- def handle_command_help(self, help_command=None, help=None):
+ async def handle_command_code(self, code=None, help=None):
+ if not help:
+ if self.ask_code:
+ reply = ('Code will be asked on console',)
+ elif code.isdigit():
+ try:
+ await self.tg.telegram_client.sign_in(code=code)
+ except:
+ reply = ('Invalid code',)
+ else:
+ reply = ('Valid code', 'Telegram account authorized')
+ await self.tg.continue_auth()
+ else: # not isdigit
+ reply = ('Code must be numeric',)
+
+ else: # HELP.brief or HELP.desc (first line)
+ reply = (' code Enter authorization code',)
+ if help == HELP.desc: # rest of HELP.desc
+ reply += \
+ (
+ ' code <code>',
+ 'Enter authorization code sent by Telegram to the phone or to',
+ 'another client connected.',
+ 'This authorization code usually is only needed the first time',
+ 'that irgramd connects to Telegram with a given account.',
+ )
+ return reply
+
+ async def handle_command_help(self, help_command=None, help=None):
hunk ./service.py 79
- help_text += handler(help=HELP.brief)
+ help_text += await handler(help=HELP.brief)
hunk ./service.py 89
- help_text += handler(help=HELP.desc)
+ help_text += await handler(help=HELP.desc)
hunk ./telegram.py 45
+ self.ask_code = settings['ask_code']
hunk ./telegram.py 93
- self.logger.info('Telegram account not authorized, you must provide the Login code '
- 'that Telegram will sent you via SMS or another connected client')
+ self.logger.info('Telegram account not authorized')
hunk ./telegram.py 95
+ if not self.ask_code:
+ return
+ self.logger.info('You must provide the Login code that Telegram will '
+ 'sent you via SMS or another connected client')
hunk ./telegram.py 105
+ await self.continue_auth()
+
+ async def continue_auth(self):