2024-01-11 08:17:25 +01:00
|
|
|
|
from datetime import datetime
|
|
|
|
|
import os
|
|
|
|
|
|
2024-04-01 19:27:52 +02:00
|
|
|
|
import privatebinapi
|
|
|
|
|
|
2024-01-11 08:17:25 +01:00
|
|
|
|
import logger
|
2024-04-01 19:27:52 +02:00
|
|
|
|
from review.stats import ReviewData, ReviewStats
|
2024-01-11 08:17:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2024-04-01 19:27:52 +02:00
|
|
|
|
pastebin_url = ""
|
|
|
|
|
if bot.settings.PASTEBIN_URL != "":
|
2024-06-25 20:29:50 +02:00
|
|
|
|
try:
|
|
|
|
|
result = privatebinapi.send(
|
|
|
|
|
bot.settings.PASTEBIN_URL,
|
|
|
|
|
text=report,
|
|
|
|
|
expiration=bot.settings.PASTEBIN_EXPIRATION,
|
|
|
|
|
)
|
|
|
|
|
except:
|
|
|
|
|
# En cas d'erreur, on re-essaye une fois après un temps d'attente
|
|
|
|
|
time.sleep(int(bot.settings.PASTEBIN_WAIT))
|
|
|
|
|
result = privatebinapi.send(
|
|
|
|
|
bot.settings.PASTEBIN_URL,
|
|
|
|
|
text=report,
|
|
|
|
|
expiration=bot.settings.PASTEBIN_EXPIRATION,
|
|
|
|
|
)
|
|
|
|
|
try:
|
|
|
|
|
pastebin_url = result["full_url"]
|
|
|
|
|
except:
|
|
|
|
|
bot.send(channel, "Erreur sur le pastebin.")
|
2024-01-11 08:17:25 +01:00
|
|
|
|
|
|
|
|
|
# On sauve le texte dans un fichier
|
2024-04-06 10:03:48 +02:00
|
|
|
|
review_file = (
|
2024-01-11 08:17:25 +01:00
|
|
|
|
f"{bot.review.start_time.strftime('%Y%m%d')}"
|
2024-04-06 10:03:48 +02:00
|
|
|
|
"-log-irc-revue-hebdomadaire.txt"
|
2024-01-11 08:17:25 +01:00
|
|
|
|
)
|
2024-04-06 10:03:48 +02:00
|
|
|
|
review_path = os.path.join(bot.settings.REVIEW_DIRECTORY, f"{review_file}")
|
2024-01-11 08:17:25 +01:00
|
|
|
|
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}.",
|
|
|
|
|
)
|
2024-04-01 19:27:52 +02:00
|
|
|
|
bot.send(channel, f"% Compte-rendu de la revue : {pastebin_url}")
|
2024-04-06 10:03:48 +02:00
|
|
|
|
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}",
|
|
|
|
|
)
|
2024-01-11 08:17:25 +01:00
|
|
|
|
bot.send(
|
|
|
|
|
channel,
|
|
|
|
|
"% La participation moyenne aux revues est de "
|
2024-04-06 10:03:48 +02:00
|
|
|
|
f"{stats.avg_users:.1f} personnes",
|
2024-01-11 08:17:25 +01:00
|
|
|
|
)
|
|
|
|
|
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 "
|
2024-04-06 10:03:48 +02:00
|
|
|
|
f"comme nom de fichier {review_file}",
|
2024-01-11 08:17:25 +01:00
|
|
|
|
)
|
|
|
|
|
bot.send(channel, "% Fin de la revue hebdomadaire")
|
|
|
|
|
bot.send(bot.review.owner, "Revue finie.")
|
|
|
|
|
|
|
|
|
|
return True
|