improvements
This commit is contained in:
@@ -75,7 +75,7 @@ class MessageHandler():
|
|||||||
docstring = "No description available"
|
docstring = "No description available"
|
||||||
if docstring.startswith("nolist "):
|
if docstring.startswith("nolist "):
|
||||||
continue
|
continue
|
||||||
reply += "\n!{command} - {doc}".format(method, docstring.split("\n")[0])
|
reply += "\n!{} - {}".format(method, docstring.split("\n")[0])
|
||||||
return reply
|
return reply
|
||||||
else:
|
else:
|
||||||
method = getattr(self,self.arguments[0])
|
method = getattr(self,self.arguments[0])
|
||||||
|
|||||||
102
xmpp_tg/xmpp.py
102
xmpp_tg/xmpp.py
@@ -323,88 +323,32 @@ class XMPPTelegram(ComponentXMPP):
|
|||||||
self.gate_reply_message(msg, reply)
|
self.gate_reply_message(msg, reply)
|
||||||
#msg.reply(reply).send()
|
#msg.reply(reply).send()
|
||||||
|
|
||||||
if False:
|
|
||||||
self.gate_reply_message(iq, '=== Available dialog commands ===:\n\n'
|
|
||||||
|
|
||||||
'!help - Displays this text\n'
|
|
||||||
'!s/find/replace - Edit last message. Use empty `find` to edit whole message and empty `replace` to delete it.\n'
|
|
||||||
'!block - Blacklists current user\n'
|
|
||||||
'!unblock - Unblacklists current user\n'
|
|
||||||
'!remove - Removes history and contact from your contact list\n' )
|
|
||||||
|
|
||||||
def process_chat_group_command(self, iq):
|
def process_chat_group_command(self, iq):
|
||||||
parsed = iq['body'].split(' ')
|
logging.info("received command "+str(msg["body"])+" from "+str(msg["from"])+" for "+str(msg["to"]))
|
||||||
jid = iq['from'].bare
|
is_command = msg["body"].startswith("!") and msg["body"][1] != "_"
|
||||||
|
|
||||||
if parsed[0] == '!help':
|
if is_command:
|
||||||
self.gate_reply_message(iq, '=== Available chat commands ===:\n\n'
|
command = msg["body"].split(" ")[0][1:]
|
||||||
'!help - Displays this text\n'
|
handler = GroupchatCommandHandler(msg)._handler
|
||||||
'!s/find/replace - Edit last message. Use empty `find` to edit whole message and empty `replace` to delete it.\n'
|
try:
|
||||||
'!leave - Leaves current group or supergroup\n'
|
reply = str(handler(self))
|
||||||
'!invite - Invites user to group\n'
|
except Exception as e:
|
||||||
'!kick - Kicks user to group\n'
|
if self.config["debug"]:
|
||||||
)
|
reply = "******* DEBUG MODE ACTIVE *********\n"
|
||||||
elif parsed[0] == '!leave':
|
reply += "An Exception occured while executing this command:\n"
|
||||||
tg_id = int(iq['to'].node[1:])
|
reply += traceback.format_exc()
|
||||||
if tg_id in self.tg_dialogs[jid]['supergroups']:
|
|
||||||
peer = InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash)
|
|
||||||
self.tg_connections[jid].invoke( LeaveChannelRequest(peer) )
|
|
||||||
self.tg_connections[jid].invoke( DeleteHistoryRequest( peer, max_id = 0, just_clear = None ) )
|
|
||||||
c_jid = get_contact_jid(self.tg_dialogs[jid]['supergroups'][tg_id], self.boundjid.bare)
|
|
||||||
self.send_presence(pto = jid, pfrom = c_jid, ptype = 'unavailable')
|
|
||||||
self.send_presence(pto = jid, pfrom = c_jid, ptype = 'unsubscribed')
|
|
||||||
self.send_presence(pto = jid, pfrom = c_jid, ptype = 'unsubscribe')
|
|
||||||
if tg_id in self.tg_dialogs[jid]['groups']:
|
|
||||||
self.tg_connections[jid].invoke( DeleteChatUserRequest(tg_id, self.tg_connections[jid].me) )
|
|
||||||
self.tg_connections[jid].invoke( DeleteHistoryRequest( InputPeerChat(tg_id), max_id = 0, just_clear = None ) )
|
|
||||||
c_jid = get_contact_jid(self.tg_dialogs[jid]['groups'][tg_id], self.boundjid.bare)
|
|
||||||
self.send_presence(pto = jid, pfrom = c_jid, ptype = 'unavailable')
|
|
||||||
self.send_presence(pto = jid, pfrom = c_jid, ptype = 'unsubscribed')
|
|
||||||
self.send_presence(pto = jid, pfrom = c_jid, ptype = 'unsubscribe')
|
|
||||||
|
|
||||||
elif parsed[0] == '!invite':
|
|
||||||
tg_id = int(iq['to'].node[1:])
|
|
||||||
if tg_id in self.tg_dialogs[jid]['supergroups']:
|
|
||||||
invited_user = self.tg_connections[jid].get_entity(parsed[1])
|
|
||||||
if type(invited_user) == User:
|
|
||||||
self.tg_connections[jid].invoke(EditBannedRequest( InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash), invited_user, ChannelBannedRights(until_date=None,view_messages=False) ) )
|
|
||||||
self.tg_connections[jid].invoke(InviteToChannelRequest( InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash), [invited_user] ) )
|
|
||||||
if tg_id in self.tg_dialogs[jid]['groups']:
|
|
||||||
invited_user = self.tg_connections[jid].get_entity(parsed[1])
|
|
||||||
if type(invited_user) == User:
|
|
||||||
self.tg_connections[jid].invoke( AddChatUserRequest(tg_id, invited_user, 0) )
|
|
||||||
|
|
||||||
elif parsed[0] == '!kick':
|
|
||||||
tg_id = int(iq['to'].node[1:])
|
|
||||||
if tg_id in self.tg_dialogs[jid]['supergroups']:
|
|
||||||
kicked_user = self.tg_connections[jid].get_entity(parsed[1])
|
|
||||||
if type(kicked_user) == User:
|
|
||||||
self.tg_connections[jid].invoke(EditBannedRequest( InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash), kicked_user, ChannelBannedRights(until_date=None,view_messages=True) ) )
|
|
||||||
if tg_id in self.tg_dialogs[jid]['groups']:
|
|
||||||
kicked_user = self.tg_connections[jid].get_entity(parsed[1])
|
|
||||||
if type(kicked_user) == User:
|
|
||||||
self.tg_connections[jid].invoke( DeleteChatUserRequest(tg_id, kicked_user) )
|
|
||||||
|
|
||||||
elif iq['body'].startswith('!s/'):
|
|
||||||
tg_id = int(iq['to'].node[1:])
|
|
||||||
peer = InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash) if tg_id in self.tg_dialogs[jid]['supergroups'] else InputPeerChat(tg_id)
|
|
||||||
|
|
||||||
msg_id, edited = self.edit_message(jid, tg_id, iq['body'])
|
|
||||||
if not edited: return
|
|
||||||
|
|
||||||
# and send it
|
|
||||||
if edited != '' and edited != ' ':
|
|
||||||
self.tg_dialogs[jid]['messages'][tg_id]["body"] = edited
|
|
||||||
self.tg_connections[jid].invoke( EditMessageRequest(peer, msg_id, message = edited) )
|
|
||||||
else:
|
|
||||||
del(self.tg_dialogs[jid]['messages'][tg_id])
|
|
||||||
if isinstance(peer, InputPeerChannel):
|
|
||||||
self.tg_connections[jid].invoke( DeleteMessagesChannel(peer, [msg_id]) )
|
|
||||||
else:
|
else:
|
||||||
self.tg_connections[jid].invoke( DeleteMessagesRequest([msg_id], revoke = True) )
|
if isinstance(e, NotAuthorizedError):
|
||||||
|
reply = str(e)
|
||||||
|
elif isinstance(e, MessageHandler.WrongNumberOfArgsError):
|
||||||
|
reply = str(e)
|
||||||
|
else:
|
||||||
|
logging.error("Exception in command from {}, command was '{}'".format(msg["from"],msg["body"]))
|
||||||
|
traceback.print_exc()
|
||||||
|
reply = "Internal error, please contact Sysadmin"
|
||||||
|
if reply is not None:
|
||||||
|
self.gate_reply_message(msg, reply)
|
||||||
|
#msg.reply(reply).send()
|
||||||
|
|
||||||
def spawn_tg_client(self, jid, phone):
|
def spawn_tg_client(self, jid, phone):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user