refactor(bot): improve code readability by reformatting
Refactor the ApplicationBot's methods for enhanced readability. This includes reformatting multiline structures and improving code consistency by adjusting indentation and ensuring uniform string formatting. These changes do not alter functionality but streamline future maintenance and readability. No functional impact or changes to logic were made.
This commit is contained in:
parent
ddc9b05fed
commit
ac18806308
1 changed files with 31 additions and 13 deletions
|
@ -97,9 +97,13 @@ class ApplicationBot:
|
|||
elif command.startswith("!supportbot close"):
|
||||
await self.close_ticket(room, sender, command)
|
||||
elif command.startswith("!supportbot approve"):
|
||||
await self.approve_or_reject_application(room, sender, command, approved=True)
|
||||
await self.approve_or_reject_application(
|
||||
room, sender, command, approved=True
|
||||
)
|
||||
elif command.startswith("!supportbot reject"):
|
||||
await self.approve_or_reject_application(room, sender, command, approved=False)
|
||||
await self.approve_or_reject_application(
|
||||
room, sender, command, approved=False
|
||||
)
|
||||
elif command == "!supportbot list":
|
||||
await self.list_tickets(room)
|
||||
elif command.startswith("!supportbot monitor"):
|
||||
|
@ -144,7 +148,11 @@ class ApplicationBot:
|
|||
await self.relay_message(room, sender, message_body)
|
||||
|
||||
async def approve_or_reject_application(self, room, sender, command, approved):
|
||||
user_id = command.split()[2] if len(command.split()) > 2 else await self.get_user_id_from_ticket_room(room.room_id)
|
||||
user_id = (
|
||||
command.split()[2]
|
||||
if len(command.split()) > 2
|
||||
else await self.get_user_id_from_ticket_room(room.room_id)
|
||||
)
|
||||
|
||||
if not user_id:
|
||||
await self.client.room_send(
|
||||
|
@ -163,7 +171,9 @@ class ApplicationBot:
|
|||
for protected_room in protected_rooms:
|
||||
invite_response = await self.client.room_invite(protected_room, user_id)
|
||||
if not isinstance(invite_response, RoomInviteResponse):
|
||||
logging.error(f"Failed to invite user {user_id} to protected room {protected_room}: {invite_response}")
|
||||
logging.error(
|
||||
f"Failed to invite user {user_id} to protected room {protected_room}: {invite_response}"
|
||||
)
|
||||
|
||||
await self.client.room_send(
|
||||
room.room_id,
|
||||
|
@ -188,7 +198,9 @@ class ApplicationBot:
|
|||
for monitored_room in monitored_rooms:
|
||||
kick_response = await self.client.room_kick(monitored_room, user_id)
|
||||
if not isinstance(kick_response, RoomKickResponse):
|
||||
logging.error(f"Failed to kick user {user_id} from monitored room {monitored_room}: {kick_response}")
|
||||
logging.error(
|
||||
f"Failed to kick user {user_id} from monitored room {monitored_room}: {kick_response}"
|
||||
)
|
||||
|
||||
async def get_user_id_from_ticket_room(self, room_id):
|
||||
# Find the user associated with the ticket id based on the room id
|
||||
|
@ -230,13 +242,13 @@ class ApplicationBot:
|
|||
await self.client.room_put_state(
|
||||
room_id=self.operator_room_id,
|
||||
event_type="m.room.monitored",
|
||||
content={"rooms": rooms}
|
||||
content={"rooms": rooms},
|
||||
)
|
||||
|
||||
async def list_monitored_rooms(self, room):
|
||||
monitored_rooms = await self.get_monitored_rooms()
|
||||
if monitored_rooms:
|
||||
rooms_list = ', '.join(monitored_rooms)
|
||||
rooms_list = ", ".join(monitored_rooms)
|
||||
await self.client.room_send(
|
||||
room.room_id,
|
||||
"m.room.message",
|
||||
|
@ -281,13 +293,13 @@ class ApplicationBot:
|
|||
await self.client.room_put_state(
|
||||
room_id=self.operator_room_id,
|
||||
event_type="m.room.protected",
|
||||
content={"rooms": rooms}
|
||||
content={"rooms": rooms},
|
||||
)
|
||||
|
||||
async def list_protected_rooms(self, room):
|
||||
protected_rooms = await self.get_protected_rooms()
|
||||
if protected_rooms:
|
||||
rooms_list = ', '.join(protected_rooms)
|
||||
rooms_list = ", ".join(protected_rooms)
|
||||
await self.client.room_send(
|
||||
room.room_id,
|
||||
"m.room.message",
|
||||
|
@ -430,13 +442,19 @@ class ApplicationBot:
|
|||
await self.client.room_send(
|
||||
operator_room_id,
|
||||
"m.room.message",
|
||||
{"msgtype": "m.text", "body": f"Application #{ticket_id} has been closed."},
|
||||
{
|
||||
"msgtype": "m.text",
|
||||
"body": f"Application #{ticket_id} has been closed.",
|
||||
},
|
||||
)
|
||||
else:
|
||||
await self.client.room_send(
|
||||
room.room_id,
|
||||
"m.room.message",
|
||||
{"msgtype": "m.text", "body": f"Application #{ticket_id} does not exist."},
|
||||
{
|
||||
"msgtype": "m.text",
|
||||
"body": f"Application #{ticket_id} does not exist.",
|
||||
},
|
||||
)
|
||||
|
||||
async def list_tickets(self, room):
|
||||
|
|
Loading…
Reference in a new issue