fix sending updates from MessageHandler
This commit is contained in:
@@ -20,7 +20,7 @@ class CommandHandler():
|
|||||||
if len(self.arguments) < num_args:
|
if len(self.arguments) < num_args:
|
||||||
raise WrongNumberOfArgsError("!{} needs at least {} arguments".format(self._command, num_args))
|
raise WrongNumberOfArgsError("!{} needs at least {} arguments".format(self._command, num_args))
|
||||||
|
|
||||||
def __init__(self, msg):
|
def __init__(self, msg, xmpp):
|
||||||
self._command = msg["body"].split(" ")[0][1:]
|
self._command = msg["body"].split(" ")[0][1:]
|
||||||
self._handler = getattr(self, self._command, self._unknown_command_handler)
|
self._handler = getattr(self, self._command, self._unknown_command_handler)
|
||||||
self.type = "groupchat" if msg["type"] == "groupchat" else "chat"
|
self.type = "groupchat" if msg["type"] == "groupchat" else "chat"
|
||||||
@@ -29,14 +29,19 @@ class CommandHandler():
|
|||||||
self.replyto = self.sender.full if self.type == "chat" else self.sender.bare
|
self.replyto = self.sender.full if self.type == "chat" else self.sender.bare
|
||||||
self.arguments = msg["body"].split(" ")[1:]
|
self.arguments = msg["body"].split(" ")[1:]
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
|
self.xmpp = xmpp
|
||||||
|
|
||||||
def _update(self, text):
|
def _update(self, text):
|
||||||
xmpp.send_message(mto=self.replyto, mtype=self.type, mbody=text)
|
self.xmpp.send_message(mto=self.replyto, mtype=self.type, mbody=text)
|
||||||
|
|
||||||
def debug(self, *args, **kwargs):
|
def debug(self, *args, **kwargs):
|
||||||
"""nolist Show debug info"""
|
"""nolist Show debug info"""
|
||||||
return pprint.pformat(self.__dict__)
|
return pprint.pformat(self.__dict__)
|
||||||
|
|
||||||
|
def dupdate(self, *args, **kwargs):
|
||||||
|
"""nolist send message as update"""
|
||||||
|
self._update(str(args))
|
||||||
|
|
||||||
#TODO: handle non-existant commands
|
#TODO: handle non-existant commands
|
||||||
#TODO: add end text
|
#TODO: add end text
|
||||||
def help(self, *args, **kwargs):
|
def help(self, *args, **kwargs):
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ class XMPPTelegram(ComponentXMPP):
|
|||||||
|
|
||||||
if is_command:
|
if is_command:
|
||||||
command = msg["body"].split(" ")[0][1:]
|
command = msg["body"].split(" ")[0][1:]
|
||||||
handler = GateCommandHandler(msg)._handler
|
handler = GateCommandHandler(msg, self)._handler
|
||||||
try:
|
try:
|
||||||
reply = str(handler(self))
|
reply = str(handler(self))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -317,7 +317,7 @@ class XMPPTelegram(ComponentXMPP):
|
|||||||
|
|
||||||
if is_command:
|
if is_command:
|
||||||
command = msg["body"].split(" ")[0][1:]
|
command = msg["body"].split(" ")[0][1:]
|
||||||
handler = ChatCommandHandler(msg)._handler
|
handler = ChatCommandHandler(msg, self)._handler
|
||||||
try:
|
try:
|
||||||
reply = str(handler(self))
|
reply = str(handler(self))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -344,7 +344,7 @@ class XMPPTelegram(ComponentXMPP):
|
|||||||
|
|
||||||
if is_command:
|
if is_command:
|
||||||
command = msg["body"].split(" ")[0][1:]
|
command = msg["body"].split(" ")[0][1:]
|
||||||
handler = GroupchatCommandHandler(msg)._handler
|
handler = GroupchatCommandHandler(msg), self._handler
|
||||||
try:
|
try:
|
||||||
reply = str(handler(self))
|
reply = str(handler(self))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user