Refactor /cmd handling to be more extensible
This commit is contained in:
@@ -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
|
||||
# )
|
||||
|
||||
Reference in New Issue
Block a user