forked from LeineLab-Public/lab-signal-bot
LabCleaningBot: some docstrings for the methods
This commit is contained in:
parent
e07c3bc4e6
commit
1f22182c72
10
main.py
10
main.py
@ -170,6 +170,7 @@ class LabCleaningBot:
|
|||||||
self.base_group = base_group
|
self.base_group = base_group
|
||||||
|
|
||||||
def get_other_members(self) -> Result[List[str], str]:
|
def get_other_members(self) -> Result[List[str], str]:
|
||||||
|
# Get all members of the base group except the bot
|
||||||
group = self.api.get_group(self.base_group)
|
group = self.api.get_group(self.base_group)
|
||||||
if group.is_err():
|
if group.is_err():
|
||||||
return Err(group.unwrap_err())
|
return Err(group.unwrap_err())
|
||||||
@ -184,6 +185,8 @@ class LabCleaningBot:
|
|||||||
return Ok(other_members)
|
return Ok(other_members)
|
||||||
|
|
||||||
def sync_members_as_active_users(self, session) -> Result[None, str]:
|
def sync_members_as_active_users(self, session) -> Result[None, str]:
|
||||||
|
# Get all members of the base group and set them as active users
|
||||||
|
# if they are not already in the database
|
||||||
maybe_members = self.get_other_members()
|
maybe_members = self.get_other_members()
|
||||||
|
|
||||||
if is_err(maybe_members):
|
if is_err(maybe_members):
|
||||||
@ -209,10 +212,13 @@ class LabCleaningBot:
|
|||||||
return Ok(None)
|
return Ok(None)
|
||||||
|
|
||||||
def send_to_base_group(self, message: str) -> Result[None, str]:
|
def send_to_base_group(self, message: str) -> Result[None, str]:
|
||||||
|
# Send a message to the base group
|
||||||
message = SendMessageSimple(message=message, recipients=[self.base_group])
|
message = SendMessageSimple(message=message, recipients=[self.base_group])
|
||||||
return self.api.send_message(message)
|
return self.api.send_message(message)
|
||||||
|
|
||||||
async def receiver(self, session: Session):
|
async def receiver(self, session: Session):
|
||||||
|
# Async routine that receives messages and calles message_received() for
|
||||||
|
# each message
|
||||||
async for websocket in self.api.websocket_connect_receive():
|
async for websocket in self.api.websocket_connect_receive():
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
@ -230,6 +236,7 @@ class LabCleaningBot:
|
|||||||
print("Websockets connection closed. Reestablishing connection.")
|
print("Websockets connection closed. Reestablishing connection.")
|
||||||
|
|
||||||
def message_received(self, message: Message, session: Session):
|
def message_received(self, message: Message, session: Session):
|
||||||
|
# This method is called by the async receiver for each message
|
||||||
envelope = message.envelope
|
envelope = message.envelope
|
||||||
|
|
||||||
match envelope:
|
match envelope:
|
||||||
@ -298,6 +305,9 @@ class LabCleaningBot:
|
|||||||
print(emoji, "direct", sourceNumber, isRemove)
|
print(emoji, "direct", sourceNumber, isRemove)
|
||||||
|
|
||||||
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(),
|
||||||
|
# sends out new requests for tasks to active users and handles timeouts for the
|
||||||
|
# requests.
|
||||||
unfulfillable_tasks = []
|
unfulfillable_tasks = []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
Loading…
Reference in New Issue
Block a user