From 43d450811c3cb2340feed826e637a78d58158610 Mon Sep 17 00:00:00 2001 From: lemoer Date: Sat, 28 Dec 2024 18:32:26 +0100 Subject: [PATCH] LabCleaningBot: send hint for pad to group --- main.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 874a8ec..0471b52 100644 --- a/main.py +++ b/main.py @@ -312,6 +312,12 @@ class LabCleaningBot: except websockets.exceptions.ConnectionClosed: print("Websockets connection closed. Reestablishing connection.") + def pad_hint(self, task: Task) -> str: + if task.pad_url is not None: + return "\n\nA list of the tasks is linked the description of the group or can be found here: " + task.pad_url + "." + else: + return "" + def message_received(self, message: Message, session: Session): # This method is called by the async receiver for each message envelope = message.envelope @@ -362,15 +368,17 @@ If due to any reason you can not participate, please just change your "👍" rea self.api.add_group_members(request.task.chatgroup, [source]) - number_of_additional_requests_to_be_sent = request.task.additional_requests_to_be_sent() + number_of_additional_people_needed = request.task.required_number_of_participants - len(request.task.accepted_requests()) - if number_of_additional_requests_to_be_sent < 0: + pad_hint = self.pad_hint(request.task) + + if number_of_additional_people_needed < 0: self.api.send_message(SendMessageSimple( - message="This task now has more participants than necessary. This can happen if a person has first rejected a request and then accepted it. You can handle this situation as you like.", + message="This task now has more participants than necessary. This can happen if a person has first rejected a request and then accepted it. You can handle this situation as you like." + pad_hint, recipients=[request.task.chatgroup])) - elif number_of_additional_requests_to_be_sent < 1: + elif number_of_additional_people_needed < 1: self.api.send_message(SendMessageSimple( - message="Enough participants have accepted the task. You can now start coordinating your task.", + message="Enough participants have accepted the task. You can now start coordinating your task." + pad_hint, recipients=[request.task.chatgroup])) case Err(AcceptAfterRejectExpired()): @@ -467,7 +475,7 @@ If due to any reason you can not participate, please just change your "👍" rea print("Could not fulfill task: " + task.name) additional_requested_users = [r.user.name for r in task.requested_requests()] - self.api.send_message(SendMessageSimple(message=f"It was planned to do this task with {task.required_number_of_participants} participants. There are currently {len(additional_requested_users)} unanswered requests. However, currently, no additional users are left to request for this task. Please try to fulfill the tasks as good as you are able to within your group or ask other people directly if they can join your group.", recipients=[task.chatgroup])) + self.api.send_message(SendMessageSimple(message=f"It was planned to do this task with {task.required_number_of_participants} participants. There are currently {len(additional_requested_users)} unanswered requests. However, currently, no additional users are left to request for this task. Please try to fulfill the tasks as good as you are able to within your group or ask other people directly if they can join your group." + self.pad_hint(task), recipients=[task.chatgroup])) unfulfillable_tasks.append(task)