info to debug
This commit is contained in:
parent
893c6a5d39
commit
d9cc1e2651
1 changed files with 8 additions and 2 deletions
|
@ -33,12 +33,16 @@ class MemeteraCounter(niobot.Module):
|
|||
@niobot.event("message")
|
||||
async def on_message(self, room: niobot.MatrixRoom, event: niobot.RoomMessage):
|
||||
if self.bot.is_old(event):
|
||||
self.log.debug("Ignoring old event")
|
||||
return
|
||||
if room.room_id not in self.ROOM_IDS:
|
||||
self.log.debug("Ignoring non-interesting event in %s", room.room_id)
|
||||
return
|
||||
if event.sender not in self.USER_IDS:
|
||||
self.log.debug("Ignoring uninteresting event by %s in %s", event.sender, room.room_id)
|
||||
return
|
||||
if not self.bot.redis:
|
||||
self.log.warning("Redis is not configured!")
|
||||
return
|
||||
|
||||
counts = {}
|
||||
|
@ -46,17 +50,19 @@ class MemeteraCounter(niobot.Module):
|
|||
for word, regex in self.WORDS.items():
|
||||
word_count = len(regex.findall(lower_body))
|
||||
if word_count:
|
||||
self.log.info("June said %r %d times in %s!", word, word_count, event.event_id)
|
||||
self.log.debug("June said %r %d times in %s!", word, word_count, event.event_id)
|
||||
counts.setdefault(word, 0)
|
||||
counts[word] += word_count
|
||||
|
||||
for word, count in counts.items():
|
||||
key = "june_wordcount_%s" % word
|
||||
self.log.debug("Fetching redis key %r", key)
|
||||
stored = await self.bot.redis.get(key)
|
||||
stored = stored or 0
|
||||
stored += count
|
||||
await self.bot.redis.set(key, count)
|
||||
self.log.info("June has now said %r %d times", word, stored)
|
||||
self.log.debug("June has now said %r %d times", word, stored)
|
||||
niobot.Event.parse_event()
|
||||
|
||||
@niobot.command(name="june-word-count", hidden=True)
|
||||
async def june_word_count(
|
||||
|
|
Loading…
Reference in a new issue