Add dashboard chat controls and suppress echoes

This commit is contained in:
Tanner committed 2026-11-17 00:37:14 +00:00
1 parent 5a3b299aa9
commit c3a045d17a
10 files changed
+178 -13

No files matched your search

+41 -1
View File
@@ -95,7 +95,7 @@ class TestWebInventoryAPI(unittest.TestCase):
key: self.g.get(key) for key in
('connected', 'game', 'inv', 'chest_viewers', 'time', 'time_base',
'weather', 'rain_level', 'thunder_level', 'chunks', 'pos', 'yaw',
'path', 'chat_log')
'path', 'chat_log', 'chat')
}
self.game = FakeGame()
self.g.connected = True
@@ -281,6 +281,46 @@ class TestWebInventoryAPI(unittest.TestCase):
'(12, 64, -7)': 1,
})
def test_chat_endpoint_sends_messages_and_slash_commands(self):
class FakeChat:
def __init__(self):
self.messages = []
def send(self, message):
self.messages.append(message)
chat = FakeChat()
self.g.chat = chat
message = self.client.post('/api/chat', json={
'message': 'hello from dashboard',
})
command = self.client.post('/api/chat', json={
'message': '/help',
})
self.assertEqual(message.status_code, 200)
self.assertFalse(message.get_json()['command'])
self.assertEqual(command.status_code, 200)
self.assertTrue(command.get_json()['command'])
self.assertEqual(chat.messages, ['hello from dashboard', '/help'])
def test_chat_endpoint_validates_input_and_rejects_cross_origin(self):
class FakeChat:
def send(self, _message):
raise AssertionError('invalid request must not be sent')
self.g.chat = FakeChat()
self.assertEqual(self.client.post('/api/chat', json={
'message': ' ',
}).status_code, 400)
self.assertEqual(self.client.post('/api/chat', json={
'message': 'x' * 257,
}).status_code, 400)
self.assertEqual(self.client.post('/api/chat', json={
'message': '/help',
}, headers={'Origin': 'https://elsewhere.example'}).status_code, 403)
def test_drop_endpoint_supports_one_stack_and_matching_actions(self):
one = self.client.post('/api/inventory/drop', json={
'slot': 9, 'action': 'one'})