Create a concept of default target for messages
This commit is contained in:
parent
80b91d872d
commit
97d42bce52
24
ethermess.py
24
ethermess.py
|
@ -8,6 +8,8 @@ import sys
|
||||||
own_nick = None
|
own_nick = None
|
||||||
own_status = None
|
own_status = None
|
||||||
|
|
||||||
|
default_target_mac = None
|
||||||
|
|
||||||
def writeall(f, b):
|
def writeall(f, b):
|
||||||
written = 0
|
written = 0
|
||||||
while written < len(b):
|
while written < len(b):
|
||||||
|
@ -64,10 +66,18 @@ def set_status_nick(backend, status, nick):
|
||||||
|
|
||||||
def handle_user_command(backend, line):
|
def handle_user_command(backend, line):
|
||||||
global own_nick, own_status
|
global own_nick, own_status
|
||||||
|
global default_target_mac
|
||||||
|
|
||||||
if len(line) > 0 and line[0] == '/':
|
if len(line) > 0 and line[0] == '/':
|
||||||
command, _, rest = line.partition(' ')
|
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
|
# Send message to target
|
||||||
mac_str, _, message = rest.partition(' ')
|
mac_str, _, message = rest.partition(' ')
|
||||||
mac = parse_mac(mac_str)
|
mac = parse_mac(mac_str)
|
||||||
|
@ -90,13 +100,19 @@ def handle_user_command(backend, line):
|
||||||
own_nick = rest
|
own_nick = rest
|
||||||
set_status_nick(backend, own_status, own_nick)
|
set_status_nick(backend, own_status, own_nick)
|
||||||
|
|
||||||
|
elif command == '/target':
|
||||||
|
default_target_mac = parse_mac(rest)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Display usage
|
# 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:
|
else:
|
||||||
# Display usage
|
# Send message
|
||||||
print('/msg <MAC> <message>; /status <MAC>; /available; /unavailable; /nick')
|
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):
|
def eventloop(proc):
|
||||||
# Create unbuffered version of stdin
|
# Create unbuffered version of stdin
|
||||||
|
|
Loading…
Reference in New Issue