From 97d42bce5215d8aa8395368d53eb20c630ecc976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sun, 14 Jul 2019 23:34:40 +0300 Subject: [PATCH] Create a concept of default target for messages --- ethermess.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ethermess.py b/ethermess.py index 2a41ce3..b56e19f 100644 --- a/ethermess.py +++ b/ethermess.py @@ -8,6 +8,8 @@ import sys own_nick = None own_status = None +default_target_mac = None + def writeall(f, b): written = 0 while written < len(b): @@ -64,10 +66,18 @@ def set_status_nick(backend, status, nick): def handle_user_command(backend, line): global own_nick, own_status + global default_target_mac if len(line) > 0 and line[0] == '/': command, _, rest = line.partition(' ') - if command == '/msg': + if command == '/': + # Send quoted message + if default_target_mac is None: + print('--- Default target not set, set with /target') + else: + send_message(backend, default_target_mac, rest) + + elif command == '/msg': # Send message to target mac_str, _, message = rest.partition(' ') mac = parse_mac(mac_str) @@ -90,13 +100,19 @@ def handle_user_command(backend, line): own_nick = rest set_status_nick(backend, own_status, own_nick) + elif command == '/target': + default_target_mac = parse_mac(rest) + else: # Display usage - print('/msg ; /status ; /available; /unavailable; /nick') + print('--- / ; /msg ; /status ; /available; /unavailable; /nick ; /target ') else: - # Display usage - print('/msg ; /status ; /available; /unavailable; /nick') + # Send message + if default_target_mac is None: + print('--- Default target not set, set with /target') + else: + send_message(backend, default_target_mac, line) def eventloop(proc): # Create unbuffered version of stdin