diff --git a/asmodee.py b/asmodee.py index 80665bb..338ed61 100755 --- a/asmodee.py +++ b/asmodee.py @@ -10,7 +10,7 @@ import pickle import time import threading import json -from datetime import datetime +from datetime import datetime,timedelta from matrix_bot_api.matrix_bot_api import MatrixBotAPI from matrix_bot_api.mregex_handler import MRegexHandler @@ -1130,6 +1130,7 @@ def statistiques(room,event): # Enregistrement des statistiques stats[room.room_id,user] = usrstats1 stats[room.room_id,nick] = usrstats2 + @not_myself def last(room,event): # Regarde la dernière fois que quelqu'un a écrit un message global modules @@ -1143,23 +1144,24 @@ def last(room,event): # Regarde la dernière fois que quelqu'un a écrit un mess args.pop(0) pers = "" if (len(args) >= 1 and args[0] == "all"): - try: - max_sign = "+" - max_duree = 0 - if (len(args) > 1): - max_sign = args[1][0] - max_duree = int(args[1][1:]) - ref_duree = datetime.now() - timedelta(days=max_duree) - salon = verifPMRoom(room,event) - reponse = "Les gens ayant posté à " + max_sign + " de " + str(max_duree) + " jours :\n" - for cle,valeur in stats.items(): - if (cle[0] == room.room_id): - usrstats = stats[room.room_id,cle[1]] - if ((max_sign == "+" and usrstats.date < ref_duree) or ((max_sign == "-" and usrstats.date > ref_duree))): - reponse += "- " + usrstats.nick + " le " + usrstats.date.strftime("%Y-%m-%d %H:%M:%S") + "\n" - msg(salon, reponse) - except: - msg(room,pers + " : Erreur de commande") + max_sign = "+" + max_duree = 0 + if (len(args) > 1): + max_sign = args[1][0] + max_duree = int(args[1][1:]) + ref_duree = datetime.now() - timedelta(days=max_duree) + salon = verifPMRoom(room,event) + all_usr = {} + reponse = "Les gens ayant posté à " + max_sign + " de " + str(max_duree) + " jours :\n" + for cle,valeur in stats.items(): + if (cle[0] == room.room_id): + usrstats = stats[room.room_id,cle[1]] + if ((usrstats.user in all_usr and all_usr[usrstats.user].date < usrstats.date) or not usrstats.user in all_usr): + all_usr[usrstats.user] = usrstats + for user,usrstats in all_usr.items(): + if ((max_sign == "+" and usrstats.date < ref_duree) or ((max_sign == "-" and usrstats.date > ref_duree))): + reponse += "- " + usrstats.nick + "(" + user + ")" + " le " + usrstats.date.strftime("%Y-%m-%d %H:%M:%S") + "\n" + msg(salon, reponse) else: if (len(args) == 0): pers = getNick(room,event) @@ -1174,6 +1176,7 @@ def last(room,event): # Regarde la dernière fois que quelqu'un a écrit un mess # if (cle[0] == room.room_id): # msg(room,cle[1] + "\n") + @not_myself def actif(room,event): # Stats d'activité d'une personne global modules