From 6c3820c42f178a447a1cb3b2f83aa937ce4e11b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Tue, 16 Jul 2019 12:32:07 +0300 Subject: [PATCH] Make /status and /nick display your own if run with no arguments, and move listing of all peers to /peers --- ethermess.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/ethermess.py b/ethermess.py index 762d338..1c5c37d 100644 --- a/ethermess.py +++ b/ethermess.py @@ -230,17 +230,21 @@ def handle_user_command(backend, line): queue_message(backend, mac, message) elif command == '/status': - # Request status if rest != '': + # Request status mac = mac_from_name(rest) if mac in peers: print('%s === ~%s (%s) [%s]' % (timestamp(), peers[mac].nick, peers[mac].status.name, format_mac(mac))) send_status_request(backend, mac) else: - # List all the known peers - for mac, peer in peers.items(): - print('%s === ~%s (%s) [%s]' % (timestamp(), peer.nick, peer.status.name, format_mac(mac))) + # Show own + print('--- %s' % own_status.name) + + elif command == '/peers' and rest == '': + # List all the known peers + for mac, peer in peers.items(): + print('--- ~%s (%s) [%s]' % (timestamp(), peer.nick, peer.status.name, format_mac(mac))) elif command == '/available' and rest == '': # Set status to available @@ -253,11 +257,23 @@ def handle_user_command(backend, line): set_status_nick(backend, own_status, own_nick) elif command == '/nick': - # Change nick - validate_nick(rest) + if rest != '': + # Change nick + if rest[0] == '~': + # Remove the ~ from the front if it is there + nick = rest[1:] + else: + nick = rest - own_nick = rest - set_status_nick(backend, own_status, own_nick) + validate_nick(nick) + + own_nick = nick + + set_status_nick(backend, own_status, own_nick) + + else: + # Show own + print('--- ~%s' % own_nick) elif command == '/target': # Set default target of messages @@ -269,7 +285,7 @@ def handle_user_command(backend, line): else: # Display usage - print('--- / ; /msg ; /status []; /available; /unavailable; /nick ; /target ; /quit') + print('--- / ; /msg ; /status []; /peers; /available; /unavailable; /nick []; /target ; /quit') else: # Send message