continued work on rewrite

This commit is contained in:
2019-02-26 23:05:39 +01:00
parent 9588e61aa6
commit 7dd9ef67ad

View File

@@ -1,6 +1,6 @@
import re, sys, os, io, sqlite3, hashlib, time, datetime
import xml.etree.ElementTree as ET
import logging, traceback
import logging, traceback, pprint
from sleekxmpp.componentxmpp import ComponentXMPP
from sleekxmpp import Presence, Message
@@ -263,7 +263,7 @@ class XMPPTelegram(ComponentXMPP):
sys.exit(0)
class MessageHandler():
_unknown_command_handler = lambda self: "Unknown command, for a list send '!help'"
_unknown_command_handler = lambda self, self2: "Unknown command, for a list send '!help'"
_on_connect = lambda: None
def __init__(self, msg):
@@ -350,7 +350,7 @@ class XMPPTelegram(ComponentXMPP):
if len(hndl.arguments) != 1:
return "Wrong number of arguments"
phone_no = arguments[0]
phone_no = hndl.arguments[0]
hndl._update("Please wait...")
self.spawn_tg_client(hndl.jid, phone_no)
@@ -426,12 +426,20 @@ class XMPPTelegram(ComponentXMPP):
return "Dialogs reloadad"
def logout(hndl, self):
"""Deletes current Telegram session at Gateway"""
self.tg_connections[hndl.jid].log_out()
self.db_connection.execute("DELETE FROM accounts WHERE jid = ?", (hndl.jid,))
return 'Your Telegram session was deleted'
def add(self): #1 arg
result = self.tg_connections[jid].get_entity(parsed[1])
def add(hndl, self): #1 arg
"""Add contact by nickname or t.me link"""
if len(hndl.arguments) != 1:
return "Wrong number of arguments"
argument = hndl.arguments[0]
jid = hndl.jid
result = self.tg_connections[jid].get_entity(argument)
if type(result) == User:
tg_peer = InputPeerUser( result.id, result.access_hash )
result = self.tg_connections[jid].invoke( SendMessageRequest(tg_peer, 'Hello! I just want to add you in my contact list.', generate_random_long() ) )
@@ -444,8 +452,15 @@ class XMPPTelegram(ComponentXMPP):
self.tg_process_dialogs(jid)
def join(self): #1 arg
link = parsed[1].split('/') # https://t.me/joinchat/HrCmckx_SkMbSGFLhXCvSg
def join(hndl, self): #1 arg
"""Join conference via invite link"""
if len(hndl.arguments) != 1:
return "Wrong number of arguments"
argument = hndl.arguments[0]
jid = hndl.jid
link = argument.split('/') # https://t.me/joinchat/HrCmckx_SkMbSGFLhXCvSg
self.tg_connections[jid].invoke(ImportChatInviteRequest(link[4]))
time.sleep(1)
self.tg_process_dialogs(jid)
@@ -472,19 +487,23 @@ class XMPPTelegram(ComponentXMPP):
self.tg_process_dialogs(jid)
def username(self): #1 arg
"""Change your Telegram display name"""
username = parsed[1]
self.tg_connections[jid].invoke(UpdateUsernameRequest(username))
def name(self): #1 or 2 args
"""Change your Telegram display name"""
firstname = parsed[1]
lastname = parsed[2] if len(parsed) > 2 else None
self.tg_connections[jid].invoke(UpdateProfileRequest(first_name = firstname, last_name = lastname))
def about(self): #>0 args
"""Change your Telegram 'about' text"""
about = iq['body'][7:]
self.tg_connections[jid].invoke(UpdateProfileRequest(about = about))
def import_contact(self): #2 args
"""Add contact by phone number"""
phone = parsed[1]
firstname = parsed[2]
lastname = parsed[3] if len(parsed) > 3 else None
@@ -494,6 +513,7 @@ class XMPPTelegram(ComponentXMPP):
self.tg_process_dialogs(jid)
def roster(hndl, self):
"""Send Telegram contact list back, with JIDs"""
response = "Telegram chats:\n"
for jid,tid in self.contact_list[hndl.jid].items():
response += "{}: {}\n".format(tid, jid)