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.126.135]) by gnuweeb.org (Postfix) with ESMTPSA id 8FDAF7E5F8; Sun, 8 Jan 2023 08:08:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673165303; bh=maT0s+5Y1HmNBTIL8oM1blQPX1h7aPD8gaMWbRmiKUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ka8a8nkxysPgdB8OYvV8jumA5qaOIm1+CahrTZf4hva0W7gVoVOV+BiaLH7845IYJ c5doAmVEIMFoIKlnI9IeJkwagkh9Unj+85pxp7dMq44UhijDKfpezAdyy/PtN/gKwN v+Br+/p4xm/CbjBtp1B3th+/4ExZCt/GjXwSR9c/tsV75JAZk2ReXC3gRWzKf0/GWn fbAygzQ050Gp5xAzkFYRh0+hd9AAmpp4uzByRzyu/bU58GxWLXNa90fiWdtv7CJFu8 hKzKSO49/lKjfTPOM3JqtlSX0/taKNVOQxWKAisjHzkVnNklxOJwClkkeqGY+RN4WG HmaDRjVlVlN0w== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v3 11/11] telegram: Rename the Telegram bot custom client Date: Sun, 8 Jan 2023 15:07:41 +0700 Message-Id: <20230108080741.1914-12-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230108080741.1914-1-kiizuha@gnuweeb.org> References: <20230108080741.1914-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Rename the custom client for the Telegram bot and update all affected code in the other files to reflect the change. Signed-off-by: Muhammad Rizki --- daemon/telegram/mailer/listener.py | 4 ++-- daemon/telegram/packages/__init__.py | 2 +- daemon/telegram/packages/client.py | 2 +- daemon/telegram/packages/decorator.py | 2 +- daemon/telegram/packages/plugins/callbacks/del_atom.py | 6 +++--- daemon/telegram/packages/plugins/callbacks/del_chat.py | 6 +++--- .../telegram/packages/plugins/commands/manage_atom.py | 10 +++++----- .../packages/plugins/commands/manage_broadcast.py | 10 +++++----- daemon/telegram/packages/plugins/commands/scrape.py | 6 +++--- daemon/tg.py | 4 ++-- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/daemon/telegram/mailer/listener.py b/daemon/telegram/mailer/listener.py index 505cf44..2e8eeda 100644 --- a/daemon/telegram/mailer/listener.py +++ b/daemon/telegram/mailer/listener.py @@ -8,7 +8,7 @@ from pyrogram import idle from pyrogram.types import Message from mysql.connector.errors import OperationalError, DatabaseError from apscheduler.schedulers.asyncio import AsyncIOScheduler -from telegram.packages import DaemonClient +from telegram.packages import DaemonTelegram from exceptions import DaemonException from atom import Scraper from atom import utils @@ -23,7 +23,7 @@ class BotMutexes(): class Bot(): - def __init__(self, client: DaemonClient, sched: AsyncIOScheduler, + def __init__(self, client: DaemonTelegram, sched: AsyncIOScheduler, scraper: Scraper, mutexes: BotMutexes): self.client = client self.sched = sched diff --git a/daemon/telegram/packages/__init__.py b/daemon/telegram/packages/__init__.py index efef9ae..15a270f 100644 --- a/daemon/telegram/packages/__init__.py +++ b/daemon/telegram/packages/__init__.py @@ -1 +1 @@ -from .client import DaemonClient +from .client import DaemonTelegram diff --git a/daemon/telegram/packages/client.py b/daemon/telegram/packages/client.py index c5b0b33..a58aaf8 100644 --- a/daemon/telegram/packages/client.py +++ b/daemon/telegram/packages/client.py @@ -17,7 +17,7 @@ from .decorator import handle_flood from exceptions import DaemonException -class DaemonClient(Client): +class DaemonTelegram(Client): def __init__(self, name: str, api_id: int, api_hash: str, conn, logger: BotLogger, **kwargs diff --git a/daemon/telegram/packages/decorator.py b/daemon/telegram/packages/decorator.py index 153fa95..efcfc38 100644 --- a/daemon/telegram/packages/decorator.py +++ b/daemon/telegram/packages/decorator.py @@ -24,7 +24,7 @@ def handle_flood(func: Callable[[T], T]) -> Callable[[T], T]: try: return await func(*args) except FloodWait as e: - # Calling logger attr from the DaemonClient() class + # Calling logger attr from the DaemonTelegram() class logger = args[0].logger _flood_exceptions(e, logger) diff --git a/daemon/telegram/packages/plugins/callbacks/del_atom.py b/daemon/telegram/packages/plugins/callbacks/del_atom.py index b750e1c..84524c2 100644 --- a/daemon/telegram/packages/plugins/callbacks/del_atom.py +++ b/daemon/telegram/packages/plugins/callbacks/del_atom.py @@ -3,14 +3,14 @@ # Copyright (C) 2022 Muhammad Rizki # -from telegram.packages import DaemonClient +from telegram.packages import DaemonTelegram from atom import utils from pyrogram.types import CallbackQuery from telegram import config -@DaemonClient.on_callback_query(config.admin_only, group=1) -async def on_del_atom(c: DaemonClient, cb: CallbackQuery): +@DaemonTelegram.on_callback_query(config.admin_only, group=1) +async def on_del_atom(c: DaemonTelegram, cb: CallbackQuery): if not "del_atom" in cb.data: return diff --git a/daemon/telegram/packages/plugins/callbacks/del_chat.py b/daemon/telegram/packages/plugins/callbacks/del_chat.py index 90b557e..c7135e0 100644 --- a/daemon/telegram/packages/plugins/callbacks/del_chat.py +++ b/daemon/telegram/packages/plugins/callbacks/del_chat.py @@ -3,14 +3,14 @@ # Copyright (C) 2022 Muhammad Rizki # -from telegram.packages import DaemonClient +from telegram.packages import DaemonTelegram from atom import utils from pyrogram.types import CallbackQuery from telegram import config -@DaemonClient.on_callback_query(config.admin_only, group=2) -async def on_del_chat(c: DaemonClient, cb: CallbackQuery): +@DaemonTelegram.on_callback_query(config.admin_only, group=2) +async def on_del_chat(c: DaemonTelegram, cb: CallbackQuery): if not "del_chat" in cb.data: return diff --git a/daemon/telegram/packages/plugins/commands/manage_atom.py b/daemon/telegram/packages/plugins/commands/manage_atom.py index 99df7f7..f686adf 100644 --- a/daemon/telegram/packages/plugins/commands/manage_atom.py +++ b/daemon/telegram/packages/plugins/commands/manage_atom.py @@ -5,16 +5,16 @@ from pyrogram.types import Message from pyrogram import filters -from telegram.packages import DaemonClient +from telegram.packages import DaemonTelegram from atom import utils from telegram import config -@DaemonClient.on_message( +@DaemonTelegram.on_message( filters.command("add_atom") & config.admin_only ) -async def add_atom_url(c: DaemonClient, m: Message): +async def add_atom_url(c: DaemonTelegram, m: Message): if len(m.command) <= 1: tutor = "Please specify the URL\n" tutor += "Example: `/add_atom https://lore.kernel.org/linux-sgx/new.atom`" @@ -32,11 +32,11 @@ async def add_atom_url(c: DaemonClient, m: Message): await m.reply(f"Success add **{text}** for listening new email") -@DaemonClient.on_message( +@DaemonTelegram.on_message( filters.command("del_atom") & config.admin_only ) -async def del_atom_url(c: DaemonClient, m: Message): +async def del_atom_url(c: DaemonTelegram, m: Message): atoms = c.db.get_atom_urls() if len(atoms) == 0: return await m.reply("Currently empty.") diff --git a/daemon/telegram/packages/plugins/commands/manage_broadcast.py b/daemon/telegram/packages/plugins/commands/manage_broadcast.py index 0aa70de..63f9547 100644 --- a/daemon/telegram/packages/plugins/commands/manage_broadcast.py +++ b/daemon/telegram/packages/plugins/commands/manage_broadcast.py @@ -5,16 +5,16 @@ from pyrogram.types import Message from pyrogram import filters, enums -from telegram.packages import DaemonClient +from telegram.packages import DaemonTelegram from atom import utils from telegram import config -@DaemonClient.on_message( +@DaemonTelegram.on_message( filters.command("add_bc") & config.admin_only ) -async def add_broadcast(c: DaemonClient, m: Message): +async def add_broadcast(c: DaemonTelegram, m: Message): if m.chat.type == enums.ChatType.PRIVATE: chat_name = m.chat.first_name else: @@ -37,11 +37,11 @@ async def add_broadcast(c: DaemonClient, m: Message): await m.reply(msg) -@DaemonClient.on_message( +@DaemonTelegram.on_message( filters.command("del_bc") & config.admin_only ) -async def del_broadcast(c: DaemonClient, m: Message): +async def del_broadcast(c: DaemonTelegram, m: Message): if "--list" in m.text: chats = c.db.get_broadcast_chats() if len(chats) == 0: diff --git a/daemon/telegram/packages/plugins/commands/scrape.py b/daemon/telegram/packages/plugins/commands/scrape.py index f89727d..89581b6 100644 --- a/daemon/telegram/packages/plugins/commands/scrape.py +++ b/daemon/telegram/packages/plugins/commands/scrape.py @@ -6,7 +6,7 @@ from pyrogram.types import Message from pyrogram import filters -from telegram.packages import DaemonClient +from telegram.packages import DaemonTelegram from atom import Scraper from atom import utils from enums import Platform @@ -22,11 +22,11 @@ import asyncio # .lore https://lore.kernel.org/path/message_id/raw # LORE_CMD_URL_PATTERN = r"^(?:\/|\.|\!)lore\s+(https?:\/\/lore\.kernel\.org\/\S+)" -@DaemonClient.on_message( +@DaemonTelegram.on_message( filters.regex(LORE_CMD_URL_PATTERN) & config.admin_only ) -async def scrap_email(c: DaemonClient, m: Message): +async def scrap_email(c: DaemonTelegram, m: Message): p = re.search(LORE_CMD_URL_PATTERN, m.text) if not p: return diff --git a/daemon/tg.py b/daemon/tg.py index a676cf5..9f36e54 100644 --- a/daemon/tg.py +++ b/daemon/tg.py @@ -9,7 +9,7 @@ from dotenv import load_dotenv from mysql import connector from pyrogram import idle from atom import Scraper -from telegram.packages import DaemonClient +from telegram.packages import DaemonTelegram from telegram.mailer import BotMutexes from telegram.mailer import Bot from logger import BotLogger @@ -28,7 +28,7 @@ def main(): else: port = int(port) - client = DaemonClient( + client = DaemonTelegram( "telegram/storage/EmailScraper", api_id=int(os.getenv("API_ID")), api_hash=os.getenv("API_HASH"), -- Muhammad Rizki