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 autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.209]) by gnuweeb.org (Postfix) with ESMTPSA id 708408193C; Mon, 19 Dec 2022 23:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671493973; bh=5xcvgY7xFKkomOG2XQYrhvXCIU10eEojWTcoxXieLy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dzAcfKgiDilwSwbN5CheDGvWP740CukIvaOy8JaWhXhfQFoHS8SdFJJeQtR6pj5Lk Jk5UG6NS2SIWbVYKtG66/H8Sj5NyIHGSMEFBNAjjhQ7SQcSt94zzlipYpHPq+arh4x vnfOkDHjAR6jMQr69qyRm+vABQKP49AwnYTAuHsVPv9KnBgHdrVCWs0QRlOUlMKNx2 twv9ZfymuI+XB+/+nfvxyuNEP/mlAgzjuG+SM8i+VcNtDuA4S5Wv8u4CDcTSKy+SMZ VavOpVHZ2F806rIAZw/t/0/BUUWdhITYASe+76By7F2S/an/mINUWfum9xU+q4Rm7S 8G8ApcavTaJhA== From: Muhammad Rizki To: Cc: Muhammad Rizki , Alviro Iskandar Setiawan , Ammar Faizi , GNU/Weeb Mailing List Subject: [PATCH 03/28] discord: Add get lore mail slash command Date: Tue, 20 Dec 2022 06:52:01 +0700 Message-Id: <20221219235226.1567-3-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221219235226.1567-1-kiizuha@gnuweeb.org> References: <20221219235226.1567-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 Link: https://lore.gnuweeb.org/gwml/20221022065149.865-4-kiizuha@gnuweeb.org Cc: Alviro Iskandar Setiawan Cc: Ammar Faizi Cc: GNU/Weeb Mailing List Signed-off-by: Ammar Faizi --- .../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 + ) -- 2.34.1.windows.1