Reply to statusmsg commands (e.g. '/msg +channel !ping') with the same statusmsg

This commit is contained in:
jesopo 2019-02-04 21:32:44 +00:00
parent e2d60a541c
commit ac16887c48
2 changed files with 20 additions and 10 deletions

View file

@ -13,7 +13,7 @@ REGEX_CUTOFF = re.compile(r"^.{1,%d}(?:\s|$)" % OUT_CUTOFF)
REGEX_ARG_NUMBER = re.compile(r"\$(\d+)") REGEX_ARG_NUMBER = re.compile(r"\$(\d+)")
class Out(object): class Out(object):
def __init__(self, server, module_name, target, msgid): def __init__(self, server, module_name, target, msgid, statusmsg):
self.server = server self.server = server
self.module_name = module_name self.module_name = module_name
self._hide_prefix = False self._hide_prefix = False
@ -21,6 +21,7 @@ class Out(object):
self._text = "" self._text = ""
self.written = False self.written = False
self._msgid = msgid self._msgid = msgid
self._statusmsg = statusmsg
def write(self, text): def write(self, text):
self._text += text self._text += text
@ -47,10 +48,12 @@ class Out(object):
if not self._hide_prefix: if not self._hide_prefix:
prefix = utils.consts.RESET + "[%s] " % self.prefix() prefix = utils.consts.RESET + "[%s] " % self.prefix()
target_str = "%s%s" % (self._statusmsg, self.target.name)
full_text = "%s%s" % (prefix, text)
if method == "PRIVMSG": if method == "PRIVMSG":
self.target.send_message(text, prefix=prefix, tags=tags) self.server.send_message(target_str, full_text, tags=tags)
elif method == "NOTICE": elif method == "NOTICE":
self.target.send_notice(text, prefix=prefix, tags=tags) self.server.send_notice(target_str, full_text, tags=tags)
def set_prefix(self, prefix): def set_prefix(self, prefix):
self.module_name = prefix self.module_name = prefix
@ -170,8 +173,11 @@ class Module(ModuleManager.BaseModule):
module_name = hook.function.__self__._name module_name = hook.function.__self__._name
msgid = event["tags"].get("draft/msgid", None) msgid = event["tags"].get("draft/msgid", None)
stdout = StdOut(event["server"], module_name, target, msgid) statusmsg = "".join(event.get("statusmsg", []))
stderr = StdErr(event["server"], module_name, target, msgid) stdout = StdOut(event["server"], module_name, target, msgid,
statusmsg)
stderr = StdErr(event["server"], module_name, target, msgid,
statusmsg)
command_method = self._command_method(target, event["server"]) command_method = self._command_method(target, event["server"])
if hook.kwargs.get("remove_empty", True): if hook.kwargs.get("remove_empty", True):
@ -385,7 +391,8 @@ class Module(ModuleManager.BaseModule):
@utils.hook("send.stdout") @utils.hook("send.stdout")
def send_stdout(self, event): def send_stdout(self, event):
stdout = StdOut(event["server"], event["module_name"], stdout = StdOut(event["server"], event["module_name"],
event["target"], event.get("msgid", None)) event["target"], event.get("msgid", None),
event.get("statusmsg", ""))
if event.get("hide_prefix", False): if event.get("hide_prefix", False):
stdout.hide_prefix() stdout.hide_prefix()
@ -397,7 +404,8 @@ class Module(ModuleManager.BaseModule):
@utils.hook("send.stderr") @utils.hook("send.stderr")
def send_stderr(self, event): def send_stderr(self, event):
stderr = StdErr(event["server"], event["module_name"], stderr = StdErr(event["server"], event["module_name"],
event["target"], event.get("msgid", None)) event["target"], event.get("msgid", None),
event.get("statusmsg", ""))
if event.get("hide_prefix", False): if event.get("hide_prefix", False):
stderr.hide_prefix() stderr.hide_prefix()

View file

@ -413,8 +413,10 @@ class Module(ModuleManager.BaseModule):
# strip prefix_symbols from the start of target, for when people use # strip prefix_symbols from the start of target, for when people use
# e.g. 'PRIVMSG +#channel :hi' which would send a message to only # e.g. 'PRIVMSG +#channel :hi' which would send a message to only
# voiced-or-above users # voiced-or-above users
prefix_symbols = "".join(event["server"].prefix_symbols.keys()) statusmsg = []
target = target.lstrip(prefix_symbols) while target[0] in event["server"].prefix_symbols.keys():
statusmsg.append(target[0])
target = target[1:]
channel = None channel = None
if target[0] in event["server"].channel_types: if target[0] in event["server"].channel_types:
@ -445,7 +447,7 @@ class Module(ModuleManager.BaseModule):
if channel: if channel:
self._event(event, "message.channel", user=user, channel=channel, self._event(event, "message.channel", user=user, channel=channel,
**kwargs) statusmsg=statusmsg, **kwargs)
channel.buffer.add_message(user_nickname, message, action, channel.buffer.add_message(user_nickname, message, action,
event["tags"], user==None) event["tags"], user==None)
elif event["server"].is_own_nickname(target): elif event["server"].is_own_nickname(target):