updated commands
This commit is contained in:
@@ -9,6 +9,7 @@ from xmpp_tg.utils import var_dump, display_tg_name, get_contact_jid, localtime
|
|||||||
|
|
||||||
class MessageHandler():
|
class MessageHandler():
|
||||||
_on_connect = lambda: None
|
_on_connect = lambda: None
|
||||||
|
_helptext = "Available Commands:"
|
||||||
|
|
||||||
def _unknown_command_handler(self, *args, **kwargs):
|
def _unknown_command_handler(self, *args, **kwargs):
|
||||||
return "Unknown command, for a list send !help"
|
return "Unknown command, for a list send !help"
|
||||||
@@ -34,7 +35,7 @@ class MessageHandler():
|
|||||||
xmpp.send_message(mto=self.replyto, mtype=self.type, mbody=text)
|
xmpp.send_message(mto=self.replyto, mtype=self.type, mbody=text)
|
||||||
|
|
||||||
def debug(self, *args, **kwargs):
|
def debug(self, *args, **kwargs):
|
||||||
"""Show debug info"""
|
"""nolistnolist Show debug info"""
|
||||||
return pprint.pformat(self.__dict__)
|
return pprint.pformat(self.__dict__)
|
||||||
|
|
||||||
def help(self, *args, **kwargs):
|
def help(self, *args, **kwargs):
|
||||||
@@ -66,13 +67,15 @@ class MessageHandler():
|
|||||||
return '\n'.join(trimmed)
|
return '\n'.join(trimmed)
|
||||||
|
|
||||||
if len(self.arguments) == 0:
|
if len(self.arguments) == 0:
|
||||||
methods = [func for func in dir(self) if not func.startswith("_") and callable(getattr(self, func))]
|
methods = [func for func in dir(self) if not func.startswith("_") and callable(getattr(self, func)) and not isinstance(func, Exception)]
|
||||||
reply = "Available commands:"
|
reply = self._helptext
|
||||||
for method in methods:
|
for method in methods:
|
||||||
docstring = getattr(self, method).__doc__
|
docstring = getattr(self, method).__doc__
|
||||||
if docstring is None:
|
if docstring is None:
|
||||||
docstring = "No description available"
|
docstring = "No description available"
|
||||||
reply += "\n"+method+" ("+docstring.split("\n")[0]+")"
|
if docstring.startswith("nolist "):
|
||||||
|
continue
|
||||||
|
reply += "\n!{command} - {doc}".format(method, docstring.split("\n")[0]
|
||||||
return reply
|
return reply
|
||||||
else:
|
else:
|
||||||
method = getattr(self,self.arguments[0])
|
method = getattr(self,self.arguments[0])
|
||||||
@@ -80,6 +83,8 @@ class MessageHandler():
|
|||||||
return reply
|
return reply
|
||||||
|
|
||||||
class GateMessageHandler(MessageHandler):
|
class GateMessageHandler(MessageHandler):
|
||||||
|
_helptext = "Available Gateway commands:"
|
||||||
|
|
||||||
def configure(hndl, self):
|
def configure(hndl, self):
|
||||||
"""Get config/set config options"""
|
"""Get config/set config options"""
|
||||||
config_exclude = ['jid', 'tg_phone']
|
config_exclude = ['jid', 'tg_phone']
|
||||||
@@ -119,6 +124,7 @@ class GateMessageHandler(MessageHandler):
|
|||||||
return 'Please enter one-time code via !code 12345.'
|
return 'Please enter one-time code via !code 12345.'
|
||||||
|
|
||||||
def code(hndl, self):
|
def code(hndl, self):
|
||||||
|
"""nolist Enter confirmation code"""
|
||||||
hndl._min_args(1)
|
hndl._min_args(1)
|
||||||
|
|
||||||
code = hndl.arguments[0]
|
code = hndl.arguments[0]
|
||||||
@@ -146,6 +152,7 @@ class GateMessageHandler(MessageHandler):
|
|||||||
return 'You are already authenticated. Please use !logout before new login.'
|
return 'You are already authenticated. Please use !logout before new login.'
|
||||||
|
|
||||||
def password(hndl, self):
|
def password(hndl, self):
|
||||||
|
"""nolist Enter password"""
|
||||||
hndl._min_args(1)
|
hndl._min_args(1)
|
||||||
|
|
||||||
password = hndl.arguments[1]
|
password = hndl.arguments[1]
|
||||||
@@ -167,14 +174,8 @@ class GateMessageHandler(MessageHandler):
|
|||||||
else:
|
else:
|
||||||
self.gate_reply_message(iq, 'You are already authenticated. Please use !logout before new login.')
|
self.gate_reply_message(iq, 'You are already authenticated. Please use !logout before new login.')
|
||||||
|
|
||||||
def list_sessions(hndl, self):
|
|
||||||
if not self.tg_connections[hndl.jid].is_user_authorized():
|
|
||||||
return "Error"
|
|
||||||
|
|
||||||
sessions = self.tg_connections[hndl.jid].invoke(GetAuthorizationsRequest())
|
|
||||||
return str(sessions)
|
|
||||||
|
|
||||||
def reload_dialogs(hndl, self):
|
def reload_dialogs(hndl, self):
|
||||||
|
"""Reload Telegram dialogs"""
|
||||||
if not self.tg_connections[hndl.jid].is_user_authorized():
|
if not self.tg_connections[hndl.jid].is_user_authorized():
|
||||||
return "Error"
|
return "Error"
|
||||||
|
|
||||||
@@ -287,7 +288,7 @@ class GateMessageHandler(MessageHandler):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
def oldhelp(hndl, self):
|
def oldhelp(hndl, self):
|
||||||
"""Old !help message"""
|
"""nolist Old !help message"""
|
||||||
return ('=== Available gateway commands ===:\n\n'
|
return ('=== Available gateway commands ===:\n\n'
|
||||||
'!help - Displays this text\n'
|
'!help - Displays this text\n'
|
||||||
'!login +123456789 - Initiates Telegram session\n'
|
'!login +123456789 - Initiates Telegram session\n'
|
||||||
@@ -316,6 +317,7 @@ class GateMessageHandler(MessageHandler):
|
|||||||
'!roster - Lists yout TG roster\n')
|
'!roster - Lists yout TG roster\n')
|
||||||
|
|
||||||
class ChatCommandHandler(MessageHandler):
|
class ChatCommandHandler(MessageHandler):
|
||||||
|
_helptext = "Available Userchat commands:"
|
||||||
|
|
||||||
def __init__(self, msg):
|
def __init__(self, msg):
|
||||||
super(ChatCommandHandler, self).__init__(msg)
|
super(ChatCommandHandler, self).__init__(msg)
|
||||||
@@ -324,16 +326,19 @@ class ChatCommandHandler(MessageHandler):
|
|||||||
self.tg_id = int(msg['to'].node[1:])
|
self.tg_id = int(msg['to'].node[1:])
|
||||||
|
|
||||||
def block(hndl, self):
|
def block(hndl, self):
|
||||||
|
"""Block this user"""
|
||||||
nickname = display_tg_name(self.tg_dialogs[hndl.jid]['users'][hndl.tg_id])
|
nickname = display_tg_name(self.tg_dialogs[hndl.jid]['users'][hndl.tg_id])
|
||||||
self.tg_connections[hndl.jid].invoke(BlockRequest( InputPeerUser(hndl.tg_id, self.tg_dialogs[jid]['users'][hndl.tg_id].access_hash) ) )
|
self.tg_connections[hndl.jid].invoke(BlockRequest( InputPeerUser(hndl.tg_id, self.tg_dialogs[jid]['users'][hndl.tg_id].access_hash) ) )
|
||||||
self.gate_reply_message(iq, 'User %s blacklisted!' % nickname)
|
self.gate_reply_message(iq, 'User %s blacklisted!' % nickname)
|
||||||
|
|
||||||
def unblock(hndl, self):
|
def unblock(hndl, self):
|
||||||
|
"""Unblock this user"""
|
||||||
nickname = display_tg_name(self.tg_dialogs[hndl.jid]['users'][hndl.tg_id])
|
nickname = display_tg_name(self.tg_dialogs[hndl.jid]['users'][hndl.tg_id])
|
||||||
self.tg_connections[hndl.jid].invoke(UnblockRequest( InputPeerUser(hndl.tg_id, self.tg_dialogs[jid]['users'][hndl.tg_id].access_hash) ) )
|
self.tg_connections[hndl.jid].invoke(UnblockRequest( InputPeerUser(hndl.tg_id, self.tg_dialogs[jid]['users'][hndl.tg_id].access_hash) ) )
|
||||||
self.gate_reply_message(iq, 'User %s unblacklisted!' % nickname)
|
self.gate_reply_message(iq, 'User %s unblacklisted!' % nickname)
|
||||||
|
|
||||||
def remove(hndl, self):
|
def remove(hndl, self):
|
||||||
|
"""Remove User from Telegram contact list"""
|
||||||
peer = InputPeerUser(hndl.tg_id, self.tg_dialogs[hndl.jid]['users'][hndl.tg_id].access_hash)
|
peer = InputPeerUser(hndl.tg_id, self.tg_dialogs[hndl.jid]['users'][hndl.tg_id].access_hash)
|
||||||
c_jid = get_contact_jid(self.tg_dialogs[hndl.jid]['users'][hndl.tg_id], self.boundjid.bare)
|
c_jid = get_contact_jid(self.tg_dialogs[hndl.jid]['users'][hndl.tg_id], self.boundjid.bare)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user