X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sid%2Flog.py;h=278be3d505ebbe63d7dbdfcbe108eec57b1dbf66;hb=aedd6aa01b9f279a4ae5b10b31b66900ce84c07b;hp=ba216e5f58eafaf286ba3012451d06613d440720;hpb=2bf3f2113341a56c8059a45d886e9b77ac3ab166;p=sid.git diff --git a/sid/log.py b/sid/log.py index ba216e5..278be3d 100644 --- a/sid/log.py +++ b/sid/log.py @@ -23,7 +23,10 @@ from .plugin import Plugin, botcmd class Log(Plugin): - """Logs presence. + """Logs group chat participant presence. + + The account running the bot need at least room moderation right to log + participants JIDs (fallback to nickname). """ throttle_ts = int(time())-30 @@ -37,18 +40,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)) @@ -58,12 +70,13 @@ class Log(Plugin): @botcmd(hidden=True) def write(self, message, args): - """ - **command** ``!write`` : Write log to file""" + """Dump/save room presences log + + ``!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 +90,7 @@ class Log(Plugin): @botcmd(hidden=True) def dump(self, message, args): - """**command** ``!dump`` : dump log online!""" + """``!dump`` : Dumps log as MUC message""" self.reply(message, self._format_log())