More fixes to users.. i can't use break it seems

This commit is contained in:
Ville Ranki 2021-09-11 23:54:09 +03:00
parent fb3046b11e
commit e1e162643d
1 changed files with 10 additions and 10 deletions

View File

@ -40,7 +40,8 @@ class MatrixModule(BotModule):
else: else:
reply = f'I am seeing {len(allusers)} users in this room:\n' reply = f'I am seeing {len(allusers)} users in this room:\n'
for name in stats: for name in stats:
reply = reply + f' - {name}: {stats[name]} ({round(stats[name] / total * 100, 2)}%)\n' if stats[name] > 0:
reply = reply + f' - {name}: {stats[name]} ({round(stats[name] / total * 100, 2)}%)\n'
await bot.send_text(room, reply) await bot.send_text(room, reply)
return return
if len(args) == 2: if len(args) == 2:
@ -91,15 +92,14 @@ class MatrixModule(BotModule):
def get_users(self, bot, roomid=None): def get_users(self, bot, roomid=None):
allusers = [] allusers = []
for croomid in self.bot.client.rooms: for croomid in self.bot.client.rooms:
if roomid and (roomid != croomid): if not roomid or (roomid == croomid):
break try:
try: users = self.bot.client.rooms[croomid].users
users = self.bot.client.rooms[croomid].users except (KeyError, ValueError) as e:
except (KeyError, ValueError) as e: self.logger.warning(f"Couldn't get user list in room with id {croomid}, skipping: {repr(e)}")
self.logger.warning(f"Couldn't get user list in room with id {croomid}, skipping: {repr(e)}") continue
continue for user in users:
for user in users: allusers.append(user)
allusers.append(user)
allusers = list(dict.fromkeys(allusers)) # Deduplicate allusers = list(dict.fromkeys(allusers)) # Deduplicate
return allusers return allusers