From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.177]) by gnuweeb.org (Postfix) with ESMTPSA id D207E8060C; Sat, 1 Oct 2022 13:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1664629500; bh=Y3bTiprewwVrrwzVo6CvR99vRbsxvg0eYJCP1wbfLwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UYJnXQLRdlumnXXUT7rUEdUoHOrCNg9Fct3aDPdjw99U6oQE2RSt3F5IiN049/2M6 eCGIQW7Gw3wOItzqUNAetOKrpwck60S7KC4gz6pQhEizg/ZA4RfyNCju/tQgOxDgwm eITSOEsng6BDYDml5LSa5VJURaTg33gbsjLZBPW5fgA+OWMQK0TTIbcO9GjnipqVnS lFw9boMUEYhhFQwmR0NGiCHN7HPNiOBVMtKrFD5DFOiXLugLIGmCiuiu6+wTT5o+8a MVOs6RYOKtGnx7CssrSzRM0Gpnd4vb81L1tYlUwiIfJXsZ4u/C/fkshG68WyvA8nJg vx0QXXR0TU1Yw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 18/26] discord: Add @filters.lore_admin() decorator Date: Sat, 1 Oct 2022 20:03:46 +0700 Message-Id: <20221001130355.784-19-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221001130355.784-1-kiizuha@gnuweeb.org> References: <20221001130355.784-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add a @filters.lore_admin() decorator to filter only the lore admin role that can use the specific commands. With this, other users who don't have the lore admin role cannot use the specific commands. Signed-off-by: Muhammad Rizki --- daemon/dscord/gnuweeb/filters.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/daemon/dscord/gnuweeb/filters.py b/daemon/dscord/gnuweeb/filters.py index 19f9445..eb54a8a 100644 --- a/daemon/dscord/gnuweeb/filters.py +++ b/daemon/dscord/gnuweeb/filters.py @@ -3,11 +3,37 @@ # Copyright (C) 2022 Muhammad Rizki # -import discord + +# built-in/dev package imports import asyncio from typing import Any from functools import wraps +# Discord imports +import discord +from discord import Interaction + +# gnuweeb package import +from dscord import config + + +def lore_admin(func): + @wraps(func) + async def callback(*args: Any, **kwargs: Any) -> Any: + i: "Interaction" = args[1] + user_roles = [role.id for role in i.user.roles] + + if config.ADMIN_ROLE_ID not in user_roles: + return await i.response.send_message( + "Sorry, you don't have this permission\n"\ + "Tell the server admin to add you lore admin role.", + ephemeral=True + ) + if config.ADMIN_ROLE_ID in user_roles: + return await func(*args, **kwargs) + + return callback + def wait_on_limit(func): @wraps(func) -- Muhammad Rizki