skip !more's out/err, added a way to split messages from their prefixes for

logging purposes
This commit is contained in:
jesopo 2018-07-14 09:50:12 +01:00
parent 7d9f3dc6e4
commit 718da30728
4 changed files with 21 additions and 16 deletions

View file

@ -75,8 +75,8 @@ class Channel(object):
self.bot.database.del_channel_setting(self.server.id, self.bot.database.del_channel_setting(self.server.id,
self.name, setting) self.name, setting)
def send_message(self, text): def send_message(self, text, prefix=None):
self.server.send_message(self.name, text) self.server.send_message(self.name, text, prefix=prefix)
def send_mode(self, mode=None, target=None): def send_mode(self, mode=None, target=None):
self.server.send_mode(self.name, mode, target) self.server.send_mode(self.name, mode, target)
def send_kick(self, target, reason=None): def send_kick(self, target, reason=None):

View file

@ -233,12 +233,16 @@ class Server(object):
"" if reason == None else " %s" % reason)) "" if reason == None else " %s" % reason))
def send_quit(self, reason="Leaving"): def send_quit(self, reason="Leaving"):
self.send("QUIT :%s" % reason) self.send("QUIT :%s" % reason)
def send_message(self, target, message): def send_message(self, target, message, prefix=None):
self.send("PRIVMSG %s :%s" % (target, message)) full_message = message if not prefix else prefix+message
action = message.startswith("\01ACTION ") and message.endswith(
"\01") self.send("PRIVMSG %s :%s" % (target, full_message))
action = full_message.startswith("\01ACTION "
) and full_message.endswith("\01")
if action: if action:
message = message.split("\01ACTION ", 1)[1][:-1] message = full_message.split("\01ACTION ", 1)[1][:-1]
if self.has_channel(target): if self.has_channel(target):
self.get_channel(target).log.add_line(None, message, action, True) self.get_channel(target).log.add_line(None, message, action, True)
else: else:

View file

@ -33,8 +33,8 @@ class User(object):
self.bot.database.del_user_setting(self.server.id, self.nickname, self.bot.database.del_user_setting(self.server.id, self.nickname,
setting) setting)
def send_message(self, message): def send_message(self, message, prefix=None):
self.server.send_message(self.nickname, message) self.server.send_message(self.nickname, message, prefix=prefix)
def send_notice(self, message): def send_notice(self, message):
self.server.send_notice(self.nickname, message) self.server.send_notice(self.nickname, message)
def send_ctcp_response(self, command, args): def send_ctcp_response(self, command, args):

View file

@ -20,14 +20,14 @@ class Out(object):
return self return self
def send(self): def send(self):
if self.has_text(): if self.has_text():
text = "[%s] %s" % (self.prefix(), self._text) text = self._text
text_encoded = text.encode("utf8") text_encoded = text.encode("utf8")
if len(text_encoded) > OUT_CUTOFF: if len(text_encoded) > OUT_CUTOFF:
text = "%s%s" % (text_encoded[:OUT_CUTOFF].decode("utf8" text = "%s%s" % (text_encoded[:OUT_CUTOFF].decode("utf8"
).rstrip(), STR_MORE) ).rstrip(), STR_MORE)
self._text = "%s%s" % (STR_CONTINUED, text_encoded[OUT_CUTOFF: self._text = "%s%s" % (STR_CONTINUED, text_encoded[OUT_CUTOFF:
].decode("utf8").lstrip()) ].decode("utf8").lstrip())
self.target.send_message(text) self.target.send_message(text, prefix="[%s] " % self.prefix())
def set_prefix(self, prefix): def set_prefix(self, prefix):
self.module_name = prefix self.module_name = prefix
def has_text(self): def has_text(self):
@ -55,7 +55,7 @@ class Module(object):
help="Show usage help for commands", min_args=1, help="Show usage help for commands", min_args=1,
usage="<command>") usage="<command>")
bot.events.on("received").on("command").on("more").hook(self.more, bot.events.on("received").on("command").on("more").hook(self.more,
help="Get more output from the last command") help="Get more output from the last command", skip_out=True)
bot.events.on("postboot").on("configure").on( bot.events.on("postboot").on("configure").on(
"channelset").call(setting="command-prefix", "channelset").call(setting="command-prefix",
@ -131,10 +131,11 @@ class Module(object):
1, user=user, server=server, target=target, log=log, 1, user=user, server=server, target=target, log=log,
args=args, args_split=args_split, stdout=stdout, stderr=stderr, args=args, args_split=args_split, stdout=stdout, stderr=stderr,
command=command.lower(), is_channel=is_channel) command=command.lower(), is_channel=is_channel)
stdout.send() if not hook.kwargs.get("skip_out", False):
target.last_stdout = stdout stdout.send()
stderr.send() stderr.send()
target.last_stderr = stderr target.last_stdout = stdout
target.last_stderr = stderr
log.skip_next() log.skip_next()