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.123]) by gnuweeb.org (Postfix) with ESMTPSA id D392181101; Fri, 21 Oct 2022 13:45:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1666359945; bh=ascqL691W3f5/PNQlcbe9ja529icFMabhFFw2/JgK4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o5L8fLnZdHLNHm+VOU3AeXn6BdB8LJffRCmW6ZVlvG9KIiok0aNRWeZKDQyI7c8cU /mdHCIhmujzTkXxKWGf7ZBj4LelKdd76gdWeC/W90HLuaQ5jKxrzevHkDZOp9gCVhy +dmSVsGWbjVfVZ9dNwg/0ao3vRWwqiag86qUeKtIXLqX/6ywnxLDW41x7I124Kvjc8 YR+lwiPF1jSj/arO2I3VI02e6xAp1cjQ+ujXKtp+rsvsUOhXS5gqblb8H1/qj+HOrl CxRcAznxpYRLlwXzIBVTPlWDbqOMICAOCJHnBpuuQ0JpJHoBa1hvNzsNGV3AMKMWCL zNqe7rVDs3QWQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v3 3/9] discord: Add get lore mail slash command Date: Fri, 21 Oct 2022 20:45:14 +0700 Message-Id: <20221021134520.701-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221021134520.701-1-kiizuha@gnuweeb.org> References: <20221021134520.701-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add a `/lore {url}` slash command to get the specific lore email message from the raw atom URL. Signed-off-by: Muhammad Rizki --- .../plugins/slash_commands/__init__.py | 2 + .../plugins/slash_commands/get_lore_mail.py | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 daemon/dscord/gnuweeb/plugins/slash_commands/get_lore_mail.py diff --git a/daemon/dscord/gnuweeb/plugins/slash_commands/__init__.py b/daemon/dscord/gnuweeb/plugins/slash_commands/__init__.py index a6d913c..126af45 100644 --- a/daemon/dscord/gnuweeb/plugins/slash_commands/__init__.py +++ b/daemon/dscord/gnuweeb/plugins/slash_commands/__init__.py @@ -5,9 +5,11 @@ from .manage_atom import ManageAtomSC from .manage_broadcast import ManageBroadcastSC +from .get_lore_mail import GetLoreSC class SlashCommands( + GetLoreSC, ManageAtomSC, ManageBroadcastSC ): pass diff --git a/daemon/dscord/gnuweeb/plugins/slash_commands/get_lore_mail.py b/daemon/dscord/gnuweeb/plugins/slash_commands/get_lore_mail.py new file mode 100644 index 0000000..2d55d16 --- /dev/null +++ b/daemon/dscord/gnuweeb/plugins/slash_commands/get_lore_mail.py @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + +import asyncio +import discord +from discord.ext import commands +from discord import Interaction +from discord import app_commands + +from atom import utils +from atom import Scraper + + +class GetLoreSC(commands.Cog): + def __init__(self, bot) -> None: + self.bot = bot + + + @app_commands.command( + name="lore", + description="Get lore email from raw email URL." + ) + @app_commands.describe(url="Raw lore email URL") + async def get_lore(self, i: "Interaction", url: str): + s = Scraper() + mail = await s.get_email_from_url(url) + text, _, is_patch = utils.create_template(mail, "discord") + + if is_patch: + m = await self.bot.send_patch_mail_interaction( + mail=mail, i=i, text=text, url=url + ) + else: + text = "#ml\n" + text + m = await self.bot.send_text_mail_interaction( + i=i, text=text, url=url + ) -- Muhammad Rizki