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.name, setting)
def send_message(self, text):
self.server.send_message(self.name, text)
def send_message(self, text, prefix=None):
self.server.send_message(self.name, text, prefix=prefix)
def send_mode(self, mode=None, target=None):
self.server.send_mode(self.name, mode, target)
def send_kick(self, target, reason=None):

View file

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

View file

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

View file

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