X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sid%2Flog.py;h=f3f45e707af4bcef5611a4ffebf5c02927d1a7bd;hb=382e54a3933a477e70af74eb6af45c9ad4c669a3;hp=ba216e5f58eafaf286ba3012451d06613d440720;hpb=2bf3f2113341a56c8059a45d886e9b77ac3ab166;p=sid.git diff --git a/sid/log.py b/sid/log.py index ba216e5..f3f45e7 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)) @@ -59,11 +68,11 @@ class Log(Plugin): @botcmd(hidden=True) def write(self, message, args): """ - **command** ``!write`` : Write log to file""" + **command** (hidden) ``!write`` : Writes log to file (use mktemp and return file location as MUC message)""" 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'} @@ -77,7 +86,7 @@ class Log(Plugin): @botcmd(hidden=True) def dump(self, message, args): - """**command** ``!dump`` : dump log online!""" + """**command** (hidden) ``!dump`` : Dumps log as MUC message""" self.reply(message, self._format_log())