cleanup/bugfixes

This commit is contained in:
2019-03-10 17:05:59 +01:00
parent 5f2e2e517d
commit 09c69468a8
2 changed files with 9 additions and 2 deletions

View File

@@ -36,6 +36,8 @@ class CommandHandler():
"""nolist Show debug info"""
return pprint.pformat(self.__dict__)
#TODO: handle non-existant commands
#TODO: add end text
def help(self, *args, **kwargs):
"""List available commands"""
#taken from https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
@@ -112,13 +114,13 @@ class GateCommandHandler(CommandHandler):
gate.spawn_tg_client(self.jid, phone_no)
if gate.tg_connections[self.jid].is_user_authorized():
gate.send_presence(pto=jid, pfrom=gate.boundjid.bare, ptype='online', pstatus='connected')
# gate.send_presence(pto=jid, pfrom=gate.boundjid.bare, ptype='online', pstatus='connected') #already called in spawn_tg_client
return "You are already authenticated in Telegram"
else:
# remove old sessions for this JID #
gate.db_connection.execute("DELETE from accounts where jid = ?", (self.jid,))
gate.tg_connections[self.jid].send_code_request(phone_no)
gate._update('Gate is connected. Telegram should send SMS message to you.')
self._update('Gate is connected. Telegram should send SMS message to you.')
return 'Please enter one-time code via !code 12345.'
def code(self, gate):

View File

@@ -109,6 +109,9 @@ class XMPPTelegram(ComponentXMPP):
"""
jid = iq['from'].bare
if iq['type'] == 'normal':
raise XMPPError(text="Sorry, this type of message is not supported")
if iq['to'] == self.config['jid'] and iq['type'] == 'chat': # message to gateway
if iq['body'].startswith('!'):
self.process_command(iq)
@@ -161,6 +164,8 @@ class XMPPTelegram(ComponentXMPP):
result = None
# detect media
#TODO: fix
#TODO: implement OOB for images
if msg.startswith('http') and re.match(r'(?:http\:|https\:)?\/\/.*\.(?:' + self.config['media_external_formats'] + ')', msg):
urls = re.findall(r'(?:http\:|https\:)?\/\/.*\.(?:' + self.config['media_external_formats'] + ')', msg)
message = msg.replace(urls[0], '')