Fixes and tuning to users module

This commit is contained in:
Ville Ranki 2021-09-11 23:21:19 +03:00
parent 87aa703512
commit fb3046b11e
2 changed files with 7 additions and 3 deletions

2
bot.py
View File

@ -484,7 +484,7 @@ class Bot:
def load_module(self, modulename):
try:
self.logger.info(f'load module: {modulename}')
self.logger.info(f'Loading module: {modulename}..')
module = importlib.import_module('modules.' + modulename)
module = reload(module)
cls = getattr(module, 'MatrixModule')

View File

@ -20,6 +20,10 @@ class MatrixModule(BotModule):
else:
allusers = self.get_users(bot, room.room_id)
total = len(allusers)
if total == 0:
await bot.send_text(room, "I don't see any users. How did this happen?")
return
matched = 0
for user in allusers:
for name, pattern in self.classes.items():
@ -32,11 +36,11 @@ class MatrixModule(BotModule):
stats = dict(sorted(stats.items(), key=lambda item: item[1], reverse=True))
if args[0] == 'stats':
reply = f'I am seeing total {len(allusers)} users:\n'
reply = f'I am seeing total {len(allusers)} users in {len(self.bot.client.rooms)} rooms:\n'
else:
reply = f'I am seeing {len(allusers)} users in this room:\n'
for name in stats:
reply = reply + f' - {name}: {stats[name]} ({stats[name] / total * 100}%)\n'
reply = reply + f' - {name}: {stats[name]} ({round(stats[name] / total * 100, 2)}%)\n'
await bot.send_text(room, reply)
return
if len(args) == 2: