Add /api/mc/login endpoint for Minecraft mod auth
This commit is contained in:
@@ -584,6 +584,38 @@ def _resolve_guild_id() -> str:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Routes — Minecraft Mod API
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@app.route("/api/mc/login", methods=["POST"])
|
||||||
|
def api_mc_login():
|
||||||
|
"""Minecraft mod login endpoint. Accepts JSON {"token": "..."} and returns user info + voices."""
|
||||||
|
data = request.get_json(force=True) if request.is_json else {}
|
||||||
|
token = data.get("token", "").strip()
|
||||||
|
if not token:
|
||||||
|
return jsonify({"error": "Missing token"}), 400
|
||||||
|
|
||||||
|
entry = consume_login_token(token)
|
||||||
|
if not entry:
|
||||||
|
return jsonify({"error": "Invalid or expired token. Run [p]ttstoy login in Discord."}), 401
|
||||||
|
|
||||||
|
user_id = entry["user_id"]
|
||||||
|
ucfg = get_user_config(user_id)
|
||||||
|
voices = ucfg.get("chatterbox_voices", [])
|
||||||
|
result = []
|
||||||
|
for v in voices:
|
||||||
|
parts = v.split("_", 1)
|
||||||
|
display = parts[1].rsplit(".", 1)[0] if len(parts) > 1 else v.rsplit(".", 1)[0]
|
||||||
|
result.append({"filename": v, "display": display})
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"user_id": user_id,
|
||||||
|
"discord_name": entry.get("discord_name", "Unknown"),
|
||||||
|
"voices": result,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Routes — Chatterbox voice management
|
# Routes — Chatterbox voice management
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user