diff --git a/hooks/__init__.py b/hooks/__init__.py index 36bdc30..bb9b3be 100644 --- a/hooks/__init__.py +++ b/hooks/__init__.py @@ -11,6 +11,7 @@ from .finish_review import FinishReview from .hello import Hello from .help import Help from .individual_subject import IndividualSubject +from .input_participant import InputParticipant from .input_review import InputReview from .license import License from .listen_alexandrie import ListenAlexandrie @@ -28,6 +29,7 @@ hooks = ( CancelPreviousInput(), Chrono(), CollectiveSubject(), + InputParticipant(), Comment(), Current(), FinishReview(), diff --git a/hooks/finish_review.py b/hooks/finish_review.py index 158ef43..c5abb3b 100644 --- a/hooks/finish_review.py +++ b/hooks/finish_review.py @@ -67,14 +67,14 @@ class FinishReview: text=report, expiration=bot.settings.PASTEBIN_EXPIRATION, ) - pastebin_url = result.full_url + pastebin_url = result["full_url"] # On sauve le texte dans un fichier - review_path = os.path.join( - bot.settings.REVIEW_DIRECTORY, + review_file = ( f"{bot.review.start_time.strftime('%Y%m%d')}" - "-log-irc-revue-hebdomadaire.txt", + "-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) @@ -84,12 +84,15 @@ class FinishReview: 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, "% Durée de la revue : {temps_ecoule} minutes") - bot.send(channel, "% Nombre de personnes participantes : {combien}") + 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} personnes", + f"{stats.avg_users:.1f} personnes", ) bot.send( channel, @@ -100,7 +103,7 @@ class FinishReview: 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}", + f"comme nom de fichier {review_file}", ) bot.send(channel, "% Fin de la revue hebdomadaire") bot.send(bot.review.owner, "Revue finie.") diff --git a/hooks/input_participant.py b/hooks/input_participant.py new file mode 100644 index 0000000..4ea8eec --- /dev/null +++ b/hooks/input_participant.py @@ -0,0 +1,13 @@ +import logger + + +class InputParticipant: + def process(self, bot, channel, sender, message): + """ + Si le commentaire est ras, l'utilisateur est compté comme participant, + mais le message n'est pas considéré comme pris en compte. + """ + if message == "%ras" or message == "% ras": + logger.info("participant comment during review.") + + bot.review.add_participant(sender) diff --git a/review/review.py b/review/review.py index a51e5ef..48e507c 100644 --- a/review/review.py +++ b/review/review.py @@ -91,12 +91,20 @@ class Review: self.participants.append(sender) self.current_topic.add_message(sender, message) + def add_participant(self, sender): + if self.current_topic: + if sender not in self.participants: + self.participants.append(sender) + self.current_topic.add_participant(sender) + def start(self, owner): self.started = True + self.ended = False self.owner = owner self.start_time = datetime.today() def close(self): + self.started = False self.ended = True self.end_time = datetime.today() @@ -214,7 +222,7 @@ class Review: ) percentage = ( - stats.users_board.datas[self.user_count] / stats.users_board.sum * 100 + stats.users_board[self.user_count] / stats.users_board.sum * 100 ) content += fill( "Statistiques sur la participation à la revue " @@ -231,7 +239,7 @@ class Review: content += "\n" percentage = ( - stats.users_board.datas[self.user_count] / stats.users_board.sum * 100 + stats.users_board[self.user_count] / stats.users_board.sum * 100 ) content += fill( "Statistiques sur la durée de la revue " diff --git a/review/stats.py b/review/stats.py index e64ee57..89e341a 100644 --- a/review/stats.py +++ b/review/stats.py @@ -169,7 +169,7 @@ class ReviewStats: self.durations_board = DurationBoard(self.datas) def save(self): - with open(self.filepath, "wt") as file_handle: + with open(self.filepath, "w") as file_handle: for data in self.datas: file_handle.write( f"{data.date.strftime('%Y%m%d-%Hh%M')}\t" diff --git a/review/topic.py b/review/topic.py index 6b889c3..7b3a17c 100644 --- a/review/topic.py +++ b/review/topic.py @@ -36,6 +36,10 @@ class Topic: if sender not in self.participants: self.participants.append(sender) + def add_participant(self, sender): + if sender not in self.participants: + self.participants.append(sender) + def cancel_previous(self, author): messages = [message for message in self.messages if message.author == author] if len(messages) == 0: diff --git a/settings.py b/settings.py index 8f13a81..6759e82 100644 --- a/settings.py +++ b/settings.py @@ -13,7 +13,7 @@ LOGDATE = os.environ.get("LOGDATE", "%Y-%m-%d %H:%M:%S") # IRC configuration IRC_SERVER = os.environ.get("IRC_SERVER", "irc.libera.chat") IRC_PORT = int(os.environ.get("IRC_PORT", 6667)) -IRC_CHANNEL = os.environ.get("IRC_CHANNEL", " #april") +IRC_CHANNEL = os.environ.get("IRC_CHANNEL", " #april-test") IRC_NICK = os.environ.get("IRC_NICK", "Testbot") IRC_PASSWORD = os.environ.get("IRC_PASSWORD", " ") IRC_DELAY = float(os.environ.get("IRC_DELAY", 0.5)) # Délai entre plusieurs messages @@ -29,7 +29,7 @@ REVIEW_STATS = os.environ.get("REVIEW_STATS", os.path.join(REVIEW_DIRECTORY, "re # Pastebin PASTEBIN_URL = "https://paste.chapril.org/" # Values : 5min, 10min, 1hour, 1day, 1week, 1month, 1year, never -PASTEBIN_EXPIRATION = "5min" +PASTEBIN_EXPIRATION = "1week" # Cron CRON_REVIEW_REMINDERS = [(11, 45)] diff --git a/tests/datas/20240402-log-irc-revue-hebdomadaire.txt b/tests/datas/20240402-log-irc-revue-hebdomadaire.txt new file mode 100644 index 0000000..5885331 --- /dev/null +++ b/tests/datas/20240402-log-irc-revue-hebdomadaire.txt @@ -0,0 +1,57 @@ +================================================================================ + Revue de la semaine en cours + + mardi 02 avril 2024 +================================================================================ + + +================================================================================ + +--------------------------- Personnes participantes ---------------------------- +* Ccccc Ccccc (ccccc) + +================================================================================ + +----------------------------- Ccccc Ccccc (ccccc) ------------------------------ + +=== 1/ Actions passées ou en cours === + +* (09:59:32) lonugem: c'est cool quand « Libre à vous ! » comme ressource +argumentaire :) +https://pouet.april.org/@jonathangalou@mastodon.zaclys.com/112190112236507216 <- +<3 + + Log IRC brut + +* Hebdobot : % Début de la réunion hebdomadaire +* Hebdobot : % rappel : toute ligne commençant par % sera considérée comme un +commentaire et non prise en compte dans la synthèse +* Hebdobot : % pour connaître le point courant, taper !courant +* lllll : #1 +* Hebdobot : Sujet individuel : 1 +* Hebdobot : % si rien à signaler vous pouvez écrire % ras +* Hebdobot : % quand vous avez fini vous le dites par % fini +* lllll : %erreur :) +* lllll : # 1/ Actions passées ou en cours +* Hebdobot : % durée du point 1 : 0:00 +* Hebdobot : % , on va passer à la suite : 1/ Actions passées ou en cours +* Hebdobot : Sujet individuel : 1/ Actions passées ou en cours +* Hebdobot : % si rien à signaler vous pouvez écrire % ras +* Hebdobot : % quand vous avez fini vous le dites par % fini +* ccccc : (09:59:32) lonugem: c'est cool quand « Libre à vous ! » comme +ressource argumentaire :) +https://pouet.april.org/@jonathangalou@mastodon.zaclys.com/112190112236507216 <- +<3 +* lllll : # 2/ Actions à venir +* Hebdobot : % durée du point 1/ Actions passées ou en cours : 0:00 +* Hebdobot : % ccccc, on va passer à la suite : 2/ Actions à venir +* Hebdobot : Sujet individuel : 2/ Actions à venir +* Hebdobot : % si rien à signaler vous pouvez écrire % ras +* Hebdobot : % quand vous avez fini vous le dites par % fini +* lllll : !fin +* Hebdobot : % durée du point 2/ Actions à venir : 0:00 + + Statistiques + +C'était la 314e revue hebdomadaire de l'April, la 1e de l'année 2024. +Horaire de début de la revue : 09h59 diff --git a/tests/datas/irc_2.txt b/tests/datas/irc_2.txt new file mode 100644 index 0000000..fe09ab4 --- /dev/null +++ b/tests/datas/irc_2.txt @@ -0,0 +1,6 @@ +lllll : #1 +lllll : %erreur :) +lllll : # 1/ Actions passées ou en cours +ccccc : (09:59:32) lonugem: c'est cool quand « Libre à vous ! » comme ressource argumentaire :) https://pouet.april.org/@jonathangalou@mastodon.zaclys.com/112190112236507216 <- <3 +lllll : # 2/ Actions à venir +lllll : !fin diff --git a/tests/test_complete_review.py b/tests/test_complete_review.py index 00cede3..fc8527a 100644 --- a/tests/test_complete_review.py +++ b/tests/test_complete_review.py @@ -29,3 +29,26 @@ def test_complete_review(bot): with open("tests/reviews/20231201-log-irc-revue-hebdomadaire.txt") as file_handle: content_tested = file_handle.read() assert content_ok in content_tested + + +def test_other_review(bot): + with open("tests/datas/irc_2.txt") as file_handle: + content = file_handle.read().splitlines() + messages = [] + for line in content: + data = line.split(":") + author = data[0].strip() + text = ":".join(data[1:]).strip() + messages.append((author, text)) + + bot.test_public_message(bot.channel, "lllll", "!start") + bot.review.start_time = datetime(2024, 4, 2, 9, 59, 0) + for message in messages: + bot.test_public_message(bot.channel, message[0], message[1]) + + # compare contents + with open("tests/datas/20240402-log-irc-revue-hebdomadaire.txt") as file_handle: + content_ok = file_handle.read() + with open("tests/reviews/20240402-log-irc-revue-hebdomadaire.txt") as file_handle: + content_tested = file_handle.read() + assert content_ok in content_tested diff --git a/tests/test_review_hooks.py b/tests/test_review_hooks.py index a3f71dc..a1f5e80 100644 --- a/tests/test_review_hooks.py +++ b/tests/test_review_hooks.py @@ -424,6 +424,16 @@ def test_missing_no_one_is_missing(bot): assert bot.answers[0].message == "% Tout le monde s'est exprimé sur le sujet courant \\o/" +def test_missing_no_one_is_missing_through_ras(bot): + bot.test_public_message(bot.channel, OWNER, "!start") + bot.test_public_message(bot.channel, OWNER, "## collective topic") + bot.test_public_message(bot.channel, SENDER, "%ras") + bot.test_public_message(bot.channel, OWNER, "This is owner message") + bot.test_public_message(bot.channel, OWNER, "!manquantes") + assert len(bot.answers) == 1 + assert bot.answers[0].message == "% Tout le monde s'est exprimé sur le sujet courant \\o/" + + def test_missing_one_is_missing(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## collective topic") @@ -484,7 +494,7 @@ def test_finish_review_already_finished(bot): bot.test_public_message(bot.channel, OWNER, "!fin") bot.test_public_message(bot.channel, OWNER, "!fin") assert len(bot.answers) == 1 - assert bot.answers[0].message == "La revue est déjà finie." + assert bot.answers[0].message.endswith(", pas de revue en cours.") def test_finish_review_not_owner(bot):