From: Muhammad Rizki <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Muhammad Rizki <[email protected]>,
GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH v3 16/17] Replace send email functions
Date: Fri, 22 Jul 2022 06:29:37 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
I want to replace called functions in packages/plugins/scrape.py because
I created custom functions for send email to Telegram using inheritance
method, so I replace it and remove related unused codes.
Signed-off-by: Muhammad Rizki <[email protected]>
---
daemon/packages/plugins/scrape.py | 48 ++++++-------------------------
1 file changed, 9 insertions(+), 39 deletions(-)
diff --git a/daemon/packages/plugins/scrape.py b/daemon/packages/plugins/scrape.py
index 1698c6d..280c3f9 100644
--- a/daemon/packages/plugins/scrape.py
+++ b/daemon/packages/plugins/scrape.py
@@ -4,15 +4,11 @@
# Copyright (C) 2022 Ammar Faizi <[email protected]>
#
-from pyrogram.types import InlineKeyboardMarkup
-from pyrogram.types import InlineKeyboardButton
from pyrogram.types import Message
from pyrogram import filters
-from pyrogram import Client
+from packages import DaemonClient
from scraper import Scraper
-from pyrogram import enums
from scraper import utils
-from scraper import Bot
import shutil
import re
import asyncio
@@ -25,11 +21,11 @@ import asyncio
# .lore https://lore.kernel.org/path/message_id/raw
#
LORE_CMD_URL_PATTERN = r"^(?:\/|\.|\!)lore\s+(https?:\/\/lore\.kernel\.org\/\S+)"
[email protected]_message(
[email protected]_message(
filters.regex(LORE_CMD_URL_PATTERN) &
filters.chat(["kiizuah", "nekoha", -1001673279485])
)
-async def scrap_email(_, m: Message):
+async def scrap_email(c: DaemonClient, m: Message):
p = re.search(LORE_CMD_URL_PATTERN, m.text)
if not p:
return
@@ -43,10 +39,14 @@ async def scrap_email(_, m: Message):
text, files, is_patch = utils.create_template(mail)
if is_patch:
- m = await __send_patch_msg(m, mail, text, url)
+ m = await c.send_patch_email(
+ mail, m.chat.id, text, m.id, url
+ )
else:
text = "#ml\n" + text
- m = await __send_text_msg(m, text, url)
+ m = await c.send_text_email(
+ m.chat.id, text, m.id, url
+ )
for d, f in files:
await m.reply_document(f"{d}/{f}", file_name=f)
@@ -54,33 +54,3 @@ async def scrap_email(_, m: Message):
if files:
shutil.rmtree(str(files[0][0]))
-
-
-async def __send_patch_msg(m, mail, text, url):
- tmp, fnm, caption, url = Bot.prepare_send_patch(mail, text, url)
- ret = await m.reply_document(
- fnm,
- caption=caption,
- parse_mode=enums.ParseMode.HTML,
- reply_markup=InlineKeyboardMarkup([
- [InlineKeyboardButton(
- "See the full message",
- url=url
- )]
- ])
- )
- Bot.clean_up_after_send_patch(tmp)
- return ret
-
-
-async def __send_text_msg(m, text, url):
- return await m.reply(
- text,
- parse_mode=enums.ParseMode.HTML,
- reply_markup=InlineKeyboardMarkup([
- [InlineKeyboardButton(
- "See the full message",
- url=url.replace("/raw","")
- )]
- ])
- )
--
Muhammad Rizki
next prev parent reply other threads:[~2022-07-21 23:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-21 23:29 [PATCH v3 00/17] Code improvements Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 01/17] Fix __send_patch_msg function parameter Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 02/17] Fix import problem Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 03/17] Add default temporary directory Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 04/17] Move the Telegram bot session into the storage directory Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 05/17] daemon: Fix raw lore URL on the inline keyboard button Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 06/17] daemon: Use traceback.format_exc() to get the error detail Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 07/17] Re-design send email message to Telegram Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 08/17] Move ____send_patch_msg Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 09/17] Move prepare for patch and clean up patch functions Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 10/17] Create fix_utf8_chars function Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 11/17] Remove whitespace Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 12/17] Remove prepare patch and clean up patch Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 13/17] daemon: Add @handle_flood decorator and remove some functions Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 14/17] daemon: Remove __send_patch_msg() Muhammad Rizki
2022-07-21 23:29 ` [PATCH v3 15/17] daemon: Remove unused imports Muhammad Rizki
2022-07-21 23:29 ` Muhammad Rizki [this message]
2022-07-21 23:29 ` [PATCH v3 17/17] Add typing in decorator Muhammad Rizki
2022-07-22 10:57 ` [PATCH v3 00/17] Code improvements Ammar Faizi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox