From: Muhammad Rizki <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Muhammad Rizki <[email protected]>,
Alviro Iskandar Setiawan <[email protected]>,
GNU/Weeb Mailing List <[email protected]>
Subject: [RFC PATCH v2 05/17] telegram: Refactor the Telegram bot
Date: Tue, 13 Sep 2022 17:24:46 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
Moving 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 <[email protected]>
---
.../.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 <[email protected]>
#
-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 <[email protected]>
#
-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
next prev parent reply other threads:[~2022-09-13 10:26 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-13 10:24 [RFC PATCH v2 00/17] Refactor Telegram & initial work Discord Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 01/17] telegram: Move the Telegram bot source code Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 02/17] telegram: Refactor Telegram bot database method Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 03/17] telegram: Renaming some functions in scraper/bot.py Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 04/17] Add ignore file for .env Muhammad Rizki
2022-09-13 10:24 ` Muhammad Rizki [this message]
2022-09-13 10:24 ` [RFC PATCH v2 06/17] telegram: Renames in telegram mailer directory Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 07/17] Move scraper and utility file Muhammad Rizki
2022-09-17 17:14 ` Ammar Faizi
2022-09-17 17:16 ` Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 08/17] discord: Initial work Discord bot Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 09/17] discord: Add success run notice on_ready event Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 10/17] discord: Add error handler on events Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 11/17] Move db.sql to combine database with Discord and Telegram Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 12/17] discord: Add database tables for Discord bot Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 13/17] discord: Add initial Discord bot database instance Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 14/17] discord: Add save_atom() in database insertion Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 15/17] discord: Add save_broadcast() " Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 16/17] discord: Add save_discord_mail() " Muhammad Rizki
2022-09-13 10:24 ` [RFC PATCH v2 17/17] discord: Add save_email() " Muhammad Rizki
2022-09-17 17:08 ` [RFC PATCH v2 00/17] Refactor Telegram & initial work Discord Ammar Faizi
2022-09-17 17:16 ` Muhammad Rizki
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] \
[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