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 18D8E80AB2; Thu, 20 Oct 2022 08:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1666255148; bh=ascqL691W3f5/PNQlcbe9ja529icFMabhFFw2/JgK4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nEeNHlh/n+2iVMQMHaUvnoD35ScCs6nCeUZsqBlAY63JN9IjRk0hBjpqMLcKDOxuy SCKGH/nuhRfK5L4p6LuB71hhGnygtcFsDKjC0Oo7qDKJm2nxpTGBi+v97P3aZ9o800 ktjzin4zEmFWjberYPOlkTSBTgmouhJ3LQa5m91mNS86COwU4EMqcMJmf1mdSfjylb O0ULcpaERcEeAjA2Xhdmrhq4EMXz5yHoa1DnweJzr1X3qPxFr4Bbl+gOYULph8bI8j hs+cFWRPsHfMbfwKEz1QSbyATOYv/pT3im7U4U5knNRmsxoHtHmd79S7I6OgNxCJaj xnUx/kLXTfYqA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 3/8] discord: Add get lore mail slash command Date: Thu, 20 Oct 2022 15:38:40 +0700 Message-Id: <20221020083845.907-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221020083845.907-1-kiizuha@gnuweeb.org> References: <20221020083845.907-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