forked from LeineLab-Public/lab-signal-bot
SignalAPI: return Err() instead of None for all methods
This commit is contained in:
parent
fb994d1a5e
commit
37a8fb6f9c
27
main.py
27
main.py
@ -37,8 +37,7 @@ class SignalAPI:
|
|||||||
if r.status_code == 201:
|
if r.status_code == 201:
|
||||||
return parse_response(UsernameSetResponse, r.text)
|
return parse_response(UsernameSetResponse, r.text)
|
||||||
else:
|
else:
|
||||||
print("Failed to set username")
|
return Err("Failed to set username.")
|
||||||
print(r.json())
|
|
||||||
|
|
||||||
def get_groups(self) -> Result[List[GroupEntry], str]:
|
def get_groups(self) -> Result[List[GroupEntry], str]:
|
||||||
# get request to get groups
|
# get request to get groups
|
||||||
@ -48,8 +47,7 @@ class SignalAPI:
|
|||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
return parse_response(List[GroupEntry], r.text)
|
return parse_response(List[GroupEntry], r.text)
|
||||||
else:
|
else:
|
||||||
print("Failed to get groups")
|
return Err("Failed to get groups.")
|
||||||
print(r.json())
|
|
||||||
|
|
||||||
def get_group(self, group_id: str) -> Result[GroupEntry, str]:
|
def get_group(self, group_id: str) -> Result[GroupEntry, str]:
|
||||||
# get request to get group
|
# get request to get group
|
||||||
@ -59,8 +57,7 @@ class SignalAPI:
|
|||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
return parse_response(GroupEntry, r.text)
|
return parse_response(GroupEntry, r.text)
|
||||||
else:
|
else:
|
||||||
print("Failed to get group")
|
return Err("Failed to get group.")
|
||||||
print(r.json())
|
|
||||||
|
|
||||||
def create_group(self, group_request: CreateGroupRequest) -> Result[CreateGroupResponse, str]:
|
def create_group(self, group_request: CreateGroupRequest) -> Result[CreateGroupResponse, str]:
|
||||||
r = requests.post(f"{self.apiurl}/v1/groups/{self.number}", json=group_request.model_dump())
|
r = requests.post(f"{self.apiurl}/v1/groups/{self.number}", json=group_request.model_dump())
|
||||||
@ -68,8 +65,7 @@ class SignalAPI:
|
|||||||
if r.status_code == 201:
|
if r.status_code == 201:
|
||||||
return parse_response(CreateGroupResponse, r.text)
|
return parse_response(CreateGroupResponse, r.text)
|
||||||
else:
|
else:
|
||||||
print("Failed to create group")
|
return Err("Failed to create group.")
|
||||||
print(r.json())
|
|
||||||
|
|
||||||
def add_group_members(self, group_id: str, numbers_to_add: List[str]) -> Result[None, str]:
|
def add_group_members(self, group_id: str, numbers_to_add: List[str]) -> Result[None, str]:
|
||||||
# put request to add group members
|
# put request to add group members
|
||||||
@ -82,8 +78,7 @@ class SignalAPI:
|
|||||||
if r.status_code == 204:
|
if r.status_code == 204:
|
||||||
return Ok(None)
|
return Ok(None)
|
||||||
else:
|
else:
|
||||||
print("Failed to add group members")
|
return Err("Failed to add group members.")
|
||||||
print(r.json())
|
|
||||||
|
|
||||||
def remove_group_members(self, group_id: str, numbers_to_remove: List[str]) -> Result[None, str]:
|
def remove_group_members(self, group_id: str, numbers_to_remove: List[str]) -> Result[None, str]:
|
||||||
# delete request to remove group members
|
# delete request to remove group members
|
||||||
@ -96,8 +91,7 @@ class SignalAPI:
|
|||||||
if r.status_code == 204:
|
if r.status_code == 204:
|
||||||
return Ok(None)
|
return Ok(None)
|
||||||
else:
|
else:
|
||||||
print("Failed to remove group members")
|
return Err("Failed to remove group members.")
|
||||||
print(r.json())
|
|
||||||
|
|
||||||
def update_group_members(self, group_id: str, other_members: List[str]) -> Result[UpdateGroupResult, str]:
|
def update_group_members(self, group_id: str, other_members: List[str]) -> Result[UpdateGroupResult, str]:
|
||||||
group = self.get_group(group_id)
|
group = self.get_group(group_id)
|
||||||
@ -138,8 +132,7 @@ class SignalAPI:
|
|||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
return parse_response(List[IdentityEntry], r.text)
|
return parse_response(List[IdentityEntry], r.text)
|
||||||
else:
|
else:
|
||||||
print("Failed to get identities")
|
return Err("Failed to get identities.")
|
||||||
print(r.json())
|
|
||||||
|
|
||||||
# /v1/identities/{number}/trust/{numberToTrust}
|
# /v1/identities/{number}/trust/{numberToTrust}
|
||||||
def trust_identity(self, number_to_trust: str, trust_identity_request: TrustIdentityRequest) -> Result[None, str]:
|
def trust_identity(self, number_to_trust: str, trust_identity_request: TrustIdentityRequest) -> Result[None, str]:
|
||||||
@ -148,8 +141,7 @@ class SignalAPI:
|
|||||||
if r.status_code == 204:
|
if r.status_code == 204:
|
||||||
return Ok(None)
|
return Ok(None)
|
||||||
else:
|
else:
|
||||||
print("Failed to trust identity")
|
return Err("Failed to trust identity.")
|
||||||
print(r.text)
|
|
||||||
|
|
||||||
async def websocket_connect_receive(self):
|
async def websocket_connect_receive(self):
|
||||||
ws_url = self.apiurl.replace("http", "ws")
|
ws_url = self.apiurl.replace("http", "ws")
|
||||||
@ -167,8 +159,7 @@ class SignalAPI:
|
|||||||
if r.status_code == 201:
|
if r.status_code == 201:
|
||||||
return parse_response(SendMessageResponse, r.text)
|
return parse_response(SendMessageResponse, r.text)
|
||||||
else:
|
else:
|
||||||
print("Failed to send message")
|
return Err("Failed to send message")
|
||||||
print(r.text)
|
|
||||||
|
|
||||||
|
|
||||||
class LabCleaningBot:
|
class LabCleaningBot:
|
||||||
|
Loading…
Reference in New Issue
Block a user