Improve parsing chat commands
This commit is contained in:
+15
-39
@@ -21,11 +21,12 @@ class Commands:
|
||||
self.g.chat.set_handler(self.handle_chat)
|
||||
|
||||
def handle_chat(self, message):
|
||||
source, text = message
|
||||
source, sender, text = message
|
||||
reply = None
|
||||
private = False
|
||||
for_me = False
|
||||
authed = False
|
||||
authed = sender == '0c123cfa-1697-4427-9413-4b645dee7ec0'
|
||||
bot_num = self.g.name[-1]
|
||||
|
||||
if source == 'SYSTEM':
|
||||
self.g.command_lock = False
|
||||
@@ -35,40 +36,20 @@ class Commands:
|
||||
elif text == 'You are no longer AFK.':
|
||||
self.g.afk = False
|
||||
|
||||
match1 = re.match(r'.*<(\w+)> (.*)', text)
|
||||
match2 = re.match(r'\[(\w+) -> me] (.*)', text)
|
||||
if match1:
|
||||
sender, text = match1.groups()
|
||||
elif match2:
|
||||
sender, text = match2.groups()
|
||||
text = text.replace('zzz', '!zzz')
|
||||
|
||||
match = re.match(r'(.*\W+)\s+(['+bot_num+'|!])(\w+) ?(.*)', text)
|
||||
if match:
|
||||
meta, prefix, command, data = match.groups()
|
||||
else:
|
||||
return
|
||||
|
||||
if '-> me' in meta:
|
||||
private = True
|
||||
else:
|
||||
return
|
||||
|
||||
if sender == 'tanner6':
|
||||
authed = True
|
||||
|
||||
if text.startswith('zzz'):
|
||||
text = '!zzz'
|
||||
|
||||
bot_num = self.g.name[-1]
|
||||
|
||||
if text.startswith(bot_num):
|
||||
text = text[1:]
|
||||
if prefix == bot_num:
|
||||
for_me = True
|
||||
elif text.startswith('! '):
|
||||
text = text[2:]
|
||||
elif text.startswith('!'):
|
||||
text = text[1:]
|
||||
else:
|
||||
return
|
||||
|
||||
if ' ' in text:
|
||||
command = text.split(' ', 1)[0]
|
||||
data = text.split(' ', 1)[1]
|
||||
else:
|
||||
command = text
|
||||
data = None
|
||||
|
||||
try:
|
||||
|
||||
@@ -391,14 +372,9 @@ class Commands:
|
||||
|
||||
## 1here - bot comes to your location
|
||||
if command == 'here':
|
||||
try:
|
||||
sender_uuid = self.g.player_names[sender]
|
||||
except KeyError:
|
||||
reply = 'can\'t find your uuid'
|
||||
|
||||
if not reply:
|
||||
for p in self.g.players.values():
|
||||
if p.player_uuid == sender_uuid:
|
||||
if p.player_uuid == sender:
|
||||
player = p
|
||||
break
|
||||
else: # for
|
||||
@@ -525,7 +501,7 @@ class Commands:
|
||||
reply = 'reply too long, check console'
|
||||
|
||||
if private and not reply.startswith('/'):
|
||||
self.g.chat.send('/m ' + sender + ' ' + reply)
|
||||
self.g.chat.send('/r ' + reply)
|
||||
else:
|
||||
self.g.chat.send(reply)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user