Add support for chat commands

This commit is contained in:
2020-09-08 17:51:27 -06:00
parent 100b4da80d
commit a76d02d53c
3 changed files with 70 additions and 18 deletions
+48
View File
@@ -1,8 +1,11 @@
import re
import time
import importlib
from panda3d.core import LPoint3f
from minecraft.networking.packets import Packet, clientbound, serverbound
import utils
importlib.reload(utils)
import path
@@ -47,3 +50,48 @@ def handle_position_and_look(packet, g):
print(packet)
p = LPoint3f(x=packet.x, y=packet.y, z=packet.z)
g.pos = p
def handle_chat(message, g):
source, text = message
reply = None
match = re.match(r'<(\w+)> (.*)', text)
if match:
sender, text = match.groups()
else:
return
if 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
if command == 'ping':
reply = 'pong'
if command == 'echo' and data:
reply = data
if command == 'respawn':
packet = serverbound.play.ClientStatusPacket()
packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN
g.connection.write_packet(packet)
reply = 'ok'
if command == 'pos':
reply = str(utils.pint(g.pos))[1:-1]
if command == 'afk':
reply = '/afk'
if reply:
print(reply)
g.chat.send(reply)