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

+27
View File
@@ -389,6 +389,33 @@ def _fetch_item_texture(name):
return None
@app.route('/api/chat', methods=['POST'])
def api_chat():
origin = request.headers.get('Origin')
if origin:
from urllib.parse import urlparse
if urlparse(origin).netloc.lower() != request.host.lower():
return jsonify(ok=False, error='cross-origin chat actions are blocked'), 403
payload = request.get_json(silent=True)
if not isinstance(payload, dict):
return jsonify(ok=False, error='JSON body must be an object'), 400
message = payload.get('message')
if not isinstance(message, str):
return jsonify(ok=False, error='message must be a string'), 400
message = message.strip()
if not message:
return jsonify(ok=False, error='message cannot be empty'), 400
if len(message) > 256:
return jsonify(ok=False, error='message exceeds 256 characters'), 400
if not g.get('connected') or not g.get('chat'):
return jsonify(ok=False, error='bot is not connected'), 503
with g.reload_lock:
g.chat.send(message)
return jsonify(ok=True, command=message.startswith('/'))
@app.route('/api/item-icon/<name>')
def api_item_icon(name):
from mosfet.info.items import ITEM_NAMES