add bot-wide option to colorize nicknames in formatted output

This commit is contained in:
jesopo 2019-11-11 12:20:27 +00:00
parent ac30f8d4cc
commit d43e96f7e7

View file

@ -1,7 +1,14 @@
import datetime
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):
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,
channel=None, user=None, **kwargs):
self.events.on("formatted").on(type).call(server=server,
@ -21,6 +28,8 @@ class Module(ModuleManager.BaseModule):
if channel:
symbols = self._mode_symbols(user, channel, event["server"])
nickname = self._colorize(nickname)
if event["action"]:
return "* %s%s %s" % (symbols, nickname, event["message"])
else:
@ -43,16 +52,17 @@ class Module(ModuleManager.BaseModule):
event["channel"].name, channel=event["channel"], user=user,
parsed_line=event["line"])
def _on_notice(self, event, sender):
return "(notice) <%s> %s" % (sender, event["message"])
def _channel_notice(self, event, sender, channel):
line = self._on_notice(event, sender)
def _on_notice(self, event, nickname):
nickname = self._colorize(nickname)
return "(notice) <%s> %s" % (nickname, event["message"])
def _channel_notice(self, event, nickname, channel):
line = self._on_notice(event, nickname)
self._event("notice.channel", event["server"], line,
event["channel"].name, parsed_line=event["line"], channel=channel,
user=event["user"])
def _private_notice(self, event, sender, target):
line = self._on_notice(event, sender)
def _private_notice(self, event, nickname, target):
line = self._on_notice(event, nickname)
self._event("notice.private", event["server"], line, None,
parsed_line=event["line"], user=event["user"])