From ce2231900d476b2f1ba174faed124f9f4e2d6cb6 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 3 Oct 2018 16:44:44 +0100 Subject: [PATCH] Print user status symbols in modules/print_activity.py --- modules/print_activity.py | 17 +++++++++++++---- src/IRCChannel.py | 15 ++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/modules/print_activity.py b/modules/print_activity.py index 743a5ed3..c8e761f3 100644 --- a/modules/print_activity.py +++ b/modules/print_activity.py @@ -9,13 +9,22 @@ class Module(ModuleManager.BaseModule): target += channel self.bot.log.info("%s | %s", [target, line]) + def _mode_symbols(self, user, channel, server): + modes = channel.get_user_status(user) + symbols = [] + for mode in channel.get_user_status(user): + symbols.append(server.prefix_modes[mode]) + return "".join(symbols) + def _on_message(self, event, nickname): + symbols = self._mode_symbols(event["user"], event["channel"], + event["server"]) if event["action"]: - self.print_line(event, "* %s %s" % (nickname, event["message"]), - channel=event["channel"].name) + self.print_line(event, "* %s%s %s" % (symbols, nickname, + event["message"]), channel=event["channel"].name) else: - self.print_line(event, "<%s> %s" % (nickname, event["message"]), - channel=event["channel"].name) + self.print_line(event, "<%s%s> %s" % (symbols, nickname, + event["message"]), channel=event["channel"].name) @utils.hook("received.message.channel", priority=EventManager.PRIORITY_HIGH) def channel_message(self, event): diff --git a/src/IRCChannel.py b/src/IRCChannel.py index 9770f892..83b846f9 100644 --- a/src/IRCChannel.py +++ b/src/IRCChannel.py @@ -14,6 +14,7 @@ class Channel(IRCObject.Object): self.topic_time = 0 self.users = set([]) self.modes = {} + self.user_modes = {} self.created_timestamp = None self.buffer = IRCBuffer.Buffer(bot, server) @@ -40,6 +41,8 @@ class Channel(IRCObject.Object): self.modes[mode].discard(user) if not len(self.modes[mode]): del self.modes[mode] + if user in self.user_modes: + del self.user_modes def has_user(self, user): return user in self.users @@ -51,6 +54,9 @@ class Channel(IRCObject.Object): user = self.server.get_user(arg) if user: self.modes[mode].add(user) + if not user in self.user_modes: + self.user_modes[user] = set([]) + self.user_modes[user].add(mode) else: self.modes[mode].add(arg.lower()) def remove_mode(self, mode, arg=None): @@ -61,6 +67,9 @@ class Channel(IRCObject.Object): user = self.server.get_user(arg) if user: self.modes[mode].discard(user) + self.user_modes[user].discard(mode) + if not self.user_modes[user]: + del self.user_modes[user] else: self.modes[mode].discard(arg.lower()) if not len(self.modes[mode]): @@ -130,8 +139,4 @@ class Channel(IRCObject.Object): return False def get_user_status(self, user): - modes = "" - for mode in self.server.mode_prefixes.values(): - if user in self.modes.get(mode, []): - modes += mode - return modes + return self.user_modes.get(user, [])