#!/usr/bin/env python3
# =============================================================
# set_commands.py — Iestata Telegram komandu izvēlni
# Palaid: cPanel → Python App → Execute python script
# =============================================================

import os
import requests
from pathlib import Path

# Ielādē .env
env_path = Path(__file__).resolve().parent / ".env"
if env_path.exists():
    with open(env_path) as f:
        for line in f:
            line = line.strip()
            if line and not line.startswith("#") and "=" in line:
                key, _, val = line.partition("=")
                os.environ.setdefault(key.strip(), val.strip())

TOKEN = os.getenv("TELEGRAM_BOT_TOKEN", "")
BASE  = f"https://api.telegram.org/bot{TOKEN}"

# ── KOMANDU SARAKSTS ──────────────────────────────────────────
COMMANDS = [
    {"command": "start",      "description": "🏠 Sākums un galvenā izvēlne"},
    {"command": "komandas",   "description": "📋 Visu komandu saraksts"},
    {"command": "ai",         "description": "🤖 Kas ir mākslīgais intelekts"},
    {"command": "aiakts",     "description": "🇪🇺 ES AI Akts un regulējums"},
    {"command": "drosha",     "description": "🛡️ AI drošība un ētika"},
    {"command": "bizness",    "description": "💼 AI pielietojums biznesā"},
    {"command": "modeli",     "description": "🧠 Vadošie AI modeļi (Gemini, GPT...)"},
    {"command": "riki",       "description": "🛠️ Noderīgi AI rīki pa kategorijām"},
    {"command": "standarti",  "description": "📐 ISO, OECD, NIST standarti"},
    {"command": "parmums",    "description": "🚀 DevSprintAI pakalpojumi un cenas"},
    {"command": "portals",    "description": "🔐 Klientu portāls mim.melgalis.lv"},
    {"command": "kontakts",   "description": "📞 Sazināties ar MiM"},
    {"command": "jauns",      "description": "🔄 Notīrīt sarunu (jauna sesija)"},
]

# Iestata komandas
resp = requests.post(f"{BASE}/setMyCommands", json={"commands": COMMANDS})
data = resp.json()

if data.get("ok"):
    print(f"✅ {len(COMMANDS)} komandas iestatītas!")
    print("\nTagad Telegram rāda izvēlni ar '/' taustiņu:")
    for c in COMMANDS:
        print(f"  /{c['command']} — {c['description']}")
else:
    print(f"❌ Kļūda: {data}")
