Compare commits

..

No commits in common. "080895421d6466714cea1e16aaed65ad9d8c0524" and "ad6c412802a22ea6a21d0533f778ae1d0520da04" have entirely different histories.

3 changed files with 55 additions and 32 deletions

View File

@ -2,9 +2,9 @@
A general-purpose Minecraft 1.16 bot written in Python.
Mosfet is able to farm wood by cutting trees, farm crops, gather sand, farm
netherwart, and trade with villagers to get emeralds. He can eat, sleep, and
flee from threats.
Mosfet is able to farm wood by cutting trees, gather sand, gather netherwart,
and trade with villagers to get emeralds. He can eat, sleep, and flee from
threats.
## Requirements
- Python >= 3.6
@ -168,4 +168,4 @@ put to use.
## Acknowledgements
Thanks to Isaia, sose, and the devs behind pyCraft.
Thanks to Isaia and the devs behind pyCraft.

View File

@ -21,12 +21,11 @@ class Commands:
self.g.chat.set_handler(self.handle_chat)
def handle_chat(self, message):
source, sender, text = message
source, text = message
reply = None
private = False
for_me = False
authed = sender == '0c123cfa-1697-4427-9413-4b645dee7ec0'
bot_num = self.g.name[-1]
authed = False
if source == 'SYSTEM':
self.g.command_lock = False
@ -36,20 +35,40 @@ class Commands:
elif text == 'You are no longer AFK.':
self.g.afk = False
text = text.replace('zzz', '!zzz')
match = re.match(r'(.*\W+)\s+(['+bot_num+'|!])(\w+) ?(.*)', text)
if match:
meta, prefix, command, data = match.groups()
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()
private = True
else:
return
if '-> me' in meta:
private = True
if sender == 'tanner6':
authed = True
if prefix == bot_num:
if text.startswith('zzz'):
text = '!zzz'
bot_num = self.g.name[-1]
if text.startswith(bot_num):
text = text[1:]
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:
@ -372,9 +391,14 @@ 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:
if p.player_uuid == sender_uuid:
player = p
break
else: # for
@ -501,7 +525,7 @@ class Commands:
reply = 'reply too long, check console'
if private and not reply.startswith('/'):
self.g.chat.send('/r ' + reply)
self.g.chat.send('/m ' + sender + ' ' + reply)
else:
self.g.chat.send(reply)

View File

@ -161,25 +161,24 @@ class ChatManager:
def translate_chat(self, data):
if isinstance(data, str):
return data
result = data.get('text', '')
result += data.get('translate', '')
if 'with' in data:
result += ' ' + ' '.join([self.translate_chat(x) for x in data['with']])
elif 'extra' in data:
result += ''.join([self.translate_chat(x) for x in data['extra']])
return result
return ''.join([self.translate_chat(x) for x in data['extra']])
elif 'text' in data:
return data['text']
elif 'with' in data:
if len(data['with']) >= 2:
return '<{}> {}'.format(*[self.translate_chat(x) for x in data['with']])
else:
return self.translate_chat(data['with'][0])
elif 'translate' in data:
return data['translate']
else:
print(data)
return '?'
def print_chat(self, chat_packet):
#print(chat_packet)
#print(chat_packet.json_data)
#import json
#print(json.dumps(json.loads(chat_packet.json_data), indent=4))
try:
source = chat_packet.field_string('position')
sender = chat_packet.sender
text = self.translate_chat(json.loads(chat_packet.json_data))
print('[%s] %s'%(source, text))
except Exception as ex:
@ -187,7 +186,7 @@ class ChatManager:
return
if self.handler:
self.handler((source, sender, text))
self.handler((source, text))
def set_handler(self, func):
self.handler = func