forked from LeineLab-Public/lab-signal-bot
LabCleaningBot: add create_or_update_task_group()
This commit is contained in:
parent
669787bbce
commit
6fa7cf5766
25
main.py
25
main.py
@ -379,6 +379,30 @@ class LabCleaningBot:
|
|||||||
|
|
||||||
print(emoji, "direct", sourceNumber, isRemove)
|
print(emoji, "direct", sourceNumber, isRemove)
|
||||||
|
|
||||||
|
def create_or_update_task_group(self, task: Task) -> Result[str, str]:
|
||||||
|
chatgroup = task.chatgroup
|
||||||
|
|
||||||
|
# Check if the group still exists
|
||||||
|
if chatgroup is not None:
|
||||||
|
info = self.api.get_group(chatgroup)
|
||||||
|
|
||||||
|
if is_err(info):
|
||||||
|
# group does not exist (or so...)
|
||||||
|
print(info.unwrap_err())
|
||||||
|
chatgroup = None
|
||||||
|
|
||||||
|
# Create a group for the task if it does not exist
|
||||||
|
if chatgroup is None:
|
||||||
|
create_result = self.api.create_group(CreateGroupRequest(name=task.name, members=[self.api.number]))
|
||||||
|
|
||||||
|
if is_err(create_result):
|
||||||
|
return Err(create_result.unwrap_err())
|
||||||
|
else:
|
||||||
|
chatgroup = create_result.unwrap().id
|
||||||
|
|
||||||
|
task.chatgroup = chatgroup
|
||||||
|
self.api.update_group_members(chatgroup, [r.user.name for r in task.accepted_requests()])
|
||||||
|
|
||||||
async def sync_members_and_tasks(self, session: Session):
|
async def sync_members_and_tasks(self, session: Session):
|
||||||
# Async routine that syncs active members using sync_members_as_active_users(),
|
# Async routine that syncs active members using sync_members_as_active_users(),
|
||||||
# sends out new requests for tasks to active users and handles timeouts for the
|
# sends out new requests for tasks to active users and handles timeouts for the
|
||||||
@ -435,6 +459,7 @@ You have time to answer for {format_seconds(task.timeout)}."""
|
|||||||
recipients=[request.user.name])
|
recipients=[request.user.name])
|
||||||
res = self.api.send_message(message)
|
res = self.api.send_message(message)
|
||||||
|
|
||||||
|
self.create_or_update_task_group(task)
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
@ -84,6 +84,7 @@ class Task(SQLModel, table=True):
|
|||||||
required_number_of_participants: int
|
required_number_of_participants: int
|
||||||
due: datetime.datetime
|
due: datetime.datetime
|
||||||
timeout: int # in seconds
|
timeout: int # in seconds
|
||||||
|
chatgroup: str | None = None # None = to be created
|
||||||
|
|
||||||
participation_requests: list["ParticipationRequest"] = Relationship(back_populates="task")
|
participation_requests: list["ParticipationRequest"] = Relationship(back_populates="task")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user