From 55a4c77646865cd41014311e0efd86392ca4b5d5 Mon Sep 17 00:00:00 2001 From: kaliko Date: Tue, 12 May 2020 20:24:47 +0200 Subject: [PATCH] log: Add: log user jid when possible --- sid/log.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sid/log.py b/sid/log.py index ba216e5..746fad2 100644 --- a/sid/log.py +++ b/sid/log.py @@ -37,18 +37,27 @@ class Log(Plugin): bot.add_event_handler("muc::%s::got_offline" % self.bot.room, self.log_offline) - def log_online(self, pres): + def _get_jid(self, pres): nick = pres['muc']['nick'] + jid = self.bot.plugin['xep_0045'].rooms[self.bot.room][nick]['jid'] + if not jid: + self.log.debug('jid not found, is bot account moderating room?') + return nick + jid = jid.split('/')[0] # strip ressource + return jid + + def log_online(self, pres): + nick = self._get_jid(pres) self.log.info('got online: %s', nick) self.presence.append((datetime.now(), 'online', nick)) def log_offline(self, pres): - nick = pres['muc']['nick'] + nick = self._get_jid(pres) self.log.info('got offline: %s', nick) self.presence.append((datetime.now(), 'offline', nick)) def log_presence(self, pres): - nick = pres['muc']['nick'] + nick = self._get_jid(pres) self.log.debug('%s: %s', pres['muc']['nick'], pres['type']) self.presence.append((datetime.now(), pres['type'], nick)) @@ -63,7 +72,7 @@ class Log(Plugin): delay = int(time()) - Log.throttle_ts if delay < 30: self.log.debug('throttling file creation') - self.reply(message, f'wait {30-delay}') + self.reply(message, f'wait {30-delay}s') return log = self._format_log() mode = {'mode': 'w', 'encoding': 'utf-8'} -- 2.39.5