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.100]) by gnuweeb.org (Postfix) with ESMTPSA id A1C2680D30; Tue, 20 Sep 2022 13:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663681721; bh=Hnklnm6cwfmytGrE8yJ7vKD61JhxK7facSm9Fo0J0uI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTcCvsR9C2PCM4mv4+KtFmYlteYckfUM/fIdYBHXWWNrdWy33ruofoqqzSKEQCfCv idSdJTCpHibE3RMh0lAVsjFVTd1vd0xbl82zUJtQDaZ4Zl8G0UL5Sk6eSDURqBlaRf /HK+KjyssPB8Up5V+6hUctYH43ycpf3yoi7QuzehALPMmAPDjbdVZyZo8RFzjmOQ6G k1YRQxmkTXgZxlQvJLXySJVLXQ2AnA3EpMpQqdWVwoWt33GeroQmJrrwPGKrdZn8eI vAUiBhAdF8Mt4N4xzi4fgi7r9zOEgBa7c9MvOY89IGwikVhind3FSy8yw72GPz39Ra y4KCA5D5tq5Zg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v4 05/17] telegram: Refactor the Telegram bot Date: Tue, 20 Sep 2022 20:48:00 +0700 Message-Id: <20220920134812.331-6-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220920134812.331-1-kiizuha@gnuweeb.org> References: <20220920134812.331-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Move the Telegram bot runner script outside the telegram directory and rename it to `tg.py`. In this state, adapt the import statement for Telegram bot file that are affected to avoid breakage after the main file movement. Reason: There will be a Discord bot with `dc.py` runner script in the same directory with `tg.py`. With this, both can share the same modules that reduce the code duplication. Signed-off-by: Muhammad Rizki --- .../.env.example => telegram.env.example} | 3 ++- daemon/telegram/packages/client.py | 4 ++-- .../packages/plugins/callbacks/del_atom.py | 6 +++--- .../packages/plugins/callbacks/del_chat.py | 6 +++--- .../telegram/packages/plugins/commands/debugger.py | 2 +- .../packages/plugins/commands/manage_atom.py | 6 +++--- .../packages/plugins/commands/manage_broadcast.py | 6 +++--- .../telegram/packages/plugins/commands/scrape.py | 8 ++++---- daemon/telegram/scraper/bot.py | 4 ++-- daemon/{telegram/run.py => tg.py} | 14 +++++++------- 10 files changed, 30 insertions(+), 29 deletions(-) rename daemon/{telegram/.env.example => telegram.env.example} (82%) rename daemon/{telegram/run.py => tg.py} (78%) diff --git a/daemon/telegram/.env.example b/daemon/telegram.env.example similarity index 82% rename from daemon/telegram/.env.example rename to daemon/telegram.env.example index 99aa46a..a070dd0 100644 --- a/daemon/telegram/.env.example +++ b/daemon/telegram.env.example @@ -15,4 +15,5 @@ DB_NAME= # Telegram Chat ID that want to send to when receive new email. TG_SEND_TO= -STORAGE_DIR=storage/ +# Storage directory to save patch files +STORAGE_DIR= diff --git a/daemon/telegram/packages/client.py b/daemon/telegram/packages/client.py index 820c3e2..e419d40 100644 --- a/daemon/telegram/packages/client.py +++ b/daemon/telegram/packages/client.py @@ -8,8 +8,8 @@ from pyrogram.enums import ParseMode from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton from typing import Union from email.message import Message -from scraper import utils -from database import DB +from telegram.scraper import utils +from telegram.database import DB from .decorator import handle_flood diff --git a/daemon/telegram/packages/plugins/callbacks/del_atom.py b/daemon/telegram/packages/plugins/callbacks/del_atom.py index 1510d60..94b2489 100644 --- a/daemon/telegram/packages/plugins/callbacks/del_atom.py +++ b/daemon/telegram/packages/plugins/callbacks/del_atom.py @@ -3,10 +3,10 @@ # Copyright (C) 2022 Muhammad Rizki # -from packages import DaemonClient -from scraper import utils +from telegram.packages import DaemonClient +from telegram.scraper import utils from pyrogram.types import CallbackQuery -import config +from telegram import config @DaemonClient.on_callback_query(config.admin_only, group=1) diff --git a/daemon/telegram/packages/plugins/callbacks/del_chat.py b/daemon/telegram/packages/plugins/callbacks/del_chat.py index 26c6dd8..ae21179 100644 --- a/daemon/telegram/packages/plugins/callbacks/del_chat.py +++ b/daemon/telegram/packages/plugins/callbacks/del_chat.py @@ -3,10 +3,10 @@ # Copyright (C) 2022 Muhammad Rizki # -from packages import DaemonClient -from scraper import utils +from telegram.packages import DaemonClient +from telegram.scraper import utils from pyrogram.types import CallbackQuery -import config +from telegram import config @DaemonClient.on_callback_query(config.admin_only, group=2) diff --git a/daemon/telegram/packages/plugins/commands/debugger.py b/daemon/telegram/packages/plugins/commands/debugger.py index ae2d31d..7f6f367 100644 --- a/daemon/telegram/packages/plugins/commands/debugger.py +++ b/daemon/telegram/packages/plugins/commands/debugger.py @@ -7,7 +7,7 @@ from pyrogram import Client, filters, enums from pyrogram.types import Message from textwrap import indent import io, import_expression, contextlib, traceback -import config +from telegram import config @Client.on_message( diff --git a/daemon/telegram/packages/plugins/commands/manage_atom.py b/daemon/telegram/packages/plugins/commands/manage_atom.py index 4ba422a..a4ccc46 100644 --- a/daemon/telegram/packages/plugins/commands/manage_atom.py +++ b/daemon/telegram/packages/plugins/commands/manage_atom.py @@ -5,9 +5,9 @@ from pyrogram.types import Message from pyrogram import filters -from packages import DaemonClient -from scraper import utils -import config +from telegram.packages import DaemonClient +from telegram.scraper import utils +from telegram import config @DaemonClient.on_message( diff --git a/daemon/telegram/packages/plugins/commands/manage_broadcast.py b/daemon/telegram/packages/plugins/commands/manage_broadcast.py index 6d75c36..16a494a 100644 --- a/daemon/telegram/packages/plugins/commands/manage_broadcast.py +++ b/daemon/telegram/packages/plugins/commands/manage_broadcast.py @@ -5,9 +5,9 @@ from pyrogram.types import Message from pyrogram import filters, enums -from packages import DaemonClient -from scraper import utils -import config +from telegram.packages import DaemonClient +from telegram.scraper import utils +from telegram import config @DaemonClient.on_message( diff --git a/daemon/telegram/packages/plugins/commands/scrape.py b/daemon/telegram/packages/plugins/commands/scrape.py index 45b1581..a83420c 100644 --- a/daemon/telegram/packages/plugins/commands/scrape.py +++ b/daemon/telegram/packages/plugins/commands/scrape.py @@ -6,10 +6,10 @@ from pyrogram.types import Message from pyrogram import filters -from packages import DaemonClient -from scraper import Scraper -from scraper import utils -import config +from telegram.packages import DaemonClient +from telegram.scraper import Scraper +from telegram.scraper import utils +from telegram import config import shutil import re import asyncio diff --git a/daemon/telegram/scraper/bot.py b/daemon/telegram/scraper/bot.py index a7087ad..ac183be 100644 --- a/daemon/telegram/scraper/bot.py +++ b/daemon/telegram/scraper/bot.py @@ -6,8 +6,8 @@ from pyrogram.types import Message from apscheduler.schedulers.asyncio import AsyncIOScheduler -from packages import DaemonClient -from scraper import Scraper +from telegram.packages import DaemonClient +from telegram.scraper import Scraper from . import utils import asyncio import shutil diff --git a/daemon/telegram/run.py b/daemon/tg.py similarity index 78% rename from daemon/telegram/run.py rename to daemon/tg.py index 5360395..86b0226 100644 --- a/daemon/telegram/run.py +++ b/daemon/tg.py @@ -5,20 +5,20 @@ # from apscheduler.schedulers.asyncio import AsyncIOScheduler -from scraper import BotMutexes +from telegram.scraper import BotMutexes from dotenv import load_dotenv from mysql import connector -from packages import DaemonClient -from scraper import Scraper -from scraper import Bot +from telegram.packages import DaemonClient +from telegram.scraper import Scraper +from telegram.scraper import Bot import os def main(): - load_dotenv() + load_dotenv("telegram.env") client = DaemonClient( - "storage/EmailScraper", + "telegram/storage/EmailScraper", api_id=int(os.getenv("API_ID")), api_hash=os.getenv("API_HASH"), bot_token=os.getenv("BOT_TOKEN"), @@ -29,7 +29,7 @@ def main(): database=os.getenv("DB_NAME") ), plugins=dict( - root="packages.plugins" + root="telegram.packages.plugins" ), ) -- Muhammad Rizki