hebdobot/bot/hooks/finish_review.py

100 lines
3.6 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from datetime import datetime
import os
import logger
from bot.review.stats import ReviewData, ReviewStats
class FinishReview:
def process(self, bot, channel, sender, message):
"""
Si la commande est bonne, le bot met fin à la revue hebdomadaire.
"""
if message.lower() == "!fin":
logger.info("!fin caught.")
if not bot.review.is_started:
bot.send(channel, f"{sender}, pas de revue en cours.")
return True
if not bot.review.is_owner(sender):
bot.send(channel, f"{sender}, vous n'êtes pas responsable de la revue.")
return True
if bot.review.is_ended:
bot.send(channel, "La revue est déjà finie.")
return True
if not bot.review.has_participants:
bot.send(channel, "Participation nulle détectée. La revue est ignorée.")
bot.review.cancel()
return True
# Ok, on clot la revue hebdomadaire
bot.review.current_topic.close()
bot.send(
channel,
f"% durée du point {bot.review.current_topic.title} : "
f"{bot.review.current_topic.duration}",
)
bot.review.close()
# Chargement des statistiques des revues
stats = ReviewStats(bot.settings.REVIEW_STATS)
stats.load()
# On génère le texte de la revue
report = bot.review.report(stats, bot.settings.USER_ALIASES)
# Mise à jour des statistiques des revues
if bot.review.user_count > 1:
stats.datas.append(
ReviewData(
bot.review.start_time,
bot.review.user_count,
bot.review.duration,
)
)
stats.save()
# On copie ce texte sur un pad
url = ""
# On sauve le texte dans un fichier
review_path = os.path.join(
bot.settings.REVIEW_DIRECTORY,
f"{bot.review.start_time.strftime('%Y%m%d')}"
"-log-irc-revue-hebdomadaire.txt",
)
with open(review_path, "w") as file_handle:
file_handle.write(report)
bot.send(
channel,
f"% C'était la {stats.size}e revue hebdomadaire de l'April, la "
f"{stats.year_review(bot.review.year)}e de l'année {bot.review.year}.",
)
bot.send(channel, f"% Compte-rendu de la revue : {url}")
bot.send(channel, "% Durée de la revue : {temps_ecoule} minutes")
bot.send(channel, "% Nombre de personnes participantes : {combien}")
bot.send(
channel,
"% La participation moyenne aux revues est de "
f"{stats.avg_users} personnes",
)
bot.send(
channel,
f"% {' '.join(bot.review.participants)}, pensez à noter votre "
"bénévalo : http://www.april.org/my?action=benevalo",
)
bot.send(
channel,
f"% {bot.review.owner}, ne pas oublier d'ajouter le compte-rendu "
"de la revue sur https://agir.april.org/issues/135 en utilisant "
"comme nom de fichier {nom_fichier}",
)
bot.send(channel, "% Fin de la revue hebdomadaire")
bot.send(bot.review.owner, "Revue finie.")
return True