From c80fb18220a339f2b1a218fd1b5886e0a41725f6 Mon Sep 17 00:00:00 2001
From: Roman Sergienko <romasergienko@outlook.com>
Date: Fri, 04 Dec 2026 11:46:23 +0000
Subject: [PATCH] Register RP handler before catch-all text handler

---
 web/views.py |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/web/views.py b/web/views.py
index 179cd09..0f55ae7 100644
--- a/web/views.py
+++ b/web/views.py
@@ -695,3 +695,25 @@
     await db.delete_rp_action(action_id)
     await db.add_log(chat_id, user["user_id"], 0, "rp_delete", action["trigger"], now_ts())
     return web.json_response({"ok": True})
+
+
+async def api_rp_toggle(request) -> web.Response:
+    user = await _user(request)
+    data = await request.post()
+    try:
+        action_id = int(data["action_id"])
+        chat_id = int(data["chat_id"])
+        enabled = data.get("enabled") == "1"
+    except (KeyError, ValueError):
+        return web.json_response({"ok": False, "msg": "Некорректные данные."}, status=400)
+
+    if chat_id not in await _allowed_ids(user["user_id"]):
+        return web.json_response({"ok": False, "msg": "Нет доступа."}, status=403)
+
+    action = await db.get_rp_action(action_id)
+    if not action or action["chat_id"] != chat_id:
+        return web.json_response({"ok": False, "msg": "Действие не найдено."}, status=404)
+
+    await db.set_rp_action_enabled(action_id, enabled)
+    await db.add_log(chat_id, user["user_id"], 0, "rp_enable" if enabled else "rp_disable", action["trigger"], now_ts())
+    return web.json_response({"ok": True})

--
Gitblit v1.9.3