info to debug

This commit is contained in:
Nexus 2024-09-19 01:48:26 +01:00
parent 893c6a5d39
commit d9cc1e2651

View file

@ -33,12 +33,16 @@ class MemeteraCounter(niobot.Module):
@niobot.event("message") @niobot.event("message")
async def on_message(self, room: niobot.MatrixRoom, event: niobot.RoomMessage): async def on_message(self, room: niobot.MatrixRoom, event: niobot.RoomMessage):
if self.bot.is_old(event): if self.bot.is_old(event):
self.log.debug("Ignoring old event")
return return
if room.room_id not in self.ROOM_IDS: if room.room_id not in self.ROOM_IDS:
self.log.debug("Ignoring non-interesting event in %s", room.room_id)
return return
if event.sender not in self.USER_IDS: if event.sender not in self.USER_IDS:
self.log.debug("Ignoring uninteresting event by %s in %s", event.sender, room.room_id)
return return
if not self.bot.redis: if not self.bot.redis:
self.log.warning("Redis is not configured!")
return return
counts = {} counts = {}
@ -46,17 +50,19 @@ class MemeteraCounter(niobot.Module):
for word, regex in self.WORDS.items(): for word, regex in self.WORDS.items():
word_count = len(regex.findall(lower_body)) word_count = len(regex.findall(lower_body))
if word_count: 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.setdefault(word, 0)
counts[word] += word_count counts[word] += word_count
for word, count in counts.items(): for word, count in counts.items():
key = "june_wordcount_%s" % word key = "june_wordcount_%s" % word
self.log.debug("Fetching redis key %r", key)
stored = await self.bot.redis.get(key) stored = await self.bot.redis.get(key)
stored = stored or 0 stored = stored or 0
stored += count stored += count
await self.bot.redis.set(key, 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) @niobot.command(name="june-word-count", hidden=True)
async def june_word_count( async def june_word_count(