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.217]) by gnuweeb.org (Postfix) with ESMTPSA id 969EA80E1F; Mon, 3 Oct 2022 23:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1664841218; bh=Y3bTiprewwVrrwzVo6CvR99vRbsxvg0eYJCP1wbfLwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VxBMbxRqwg7PXw8GlXqUTn7RkNB6kr4wv3Y00JQKuRkeioy3XZtnsqisM6ydhHgv0 OaVPxaOg6bgkACvhO7bXfDyDur38frf/2gWHEwoLyH8Bpa6HlW1WzowDvme12t/DbU q1maTpaHAyMh0AP3bLLM+BdPil3IjQYPgMEVMyUoXy/6LCMdyGnlJoKBlMy9g/TrzH m9pP9LzPMUPpbf8/ZKlaeFv8IxoNdS5SZAI8H8mNoNHAEOzNxGZMbndygmESYb36AQ 3FocSOe+B6sqoe4Oo8DfnNkm82sJHs3BFmkXN42f2AFBJPNUaEkyYJBT9r0C71FR3D o9VMwMfB2Ac/g== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 20/28] discord: Add @filters.lore_admin() decorator Date: Tue, 4 Oct 2022 06:52:21 +0700 Message-Id: <20221003235230.1824-21-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221003235230.1824-1-kiizuha@gnuweeb.org> References: <20221003235230.1824-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