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 140FE8104C; Mon, 3 Oct 2022 23:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1664841220; bh=hxyoEqYB7CchdtpYq4JoOOtvS5sWzaDEghaN5hxMwJc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gMTroKLnQ6XM//jJTO6NafcPjKsVdbvVLGQBDDZTnpOR8GtVN263twiJFyxq1f301 FZz/BKmjmdYvUybcEFrW0l5VDEutj1riMHYzprUq2orTr5f/HV7XrWA3cHecYC/s2e wOkAYrCV6ATuz+0mVvNcRSjHBB/5j0mQAXqvGOhSNVr6DrOPXBYAcAgunSO2EbOTR0 F3eQgHSRwrueLIVQOmPfOUWHp06D/8l7YFsMbcP4XBQjAO4Z+n9EEkqQ38B0H5pj+y dUPNF8ArNR+cHWJIr9ls44EXDm2JKut8HDz3Sqahz0eJVnN6WQ6pBl4SIeRauECgfw E/NkKrlsirqYQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 21/28] discord: Add a list of atom URL slash command Date: Tue, 4 Oct 2022 06:52:22 +0700 Message-Id: <20221003235230.1824-22-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 `/atom list` slash command to get the list of atom URLs in the database that is currently listening. Signed-off-by: Muhammad Rizki --- daemon/dscord/gnuweeb/plugins/__init__.py | 4 +- .../plugins/slash_commands/__init__.py | 11 ++++++ .../plugins/slash_commands/manage_atom.py | 39 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 daemon/dscord/gnuweeb/plugins/slash_commands/__init__.py create mode 100644 daemon/dscord/gnuweeb/plugins/slash_commands/manage_atom.py diff --git a/daemon/dscord/gnuweeb/plugins/__init__.py b/daemon/dscord/gnuweeb/plugins/__init__.py index cbec2b5..631d9ad 100644 --- a/daemon/dscord/gnuweeb/plugins/__init__.py +++ b/daemon/dscord/gnuweeb/plugins/__init__.py @@ -8,11 +8,13 @@ from discord.ext import commands from .events import Events from .basic_commands import BasicCommands +from .slash_commands import SlashCommands class Plugins( BasicCommands, - Events + Events, + SlashCommands ): pass diff --git a/daemon/dscord/gnuweeb/plugins/slash_commands/__init__.py b/daemon/dscord/gnuweeb/plugins/slash_commands/__init__.py new file mode 100644 index 0000000..0ed86b1 --- /dev/null +++ b/daemon/dscord/gnuweeb/plugins/slash_commands/__init__.py @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + +from .manage_atom import ManageAtomSC + + +class SlashCommands( + ManageAtomSC, +): pass diff --git a/daemon/dscord/gnuweeb/plugins/slash_commands/manage_atom.py b/daemon/dscord/gnuweeb/plugins/slash_commands/manage_atom.py new file mode 100644 index 0000000..a4281c1 --- /dev/null +++ b/daemon/dscord/gnuweeb/plugins/slash_commands/manage_atom.py @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + +from discord.ext import commands +from discord import Interaction +from discord import app_commands + +from dscord.gnuweeb import filters + + +class ManageAtomSC(commands.Cog): + atom = app_commands.Group( + name="atom", + description="Manage lore atom URL." + ) + + def __init__(self, bot) -> None: + self.bot = bot + + + @atom.command( + name="list", + description="List of lore atom URL." + ) + @filters.lore_admin + async def list_atom(self, i: "Interaction"): + atoms = self.bot.db.get_atom_urls() + if len(atoms) == 0: + t = "Currently empty." + await i.response.send_message(t, ephemeral=True) + return + + text = "List of atom URL that currently listened:\n" + for u,n in zip(atoms, range(1, len(atoms)+1)): + text += f"{n}. {u}\n" + + await i.response.send_message(text, ephemeral=True) -- Muhammad Rizki