dont use "%s %s"%("thing", "%s") trick - messes up when "thing" has %

This commit is contained in:
jesopo 2019-11-15 12:29:00 +00:00
parent 2cb55306c3
commit 27de12bcfe

View file

@ -111,27 +111,32 @@ class Module(ModuleManager.BaseModule):
@utils.hook("received.chghost") @utils.hook("received.chghost")
def _on_chghost(self, event): def _on_chghost(self, event):
format = "%s changed host to %s@%s" % ("%s", event["username"], username = event["username"]
event["hostname"]) hostname = event["hostname"]
minimal = format % event["user"].nickname
format = "%s changed host to %s@%s"
minimal = format % (event["user"].nickname, username, hostname)
normal_format = "- %s" % format normal_format = "- %s" % format
normal = normal_format % event["user"].nickname normal = normal_format % (event["user"].nickname, username, hostname)
pretty = normal_format % self._color(event["user"].nickname) pretty = normal_format % (self._color(event["user"].nickname), username,
hostname)
self._event("chghost", event["server"], normal, None, self._event("chghost", event["server"], normal, None,
user=event["user"], minimal=minimal, pretty=pretty) user=event["user"], minimal=minimal, pretty=pretty)
def _on_part(self, event, user): def _on_part(self, event, user):
channel_name = event["channel"].name
reason = event["reason"] reason = event["reason"]
reason = "" if not reason else " (%s)" % reason reason = "" if not reason else " (%s)" % reason
format = "%s left %s%s" % ("%s", event["channel"].name, reason) format = "%s left %s%s"
minimal = format % user.nickname minimal = format % (user.nickname, channel_name, reason)
normal_format = "- %s" % format normal_format = "- %s" % format
normal = normal_format % user.nickname normal = normal_format % (user.nickname, channel_name, reason)
pretty = normal_format % self._color(user.nickname) pretty = normal_format % (self._color(user.nickname), channel_name,
reason)
self._event("part", event["server"], normal, event["channel"].name, self._event("part", event["server"], normal, event["channel"].name,
channel=event["channel"], user=user, minimal=minimal, pretty=pretty) channel=event["channel"], user=user, minimal=minimal, pretty=pretty)
@ -170,41 +175,45 @@ class Module(ModuleManager.BaseModule):
@utils.hook("received.invite") @utils.hook("received.invite")
def invite(self, event): def invite(self, event):
format = "%s invited %s to %s" % ("%s", "%s", event["target_channel"]) format = "%s invited %s to %s"
minimal = format % (event["user"].nickname,
event["target_user"].nickname) sender = event["user"].nickname
target = event["target_user"].nickname
channel_name = event["target_channel"]
minimal = format % (sender, target, channel_name)
normal = "- %s" % minimal normal = "- %s" % minimal
pretty = format % (self._color(event["user"].nickname), pretty = format % (self._color(sender), target, channel_name)
self._color(event["target_user"].nickname))
self._event("invite", event["server"], normal, event["target_channel"], self._event("invite", event["server"], normal, event["target_channel"],
minimal=minimal, pretty=pretty) minimal=minimal, pretty=pretty)
@utils.hook("received.mode.channel") @utils.hook("received.mode.channel")
def mode(self, event): def mode(self, event):
modes = "".join(event["modes_str"])
args = " ".join(event["args_str"]) args = " ".join(event["args_str"])
if args: if args:
args = " %s" % args args = " %s" % args
format = "%s set mode %s%s" % ("%s", "".join(event["modes_str"]), format = "%s set mode %s%s"
args) minimal = format % (event["user"].nickname, modes, args)
minimal = format % event["user"].nickname
normal_format = "- %s" % format normal_format = "- %s" % format
normal = normal_format % event["user"].nickname normal = normal_format % (event["user"].nickname, modes, args)
pretty = normal_format % self._color(event["user"].nickname) pretty = normal_format % (self._color(event["user"].nickname), modes,
args)
self._event("mode.channel", event["server"], normal, self._event("mode.channel", event["server"], normal,
event["channel"].name, channel=event["channel"], user=event["user"], event["channel"].name, channel=event["channel"], user=event["user"],
minimal=minimal, pretty=pretty) minimal=minimal, pretty=pretty)
def _on_topic(self, event, nickname, action, topic): def _on_topic(self, event, nickname, action, topic):
format = "topic %s by %s: %s" % (action, "%s", topic) format = "topic %s by %s: %s"
minimal = format % nickname minimal = format % (action, nickname, topic)
normal_format = "- %s" % format normal_format = "- %s" % format
normal = normal_format % nickname normal = normal_format % (action, nickname, topic)
pretty = normal_format % self._color(nickname) pretty = normal_format % (action, self._color(nickname), topic)
self._event("topic", event["server"], normal, event["channel"].name, self._event("topic", event["server"], normal, event["channel"].name,
channel=event["channel"], user=event.get("user", None), channel=event["channel"], user=event.get("user", None),
@ -218,8 +227,7 @@ class Module(ModuleManager.BaseModule):
self._on_topic(event, event["setter"].nickname, "set", self._on_topic(event, event["setter"].nickname, "set",
event["channel"].topic) event["channel"].topic)
unix_dt = datetime.datetime.utcfromtimestamp(event["set_at"]) dt = utils.iso8601_format(utils.datetime_timestamp(event["set_at"]))
dt = datetime.datetime.strftime(unix_dt, utils.ISO8601_PARSE)
minimal = "topic set at %s" % dt minimal = "topic set at %s" % dt
normal = "- %s" % minimal normal = "- %s" % minimal
@ -229,19 +237,21 @@ class Module(ModuleManager.BaseModule):
def _on_kick(self, event, kicked_nickname): def _on_kick(self, event, kicked_nickname):
sender_nickname = event["user"].nickname sender_nickname = event["user"].nickname
channel_name = event["channel"].name
reason = "" reason = ""
if event["reason"]: if event["reason"]:
reason = " (%s)" % event["reason"] reason = " (%s)" % event["reason"]
format = "%s kicked %s from %s%s" % ("%s", "%s", event["channel"].name, format = "%s kicked %s from %s%s"
minimal = format % (sender_nickname, kicked_nickname, channel_name,
reason) reason)
minimal = format % (sender_nickname, kicked_nickname)
normal_format = "- %s" % format normal_format = "- %s" % format
normal = normal_format % (sender_nickname, kicked_nickname) normal = normal_format % (sender_nickname, kicked_nickname,
channel_name, reason)
pretty = normal_format % (self._color(sender_nickname), pretty = normal_format % (self._color(sender_nickname),
self._color(kicked_nickname)) self._color(kicked_nickname), channel_name, reason)
self._event("kick", event["server"], normal, event["channel"].name, self._event("kick", event["server"], normal, event["channel"].name,
channel=event["channel"], user=event.get("user", None), channel=event["channel"], user=event.get("user", None),
@ -256,12 +266,12 @@ class Module(ModuleManager.BaseModule):
def _quit(self, event, user, reason): def _quit(self, event, user, reason):
reason = "" if not reason else " (%s)" % reason reason = "" if not reason else " (%s)" % reason
format = "%s quit%s" % ("%s", reason) format = "%s quit%s"
minimal = format % user.nickname minimal = format % (user.nickname, reason)
normal_format = "- %s" % format normal_format = "- %s" % format
normal = normal_format % user.nickname normal = normal_format % (user.nickname, reason)
pretty = normal_format % self._color(user.nickname) pretty = normal_format % (self._color(user.nickname), reason)
self._event("quit", event["server"], normal, None, user=user, self._event("quit", event["server"], normal, None, user=user,
minimal=minimal, pretty=pretty) minimal=minimal, pretty=pretty)