LabCleaningBot: send hint for pad to group

This commit is contained in:
lemoer 2024-12-28 18:32:26 +01:00
parent b2800252cf
commit 43d450811c

20
main.py
View File

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