Ajout de la commande ! complet. Closes #12

This commit is contained in:
Mindiell 2024-10-09 18:25:35 +02:00
parent 65077926c6
commit 5c3080e289
4 changed files with 99 additions and 1 deletions

View File

@ -3,6 +3,7 @@ from .bad_command import BadCommand
from .cancel_previous_input import CancelPreviousInput from .cancel_previous_input import CancelPreviousInput
from .collective_subject import CollectiveSubject from .collective_subject import CollectiveSubject
from .comment import Comment from .comment import Comment
from .completion import Completion
from .chrono import Chrono from .chrono import Chrono
from .current import Current from .current import Current
from .date import Date from .date import Date
@ -36,6 +37,7 @@ hooks = (
Help(), Help(),
IndividualSubject(), IndividualSubject(),
Missing(), Missing(),
Completion(),
Record(), Record(),
StartReview(), StartReview(),
StopReview(), StopReview(),

44
hooks/completion.py Normal file
View File

@ -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

View File

@ -1,7 +1,7 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
import shutil import shutil
from tests.utils import bot, OWNER, SENDER from tests.utils import bot, OWNER, SENDER, SENDER_2
def setup_function(): def setup_function():
@ -515,3 +515,54 @@ def test_finish_review_no_participation(bot):
bot.test_public_message(bot.channel, OWNER, "!fin") bot.test_public_message(bot.channel, OWNER, "!fin")
assert len(bot.answers) == 1 assert len(bot.answers) == 1
assert bot.answers[0].message == "Participation nulle détectée. La revue est ignorée." 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:]

View File

@ -7,6 +7,7 @@ from tests import settings
OWNER = "me" OWNER = "me"
SENDER = "foobar" SENDER = "foobar"
SENDER_2 = "foobaz"
@dataclass @dataclass