From 2742796fa48cabf000388f59afc5710bf679a1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Fri, 12 Jan 2018 16:49:29 +0100 Subject: [PATCH] More error messages. --- weechat-matrix.py | 68 ++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/weechat-matrix.py b/weechat-matrix.py index 7a09463..9da35b5 100644 --- a/weechat-matrix.py +++ b/weechat-matrix.py @@ -1314,6 +1314,13 @@ def check_server_existence(server_name, servers): def matrix_command_help(args): + if not args: + message = ("{prefix}matrix: Too few arguments for command " + "\"/matrix help\" (see the help for the command: " + "/matrix help help").format(prefix=W.prefix("error")) + W.prnt("", message) + return + for command in args: message = "" @@ -1405,6 +1412,8 @@ def matrix_command_help(args): W.prnt("", "") W.prnt("", message) + return + def matrix_server_command_listfull(args): def get_value_string(value, default_value): @@ -1708,13 +1717,16 @@ def matrix_command_cb(data, buffer, args): split_args = list(filter(bool, args.split(' '))) - command, args = split_args[0], split_args[1:] - - if not command: - # TODO print out error + if len(split_args) < 1: + message = ("{prefix}matrix: Too few arguments for command " + "\"/matrix\" (see the help for the command: " + "/help matrix").format(prefix=W.prefix("error")) + W.prnt("", message) return W.WEECHAT_RC_ERROR - elif command == 'connect': + command, args = split_args[0], split_args[1:] + + if command == 'connect': connect_server(args) elif command == 'disconnect': @@ -1828,31 +1840,33 @@ def matrix_command_topic_cb(data, buffer, command): if not topic: room = server.rooms[room_id] - if room.topic: - message = ("{prefix}Topic for {color}{room}{ncolor} is " - "\"{topic}\"").format( - prefix=W.prefix("network"), - color=W.color("chat_buffer"), - ncolor=W.color("reset"), - room=room.alias, - topic=room.topic) + if not room.topic: + return W.WEECHAT_RC_OK - date = int(time.time()) - topic_date = room.topic_date.strftime("%a, %d %b %Y " - "%H:%M:%S") + message = ("{prefix}Topic for {color}{room}{ncolor} is " + "\"{topic}\"").format( + prefix=W.prefix("network"), + color=W.color("chat_buffer"), + ncolor=W.color("reset"), + room=room.alias, + topic=room.topic) - tags = "matrix_topic,log1" - W.prnt_date_tags(buffer, date, tags, message) + date = int(time.time()) + topic_date = room.topic_date.strftime("%a, %d %b %Y " + "%H:%M:%S") - # TODO the nick should be colored - # TODO we should use the display name as well as - # the user name here - message = ("{prefix}Topic set by {author} on " - "{date}").format( - prefix=W.prefix("network"), - author=room.topic_author, - date=topic_date) - W.prnt_date_tags(buffer, date, tags, message) + tags = "matrix_topic,log1" + W.prnt_date_tags(buffer, date, tags, message) + + # TODO the nick should be colored + # TODO we should use the display name as well as + # the user name here + message = ("{prefix}Topic set by {author} on " + "{date}").format( + prefix=W.prefix("network"), + author=room.topic_author, + date=topic_date) + W.prnt_date_tags(buffer, date, tags, message) return W.WEECHAT_RC_OK_EAT