Refactor /cmd handling to be more extensible

This commit is contained in:
Tim Clifford
2023-11-04 23:30:02 +00:00
committed by Maze
parent 4de8e87f06
commit 7d6fba5ac7
2 changed files with 102 additions and 9 deletions

View File

@@ -541,3 +541,36 @@ class Keys:
# Sign out checked sessions if any, else sign out all sessions.
sign_out = ["Alt+S", "Delete"]
class Commands:
# If you are an advanced user, here you can define new /commands
#
# get_cmd_handler_map should return a dictionary of the form
# {
# "command": command_handling_function,
# "another_command": ...
# }
#
# each command_handling_function should have the signature:
#
# async def command_handling_function(
# matrix_client: moment.backend.MatrixClient,
# room_id: str,
# text: str, # text after the end of /command
# display_name_mentions: Optional[Dict[str, str]] = None, # {id: name}
# reply_to_event_id: Optional[str] = None,
# ) -> None:
# Example:
def get_cmd_handler_map(self):
return {
# "rot13 ": self.handle_cmd_rot13,
}
# @staticmethod
# def handle_cmd_rot13(matrix_client, room_id, text, display_name_mentions, reply_to_event_id):
# import codecs
# matrix_client._send_text(
# room_id, codecs.encode(text, 'rot_13'), display_name_mentions, reply_to_event_id
# )