hebdobot/hooks/finish_review.py

112 lines
4.0 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 privatebinapi
import logger
from 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
pastebin_url = ""
if bot.settings.PASTEBIN_URL != "":
result = privatebinapi.send(
bot.settings.PASTEBIN_URL,
text=report,
expiration=bot.settings.PASTEBIN_EXPIRATION,
)
pastebin_url = result["full_url"]
# On sauve le texte dans un fichier
review_file = (
f"{bot.review.start_time.strftime('%Y%m%d')}"
"-log-irc-revue-hebdomadaire.txt"
)
review_path = os.path.join(bot.settings.REVIEW_DIRECTORY, f"{review_file}")
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 : {pastebin_url}")
bot.send(channel, f"% Durée de la revue : {bot.review.duration} minutes")
bot.send(
channel,
f"% Nombre de personnes participantes : {bot.review.user_count}",
)
bot.send(
channel,
"% La participation moyenne aux revues est de "
f"{stats.avg_users:.1f} 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 "
f"comme nom de fichier {review_file}",
)
bot.send(channel, "% Fin de la revue hebdomadaire")
bot.send(bot.review.owner, "Revue finie.")
return True