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.126.135]) by gnuweeb.org (Postfix) with ESMTPSA id 4D7147E3B8; Tue, 3 Jan 2023 06:37:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1672727850; bh=PnGBvOZAG7I42khFmbNHdhX5CTXnJfgw1CgNPACobyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RdhHcjr2+WZentZkZpBFePyDMMcfon2cgl9UtflmgXgH8+z9E18p9gKeE5lol2MCo grqXm9FmKhAKb5YdWY/4fyWyL+dssxBaJTIgvU16CLwf+O4LW6SBwbDW9f/I/o0XVh 50pvzzpKuYgXB6Kv79dr2ua4DDZub+xZ90Vr0sem0VQwcUOPW7iFph5AlpYXjMvzqE ZvRKZuPf2MRRBfW85HdP24Bf5oVD2TsVLUkENjlPQfi3V9FE4RjMhi9c3YICB6hfDf MF9lK4GcN3Xk+JiGKRvHNFtaY7YHTSGbcorOeIDjl4KNjQnzZJ8/DuIYyKDeMSqccL pAicdROHVQkvA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 13/13] refactor(telegram)!: Rename the Telegram bot custom client Date: Tue, 3 Jan 2023 13:36:41 +0700 Message-Id: <20230103063641.1680-14-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230103063641.1680-1-kiizuha@gnuweeb.org> References: <20230103063641.1680-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Renamed all Telegram bot custom client that has been used in other files 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 e906b1f..4e1e0da 100644 --- a/daemon/telegram/mailer/listener.py +++ b/daemon/telegram/mailer/listener.py @@ -7,7 +7,7 @@ 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 @@ -22,7 +22,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 f543caa..1c5f3b7 100644 --- a/daemon/telegram/packages/client.py +++ b/daemon/telegram/packages/client.py @@ -16,7 +16,7 @@ from telegram.database import DB from .decorator import handle_flood -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 9d50e44..d3b5760 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