From 9ec684d3451c66221f8c5589b828c40ddb73b2a8 Mon Sep 17 00:00:00 2001 From: lemoer Date: Fri, 27 Dec 2024 20:14:39 +0100 Subject: [PATCH] main: better task invite message --- main.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9ee3b94..9c6cb47 100644 --- a/main.py +++ b/main.py @@ -40,6 +40,18 @@ def necessary_changes(current: List[T], desired: List[T]) -> Changes[T]: return changes +def format_seconds(seconds: float) -> str: + seconds = int(seconds) + + if seconds < 60: + return f"{seconds} seconds" + elif seconds < 3600: + return f"{seconds//60} minutes" + elif seconds < 86400: + return f"{seconds//3600} hours" + else: + return f"{seconds//86400} days" + class SignalAPI: def __init__(self, apiurl, number): @@ -396,7 +408,16 @@ class LabCleaningBot: reqs = reqs.unwrap() for request in reqs: - message = SendMessageSimple(message=task.name, recipients=[request.user.name]) + seconds_to_due = (task.due - request.requested_at).total_seconds() + text = f"""Hi! + +You have been requested to participate in the task: {task.name} (starts in {format_seconds(seconds_to_due)}). + +To accept the request, react with 👍. To reject, react with any other emoji. + +You have time to answer for {format_seconds(task.timeout)}.""" + + message = SendMessageSimple(message=text, recipients=[request.user.name]) res = self.api.send_message(message) if is_ok(res):