Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions matrixcli
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ def get_parser():
parser.add_argument("-c", "--config", dest="config",
help="custom configuration file")

parser_register = subparsers.add_parser('register', help="Register a user")
parser_register.add_argument("-U", "--username", dest="username",
help="Username for user")
parser_register.add_argument("-P", "--password", dest="password",
help="Password for user")

parser_send = subparsers.add_parser('create', help='Create a room')
parser_send.add_argument("-n", "--name", dest="create_room",
help="Create a new room with the provided name")

parser_send = subparsers.add_parser('send', help='send something to a room')
group = parser_send.add_mutually_exclusive_group()
group.add_argument("-r", "--room-id", dest="room_id",
Expand All @@ -55,6 +65,9 @@ def get_parser():

parser_rooms = subparsers.add_parser('rooms',
help='get all joined rooms')
parser_join = subparsers.add_parser("join",
help="Join a room")
parser_join.add_argument("-a", "--room-alias", dest="room_alias", help="Specify the room by alias")

parser_unread = subparsers.add_parser('unread',
help='get unread notifications')
Expand Down Expand Up @@ -155,8 +168,8 @@ configuration file by trying to figure out what the user probably mean
password = config.accounts[indexes[0]]["passeval"]()
else:
for index in indexes:
if config.accounts[index]["server"] == args_server:
server = args_server
if config.accounts[index]["server"] == args.server:
server = args.server
password = config.accounts[index]["passeval"]()
break

Expand All @@ -174,7 +187,7 @@ configuration file by trying to figure out what the user probably mean
# arguments to be not None

if all([args.server, args.password, args.username]):
return args_server, args_username, args_password
return args.server, args.username, args.password
else :
print("config file with accounts list does not exist, you have to specify the --server, --username and --password \n" +
"error raised: {0}".format(err), file=sys.stderr)
Expand Down Expand Up @@ -267,12 +280,20 @@ def choose_room():
return room

def print_rooms():
print("{} rooms:".format(len(client.rooms)), flush=True)
enum_rooms = list(enumerate(client.rooms.items()))
for i, (k, v) in enum_rooms:
print(i, v.display_name , k, sep=" : ", flush=True)
print("", flush=True)
return enum_rooms

def join_room():
response = client.join_room('#' + args.room_alias.strip('#'))

def create_room():
response = client.create_room(args.create_room)
print(response.status_code)

def listen():
print("started listening ...", flush=True)
client.add_listener(listen_callback)
Expand Down Expand Up @@ -313,6 +334,11 @@ def tail():
msg = input()
room.send_text(msg)

def register():
response = client.register(username=args.register.username,
password=args.register.password)
print(response)

def unread_callback(dump1, dump2=False):
sleep(1) # a brief delay needed when we send messages
unread(oneshot=True)
Expand Down Expand Up @@ -352,6 +378,7 @@ def unread(oneshot=False):
#--------------------------------------------

args = get_parser().parse_args()

config, config_path = load_config()
server, username, password = config_vs_options()

Expand All @@ -362,7 +389,7 @@ while True:
try:
client = MatrixClient(server)
token = client.login(username,password)
api = MatrixHttpApi(server, token)
api = MatrixHttpApi(server, token, connection_timeout=120)
break
except matrix_client.errors.MatrixHttpLibError:
print('error connecting. retrying after 1 second...', file=sys.stderr)
Expand All @@ -375,6 +402,9 @@ subcommand = { "listen": listen,
"send": send,
"tail": tail,
"unread": unread,
"create": create_room,
"register": register,
"join": join_room,
None: print_rooms}

subcommand[args.subcommand]()
4 changes: 2 additions & 2 deletions python-sdk/matrix_client.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Communications :: Conferencing
Description-Content-Type: text/x-rst
Provides-Extra: test
Provides-Extra: doc
Provides-Extra: format
Provides-Extra: e2e
Provides-Extra: format
Provides-Extra: test
2 changes: 1 addition & 1 deletion python-sdk/matrix_client.egg-info/requires.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ sphinx-rtd-theme==0.1.9
sphinxcontrib-napoleon==0.5.3

[e2e]
python-olm@ git+https://github.com/poljar/python-olm.git@4752eb22f005cb9f6143857008572e6d83252841
canonicaljson
python-olm@ git+https://github.com/poljar/python-olm.git@4752eb22f005cb9f6143857008572e6d83252841

[format]
flake8
Expand Down