Handle DMs, reply in DM

This commit is contained in:
Tanner
2026-11-04 18:09:36 +00:00
parent 23ecfa4446
commit 459e288407
4 changed files with 263 additions and 16 deletions
+14 -10
View File
@@ -20,8 +20,18 @@ class Commands:
self.g.chat.set_handler(self.handle_chat)
def _send_reply(self, reply, private=False, sender=None):
if private and not reply.startswith('/'):
if isinstance(sender, str) and re.fullmatch(r'[A-Za-z0-9_]{1,16}', sender):
self.g.chat.send('/msg {} {}'.format(sender, reply))
else:
self.g.chat.send('/r ' + reply)
else:
self.g.chat.send(reply)
def handle_chat(self, message):
source, sender, text = message
source, sender, text = message[:3]
reply_target = message[3] if len(message) > 3 else sender
reply = ''
private = False
for_me = False
@@ -46,7 +56,7 @@ class Commands:
else:
return
if '-> me' in meta:
if source == 'DM' or '-> me' in meta:
private = True
if prefix == bot_num:
@@ -64,10 +74,7 @@ class Commands:
(command == 'farm' and not data.lower().startswith('crop'))):
reply = 'not migrated to Minecraft 26.3 yet'
print('Reply:', reply)
if private:
self.g.chat.send('/r ' + reply)
else:
self.g.chat.send(reply)
self._send_reply(reply, private, reply_target)
return
try:
@@ -642,8 +649,5 @@ class Commands:
if len(reply) >= 256:
reply = 'reply too long, check console'
if private and not reply.startswith('/'):
self.g.chat.send('/r ' + reply)
else:
self.g.chat.send(reply)
self._send_reply(reply, private, reply_target)