Print user status symbols in modules/print_activity.py

This commit is contained in:
jesopo 2018-10-03 16:44:44 +01:00
parent 98207be7b1
commit ce2231900d
2 changed files with 23 additions and 9 deletions

View file

@ -9,13 +9,22 @@ class Module(ModuleManager.BaseModule):
target += channel target += channel
self.bot.log.info("%s | %s", [target, line]) 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): def _on_message(self, event, nickname):
symbols = self._mode_symbols(event["user"], event["channel"],
event["server"])
if event["action"]: if event["action"]:
self.print_line(event, "* %s %s" % (nickname, event["message"]), self.print_line(event, "* %s%s %s" % (symbols, nickname,
channel=event["channel"].name) event["message"]), channel=event["channel"].name)
else: else:
self.print_line(event, "<%s> %s" % (nickname, event["message"]), self.print_line(event, "<%s%s> %s" % (symbols, nickname,
channel=event["channel"].name) event["message"]), channel=event["channel"].name)
@utils.hook("received.message.channel", @utils.hook("received.message.channel",
priority=EventManager.PRIORITY_HIGH) priority=EventManager.PRIORITY_HIGH)
def channel_message(self, event): def channel_message(self, event):

View file

@ -14,6 +14,7 @@ class Channel(IRCObject.Object):
self.topic_time = 0 self.topic_time = 0
self.users = set([]) self.users = set([])
self.modes = {} self.modes = {}
self.user_modes = {}
self.created_timestamp = None self.created_timestamp = None
self.buffer = IRCBuffer.Buffer(bot, server) self.buffer = IRCBuffer.Buffer(bot, server)
@ -40,6 +41,8 @@ class Channel(IRCObject.Object):
self.modes[mode].discard(user) self.modes[mode].discard(user)
if not len(self.modes[mode]): if not len(self.modes[mode]):
del self.modes[mode] del self.modes[mode]
if user in self.user_modes:
del self.user_modes
def has_user(self, user): def has_user(self, user):
return user in self.users return user in self.users
@ -51,6 +54,9 @@ class Channel(IRCObject.Object):
user = self.server.get_user(arg) user = self.server.get_user(arg)
if user: if user:
self.modes[mode].add(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: else:
self.modes[mode].add(arg.lower()) self.modes[mode].add(arg.lower())
def remove_mode(self, mode, arg=None): def remove_mode(self, mode, arg=None):
@ -61,6 +67,9 @@ class Channel(IRCObject.Object):
user = self.server.get_user(arg) user = self.server.get_user(arg)
if user: if user:
self.modes[mode].discard(user) self.modes[mode].discard(user)
self.user_modes[user].discard(mode)
if not self.user_modes[user]:
del self.user_modes[user]
else: else:
self.modes[mode].discard(arg.lower()) self.modes[mode].discard(arg.lower())
if not len(self.modes[mode]): if not len(self.modes[mode]):
@ -130,8 +139,4 @@ class Channel(IRCObject.Object):
return False return False
def get_user_status(self, user): def get_user_status(self, user):
modes = "" return self.user_modes.get(user, [])
for mode in self.server.mode_prefixes.values():
if user in self.modes.get(mode, []):
modes += mode
return modes