except MatrixRequestError as e: print(e) if e.code == 400: print("Room ID/Alias in the wrong format") sys.exit(11) else: print("Couldn't find room.") sys.exit(12) room.add_listener(on_message) client.start_listener_thread() while True: msg = samples_common.get_input() if msg == "/quit": break else: room.send_text(msg) if __name__ == '__main__': logging.basicConfig(level=logging.WARNING) host, username, password = samples_common.get_user_details(sys.argv) if len(sys.argv) > 4: room_id_alias = sys.argv[4] else: room_id_alias = samples_common.get_input("Room ID/Alias: ") main(host, username, password, room_id_alias)
# Get a users display name and avatar # Args: host:port username password user_id # Error Codes: # 2 - Could not find the server. # 3 - Bad URL Format. # 4 - Bad username/password. import sys import samples_common # Common bits used between samples from matrix_client.client import MatrixClient from matrix_client.api import MatrixRequestError from requests.exceptions import MissingSchema host, username, password = samples_common.get_user_details(sys.argv) client = MatrixClient(host) try: client.login_with_password(username, password) except MatrixRequestError as e: print(e) if e.code == 403: print("Bad username or password.") sys.exit(4) else: print("Check your sever details are correct.") sys.exit(2) except MissingSchema as e: print("Bad URL format.")
#!/usr/bin/env python3 """ This sample contains example code of how encryption can be used. It requires a room to be already created. """ import sys from samples_common import get_user_details, get_input from matrix_client.client import MatrixClient from matrix_client.errors import E2EUnknownDevices host, user_id, password = get_user_details(sys.argv) try: room_id = sys.argv[4] except: room_id = get_input("Room ID: ") ## Basic usage client = MatrixClient(host, encryption=True, restore_device_id=True) client.login(username=user_id, password=password) device_id = client.device_id room = client.join_room(room_id) if not room.encrypted: room.send_text("Unencrypted!") encrypted = room.enable_encryption() if encrypted: room.send_text("Encrypted!") else: