fix: handle unknown commands and correct async indentation errors
Added a response for unknown commands to guide users on valid usage, improving user experience and preventing misuse. Fixed indentation for async functions to ensure correct code execution. These changes address issues with command handling and function performance.
This commit is contained in:
parent
840ae90376
commit
309e4968c3
1 changed files with 44 additions and 36 deletions
16
bot.py
16
bot.py
|
@ -48,6 +48,11 @@ class RoombaBot:
|
|||
await self.block_room(event.body.split()[2], True)
|
||||
elif event.body.startswith("!roomba unblock"):
|
||||
await self.block_room(event.body.split()[2], False)
|
||||
elif event.body.startswith("!roomba "):
|
||||
await self.send_message(
|
||||
self.moderation_room_id,
|
||||
"Unknown command. Use '!roomba block <room_id>' or '!roomba unblock <room_id>'.",
|
||||
)
|
||||
|
||||
async def block_room(self, room_id, block):
|
||||
"""Block or unblock a room.
|
||||
|
@ -84,8 +89,7 @@ class RoombaBot:
|
|||
f"Failed to {'block' if block else 'unblock'} room {room_id}.",
|
||||
)
|
||||
|
||||
|
||||
async def get_local_users(self, room_id):
|
||||
async def get_local_users(self, room_id):
|
||||
"""Get the local users in a room.
|
||||
|
||||
Args:
|
||||
|
@ -94,7 +98,9 @@ async def get_local_users(self, room_id):
|
|||
Returns:
|
||||
list: The list of local users in the room.
|
||||
"""
|
||||
members_url = f"{self.client.homeserver}/_matrix/client/r0/rooms/{room_id}/members"
|
||||
members_url = (
|
||||
f"{self.client.homeserver}/_matrix/client/r0/rooms/{room_id}/members"
|
||||
)
|
||||
headers = {
|
||||
"Authorization": f"Bearer {self.client.access_token}",
|
||||
"Content-Type": "application/json",
|
||||
|
@ -108,7 +114,9 @@ async def get_local_users(self, room_id):
|
|||
members = await resp.json()
|
||||
for member in members.get("chunk", []):
|
||||
user_id = member.get("user_id")
|
||||
if user_id and user_id.endswith(self.client.user_id.split(":")[1]):
|
||||
if user_id and user_id.endswith(
|
||||
self.client.user_id.split(":")[1]
|
||||
):
|
||||
local_users.append(user_id)
|
||||
return local_users
|
||||
|
||||
|
|
Loading…
Reference in a new issue