Бот для капчи в чатах
Roman Sergienko
8 hours ago c80fb18220a339f2b1a218fd1b5886e0a41725f6
web/views.py
@@ -656,7 +656,7 @@
                    file_path = gif_dir / file_name
                    
                    # Сохраняем файл
                    content = await file.read()
                    content = file.file.read()
                    with open(file_path, "wb") as f:
                        f.write(content)
                    
@@ -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})