Create a concept of default target for messages

This commit is contained in:
Juhani Krekelä 2019-07-14 23:34:40 +03:00
parent 80b91d872d
commit 97d42bce52
1 changed files with 20 additions and 4 deletions

View File

@ -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 <MAC> <message>; /status <MAC>; /available; /unavailable; /nick')
print('--- / <message>; /msg <MAC> <message>; /status <MAC>; /available; /unavailable; /nick <nick>; /target <MAC>')
else:
# Display usage
print('/msg <MAC> <message>; /status <MAC>; /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