add bot-wide option to colorize nicknames in formatted output
This commit is contained in:
parent
ac30f8d4cc
commit
d43e96f7e7
1 changed files with 16 additions and 6 deletions
|
@ -1,7 +1,14 @@
|
||||||
import datetime
|
import datetime
|
||||||
from src import EventManager, ModuleManager, utils
|
from src import EventManager, ModuleManager, utils
|
||||||
|
|
||||||
|
@utils.export("botset", utils.BoolSetting("colorize-nicknames",
|
||||||
|
"Whether or not to format nicknames with calculated colors"))
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
|
def _colorize(self, nickname):
|
||||||
|
if self.bot.get_setting("colorize-nicknames", False):
|
||||||
|
return utils.irc.hash_colorize(nickname)
|
||||||
|
return nickname
|
||||||
|
|
||||||
def _event(self, type, server, line, context, minimal=None,
|
def _event(self, type, server, line, context, minimal=None,
|
||||||
channel=None, user=None, **kwargs):
|
channel=None, user=None, **kwargs):
|
||||||
self.events.on("formatted").on(type).call(server=server,
|
self.events.on("formatted").on(type).call(server=server,
|
||||||
|
@ -21,6 +28,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
if channel:
|
if channel:
|
||||||
symbols = self._mode_symbols(user, channel, event["server"])
|
symbols = self._mode_symbols(user, channel, event["server"])
|
||||||
|
|
||||||
|
nickname = self._colorize(nickname)
|
||||||
|
|
||||||
if event["action"]:
|
if event["action"]:
|
||||||
return "* %s%s %s" % (symbols, nickname, event["message"])
|
return "* %s%s %s" % (symbols, nickname, event["message"])
|
||||||
else:
|
else:
|
||||||
|
@ -43,16 +52,17 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["channel"].name, channel=event["channel"], user=user,
|
event["channel"].name, channel=event["channel"], user=user,
|
||||||
parsed_line=event["line"])
|
parsed_line=event["line"])
|
||||||
|
|
||||||
def _on_notice(self, event, sender):
|
def _on_notice(self, event, nickname):
|
||||||
return "(notice) <%s> %s" % (sender, event["message"])
|
nickname = self._colorize(nickname)
|
||||||
def _channel_notice(self, event, sender, channel):
|
return "(notice) <%s> %s" % (nickname, event["message"])
|
||||||
line = self._on_notice(event, sender)
|
def _channel_notice(self, event, nickname, channel):
|
||||||
|
line = self._on_notice(event, nickname)
|
||||||
self._event("notice.channel", event["server"], line,
|
self._event("notice.channel", event["server"], line,
|
||||||
event["channel"].name, parsed_line=event["line"], channel=channel,
|
event["channel"].name, parsed_line=event["line"], channel=channel,
|
||||||
user=event["user"])
|
user=event["user"])
|
||||||
|
|
||||||
def _private_notice(self, event, sender, target):
|
def _private_notice(self, event, nickname, target):
|
||||||
line = self._on_notice(event, sender)
|
line = self._on_notice(event, nickname)
|
||||||
self._event("notice.private", event["server"], line, None,
|
self._event("notice.private", event["server"], line, None,
|
||||||
parsed_line=event["line"], user=event["user"])
|
parsed_line=event["line"], user=event["user"])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue