do all user-provided formatting as {VAR} formatting
otherwise, e.g., a PRIVMSG with {~NICK} will be replaced with user nickname
This commit is contained in:
parent
a974134472
commit
0eb92278cc
1 changed files with 47 additions and 41 deletions
|
@ -14,11 +14,12 @@ class Module(ModuleManager.BaseModule):
|
|||
minimal = minimal or line
|
||||
|
||||
if user:
|
||||
formatting["NICK"] = user.nickname
|
||||
formatting["~NICK"] = user.nickname
|
||||
line = line.format(**formatting)
|
||||
minimal = minimal.format(**formatting)
|
||||
|
||||
for key, value in formatting.items():
|
||||
if key[0] == "~":
|
||||
formatting[key] = self._color(value)
|
||||
pretty = pretty.format(**formatting)
|
||||
|
||||
|
@ -40,34 +41,34 @@ class Module(ModuleManager.BaseModule):
|
|||
symbols = self._mode_symbols(user, channel, event["server"])
|
||||
|
||||
if event["action"]:
|
||||
format = "* %s{NICK} %s"
|
||||
format = "* {SYM}{~NICK} {MSG}"
|
||||
else:
|
||||
format = "<%s{NICK}> %s"
|
||||
format = "<{SYM}{~NICK}> {MSG}"
|
||||
|
||||
return format % (symbols, event["message"])
|
||||
return {"MSG": event["message"], "SYM": symbols}, format
|
||||
|
||||
@utils.hook("send.message.channel")
|
||||
@utils.hook("received.message.channel")
|
||||
def channel_message(self, event):
|
||||
line = self._privmsg(event, event["channel"], event["user"])
|
||||
formatting, line = self._privmsg(event, event["channel"], event["user"])
|
||||
|
||||
self._event("message.channel", event["server"], line,
|
||||
event["channel"].name, channel=event["channel"], user=event["user"],
|
||||
parsed_line=event["line"])
|
||||
parsed_line=event["line"], formatting=formatting)
|
||||
|
||||
def _on_notice(self, event, user, channel):
|
||||
symbols = ""
|
||||
if channel:
|
||||
symbols = self._mode_symbols(user, channel, event["server"])
|
||||
|
||||
return "-%s{NICK}- %s" % (symbols, event["message"])
|
||||
return {"MSG": event["message"], "SYM": symbols}, "-{SYM}{~NICK}- {MSG}"
|
||||
|
||||
def _channel_notice(self, event, user, channel):
|
||||
line = self._on_notice(event, user, channel)
|
||||
formatting, line = self._on_notice(event, user, channel)
|
||||
|
||||
self._event("notice.channel", event["server"], line,
|
||||
event["channel"].name, parsed_line=event["line"], channel=channel,
|
||||
user=event["user"])
|
||||
user=event["user"], formatting=formatting)
|
||||
|
||||
@utils.hook("received.notice.channel")
|
||||
@utils.hook("send.notice.channel")
|
||||
|
@ -77,19 +78,20 @@ class Module(ModuleManager.BaseModule):
|
|||
@utils.hook("received.notice.private")
|
||||
@utils.hook("send.notice.private")
|
||||
def private_notice(self, event):
|
||||
line= self._on_notice(event, event["user"], None)
|
||||
formatting, line = self._on_notice(event, event["user"], None)
|
||||
self._event("notice.private", event["server"], line,
|
||||
event["target"].nickname, parsed_line=event["line"],
|
||||
user=event["user"])
|
||||
user=event["user"], formatting=formatting)
|
||||
|
||||
def _on_join(self, event, user):
|
||||
channel_name = event["channel"].name
|
||||
|
||||
minimal = "{NICK} joined %s" % channel_name
|
||||
line = "- {NICK} (%s) joined %s" % (user.userhost(), channel_name)
|
||||
minimal = "{~NICK} joined {CHAN}"
|
||||
line = "- {~NICK} ({UH}) joined {CHAN}"
|
||||
|
||||
self._event("join", event["server"], line, event["channel"].name,
|
||||
channel=event["channel"], user=user, minimal=minimal)
|
||||
channel=event["channel"], user=user, minimal=minimal,
|
||||
formatting={"UH": user.userhost(), "CHAN": channel_name})
|
||||
@utils.hook("received.join")
|
||||
def join(self, event):
|
||||
self._on_join(event, event["user"])
|
||||
|
@ -102,22 +104,23 @@ class Module(ModuleManager.BaseModule):
|
|||
username = event["username"]
|
||||
hostname = event["hostname"]
|
||||
|
||||
minimal = "{NICK} changed host to %s@%s" % (username, hostname)
|
||||
minimal = "{~NICK} changed host to {USER}@{HOST}"
|
||||
line = "- %s" % minimal
|
||||
|
||||
self._event("chghost", event["server"], line, None, user=event["user"],
|
||||
minimal=minimal)
|
||||
minimal=minimal, formatting={"USER": username, "HOST": hostname})
|
||||
|
||||
def _on_part(self, event, user):
|
||||
channel_name = event["channel"].name
|
||||
reason = event["reason"]
|
||||
reason = "" if not reason else " (%s)" % reason
|
||||
|
||||
minimal = "{NICK} left %s%s" % (channel_name, reason)
|
||||
minimal = "{~NICK} left {CHAN}{REAS}"
|
||||
line = "- %s" % minimal
|
||||
|
||||
self._event("part", event["server"], line, event["channel"].name,
|
||||
channel=event["channel"], user=user, minimal=minimal)
|
||||
channel=event["channel"], user=user, minimal=minimal,
|
||||
formatting={"CHAN": channel_name, "REAS": reason})
|
||||
@utils.hook("received.part")
|
||||
def part(self, event):
|
||||
self._on_part(event, event["user"])
|
||||
|
@ -126,10 +129,10 @@ class Module(ModuleManager.BaseModule):
|
|||
self._on_part(event, event["server"].get_user(event["server"].nickname))
|
||||
|
||||
def _on_nick(self, event, user):
|
||||
formatting = {"ONICK": event["old_nickname"],
|
||||
"NNICK": event["new_nickname"]}
|
||||
formatting = {"~ONICK": event["old_nickname"],
|
||||
"~NNICK": event["new_nickname"]}
|
||||
|
||||
minimal = "{ONICK} changed nickname to {NNICK}"
|
||||
minimal = "{~ONICK} changed nickname to {~NNICK}"
|
||||
line = "- %s" % minimal
|
||||
|
||||
self._event("nick", event["server"], line, None, user=user,
|
||||
|
@ -143,15 +146,16 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
@utils.hook("received.server-notice")
|
||||
def server_notice(self, event):
|
||||
line = "(server notice) %s" % event["message"]
|
||||
self._event("server-notice", event["server"], line, None)
|
||||
line = "(server notice) {MSG}"
|
||||
self._event("server-notice", event["server"], line, None,
|
||||
formatting={"MSG": event["message"]})
|
||||
|
||||
@utils.hook("received.invite")
|
||||
def invite(self, event):
|
||||
formatting = {"TNICK": event["target_user"].nickname}
|
||||
formatting = {"CHAN": event["target_channel"],
|
||||
"~TNICK": event["target_user"].nickname}
|
||||
|
||||
channel_name = event["target_channel"]
|
||||
minimal = "{NICK} invited {TNICK} to %s" % channel_name
|
||||
minimal = "{~NICK} invited {~TNICK} to {CHAN}"
|
||||
line = "- %s" % minimal
|
||||
|
||||
self._event("invite", event["server"], line, event["target_channel"],
|
||||
|
@ -164,16 +168,16 @@ class Module(ModuleManager.BaseModule):
|
|||
if args:
|
||||
args = " %s" % args
|
||||
|
||||
minimal = "{NICK} set mode %s%s" % (modes, args)
|
||||
minimal = "{~NICK} set mode {MODE}{ARGS}"
|
||||
line = "- %s" % minimal
|
||||
|
||||
self._event("mode.channel", event["server"], line,
|
||||
event["channel"].name, channel=event["channel"], user=event["user"],
|
||||
minimal=minimal)
|
||||
minimal=minimal, formatting={"MODE": modes, "ARGS": args})
|
||||
|
||||
def _on_topic(self, event, nickname, action, topic):
|
||||
formatting = {"TNICK": nickname}
|
||||
minimal = "topic %s by {TNICK}: %s" % (action, topic)
|
||||
formatting = {"ACT": action, "TOP": topic, "~TNICK": nickname}
|
||||
minimal = "topic {ACT} by {TNICK}: {TOP}"
|
||||
line = "- %s" % minimal
|
||||
|
||||
self._event("topic", event["server"], line, event["channel"].name,
|
||||
|
@ -198,14 +202,14 @@ class Module(ModuleManager.BaseModule):
|
|||
event["channel"].name, channel=event["channel"], minimal=minimal)
|
||||
|
||||
def _on_kick(self, event, kicked_nickname):
|
||||
formatting = {"KNICK": kicked_nickname}
|
||||
channel_name = event["channel"].name
|
||||
|
||||
reason = ""
|
||||
if event["reason"]:
|
||||
reason = " (%s)" % event["reason"]
|
||||
|
||||
minimal = "{NICK} kicked {KNICK} from %s%s" % (channel_name, reason)
|
||||
formatting = {"CHAN": event["channel"].name, "REAS": resaon,
|
||||
"~KNICK": kicked_nickname}
|
||||
|
||||
minimal = "{~NICK} kicked {~KNICK} from {CHAN}{REAS}"
|
||||
line = "- %s" % minimal
|
||||
|
||||
self._event("kick", event["server"], line, event["channel"].name,
|
||||
|
@ -221,11 +225,11 @@ class Module(ModuleManager.BaseModule):
|
|||
def _quit(self, event, user, reason):
|
||||
reason = "" if not reason else " (%s)" % reason
|
||||
|
||||
minimal = "{NICK} quit%s" % reason
|
||||
minimal = "{~NICK} quit{REAS}"
|
||||
line = "- %s" % minimal
|
||||
|
||||
self._event("quit", event["server"], line, None, user=user,
|
||||
minimal=minimal)
|
||||
minimal=minimal, formatting={"REAS": reason})
|
||||
@utils.hook("received.quit")
|
||||
def on_quit(self, event):
|
||||
self._quit(event, event["user"], event["reason"])
|
||||
|
@ -236,12 +240,14 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
@utils.hook("received.rename")
|
||||
def rename(self, event):
|
||||
line = "%s was renamed to %s" % (event["old_name"], event["new_name"])
|
||||
line = "{OLD} was renamed to {NEW}"
|
||||
self._event("rename", event["server"], line, event["old_name"],
|
||||
channel=event["channel"])
|
||||
channel=event["channel"],
|
||||
formatting={"OLD": event["old_name"], "NEW": event["new_name"]})
|
||||
|
||||
@utils.hook("received.376")
|
||||
def motd_end(self, event):
|
||||
for line in event["server"].motd_lines:
|
||||
line = "[MOTD] %s" % line
|
||||
self._event("motd", event["server"], line, None)
|
||||
line = "[MOTD] {LINE}"
|
||||
self._event("motd", event["server"], line, None,
|
||||
formatting={"LINE": line})
|
||||
|
|
Loading…
Reference in a new issue