diff --git a/hooks/__init__.py b/hooks/__init__.py index bb9b3be..0ab2c5a 100644 --- a/hooks/__init__.py +++ b/hooks/__init__.py @@ -3,6 +3,7 @@ from .bad_command import BadCommand from .cancel_previous_input import CancelPreviousInput from .collective_subject import CollectiveSubject from .comment import Comment +from .completion import Completion from .chrono import Chrono from .current import Current from .date import Date @@ -36,6 +37,7 @@ hooks = ( Help(), IndividualSubject(), Missing(), + Completion(), Record(), StartReview(), StopReview(), diff --git a/hooks/completion.py b/hooks/completion.py new file mode 100644 index 0000000..93b1046 --- /dev/null +++ b/hooks/completion.py @@ -0,0 +1,44 @@ +import logger + + +class Completion: + def process(self, bot, channel, sender, message): + """ + Si la commande est bonne, le bot renvoie la liste des personnes ayant participé + au sujet en cours mais n'ayant pas encore fini (commentaire %fini ou % fini). + """ + if message.lower() in ("!complet", ): + logger.info("!complet caught.") + + if not bot.review.is_started: + bot.send(channel, f"{sender}, pas de revue en cours.") + return True + + if bot.review.current_topic is None: + bot.send(channel, "% Pas de sujet en cours.") + return True + + participants = bot.review.current_topic.participants + find_text = f"# {bot.review.current_topic.title}" + if bot.review.current_topic.collective: + find_text = "#" + find_text + text_found = False + for message in bot.review.messages: + if text_found: + if message.text in ("%fini", "% fini", "%ras", "% ras"): + participants = list(set(participants) - set((message.author,))) + if find_text == message.text: + text_found = True + if participants == []: + bot.send( + channel, + "% Tout le monde a terminé de s'exprimer sur le sujet courant \\o/", + ) + else: + bot.send( + channel, + "% Personnes n'ayant pas encore terminé de s'exprimer sur le " + f"sujet courant : {', '.join(participants)}", + ) + + return True \ No newline at end of file diff --git a/tests/test_review_hooks.py b/tests/test_review_hooks.py index a1f5e80..2e858cc 100644 --- a/tests/test_review_hooks.py +++ b/tests/test_review_hooks.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta import shutil -from tests.utils import bot, OWNER, SENDER +from tests.utils import bot, OWNER, SENDER, SENDER_2 def setup_function(): @@ -515,3 +515,54 @@ def test_finish_review_no_participation(bot): bot.test_public_message(bot.channel, OWNER, "!fin") assert len(bot.answers) == 1 assert bot.answers[0].message == "Participation nulle détectée. La revue est ignorée." + + +def test_simple_completion_on_topic(bot): + bot.test_public_message(bot.channel, OWNER, "!start") + bot.test_public_message(bot.channel, OWNER, "# individual topic") + bot.test_public_message(bot.channel, OWNER, "Owner message on individual topic") + bot.test_public_message(bot.channel, SENDER, "Sender message on individual topic") + bot.test_public_message(bot.channel, SENDER_2, "Sender_2 message on individual topic") + bot.test_public_message(bot.channel, OWNER, "## collective topic") + bot.test_public_message(bot.channel, OWNER, "Owner message on collective topic") + bot.test_public_message(bot.channel, SENDER, "Sender message on collective topic") + bot.test_public_message(bot.channel, OWNER, "!complet") + assert len(bot.answers) == 1 + assert SENDER_2 not in bot.answers[0].message[76:] + assert SENDER in bot.answers[0].message[76:] + assert OWNER in bot.answers[0].message[76:] + +def test_semi_completion_on_topic(bot): + bot.test_public_message(bot.channel, OWNER, "!start") + bot.test_public_message(bot.channel, OWNER, "# individual topic") + bot.test_public_message(bot.channel, OWNER, "Owner message on individual topic") + bot.test_public_message(bot.channel, SENDER, "Sender message on individual topic") + bot.test_public_message(bot.channel, SENDER_2, "Sender_2 message on individual topic") + bot.test_public_message(bot.channel, OWNER, "## collective topic") + bot.test_public_message(bot.channel, OWNER, "Owner message on collective topic") + bot.test_public_message(bot.channel, SENDER, "Sender message on collective topic") + bot.test_public_message(bot.channel, SENDER_2, "%ras") + bot.test_public_message(bot.channel, SENDER, "%fini") + bot.test_public_message(bot.channel, OWNER, "!complet") + assert len(bot.answers) == 1 + assert SENDER_2 not in bot.answers[0].message[76:] + assert SENDER not in bot.answers[0].message[76:] + assert OWNER in bot.answers[0].message[76:] + +def test_total_completion_on_topic(bot): + bot.test_public_message(bot.channel, OWNER, "!start") + bot.test_public_message(bot.channel, OWNER, "# individual topic") + bot.test_public_message(bot.channel, OWNER, "Owner message on individual topic") + bot.test_public_message(bot.channel, SENDER, "Sender message on individual topic") + bot.test_public_message(bot.channel, SENDER_2, "Sender_2 message on individual topic") + bot.test_public_message(bot.channel, OWNER, "## collective topic") + bot.test_public_message(bot.channel, OWNER, "Owner message on collective topic") + bot.test_public_message(bot.channel, SENDER, "Sender message on collective topic") + bot.test_public_message(bot.channel, SENDER_2, "%ras") + bot.test_public_message(bot.channel, SENDER, "%fini") + bot.test_public_message(bot.channel, OWNER, "% fini") + bot.test_public_message(bot.channel, OWNER, "!complet") + assert len(bot.answers) == 1 + assert SENDER_2 + "," not in bot.answers[0].message[76:] + assert SENDER + "," not in bot.answers[0].message[76:] + assert OWNER + "," not in bot.answers[0].message[76:] diff --git a/tests/utils.py b/tests/utils.py index 6d6fb71..f68b1c0 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -7,6 +7,7 @@ from tests import settings OWNER = "me" SENDER = "foobar" +SENDER_2 = "foobaz" @dataclass