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: [PATCH v3 00/11] Improvements, refactors, and features
Date: Sun, 8 Jan 2023 15:07:30 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
Hir sir,
This is v3 of improvements, refactors, and features. This series is to
add more `except` block for both Discord and Telegram, and fix some
grammatical errors in the commit messages.
In the last series, I didn't care so much with the Discord
implementation. So, I forget to add a reconnect MySQL method for the
Discord bot. In this series, I've added it and implement it in the
listener.py exactly in the handle_db_error().
In the last commit of the series, Telegram report_err() is implemented
in the listener.py. In this series, I've been move it to the Telegram
bot custom client instead. I've added a report_err() for the Discord bot
too in the client.
I've added DaemonException() error class too to easily save a thread URL
if errors may happen, this error class is to easily reproducing errors.
Some unnecessary try/except block is already removed and add the
try/except block again in the __handle_atom_url(), we need to catch the
thread URL to easily reproducing errors if errors may happen in the
future.
I've implemented handle_db_error() for the Discord bot too.
What's new?
- Added a report_err() for the Discord bot.
- Added a DaemonException() error class for both bots.
- Added a ping() for reconnecting MySQL conn for the Discord bot.
- Added a handle_db_error() for the Discord bot mail listener.
Code Refactors:
v3: No code refactoring is needed.
v2:
1) Move Telegram bot connection to the listener's run() function.
We use start(), idle() and stop() rather than the run() that
are the same with 3 of them. The different is, we need to connect
to the Telegram server first, then we add a scheduler to listen a
new email message, and then idle() the Telegram bot to be able to
manage the atom URLs and broadcast chats. Why ordering from
start() -> idle() -> stop()? As I said, we need to connect to the
Telegram server first, since the code only is an initialization,
we shouldn't worry about them, they are the same as pryogram's
run().
2) Change the report_err() codes for both Telegram and Discord, we
use DaemonException as it's argument type.
v1:
1) Move report_err() to the DaemonTelegram() for the Telegram bot.
2) Remove try/except for both bots in their listener.py.
3) Ensure the Telegram bot has been started, so start the client
earlier.
4) Rename the Telegram bot custom client to "DaemonTelegram".
There are 11 patches in this series:
- Patch 1 is to remove unnecessary try/except in the listener for DC bot.
- Patch 2 is to change the TG runner method to perform graceful exit.
- Patch 3 is to add a DaemonException() error class to handle error.
- Patch 4 is to refactor report_err() and move it to the DaemonClient().
- Patch 5 is to implement the DaemonException() and change report_err().
- Patch 6 is to remove unnecessary try/except in the listener for TG bot.
- Patch 7 is to add a report_err() for the Discord bot.
- Patch 8 is to implement report_err() and DaemonException() for DC bot.
- Patch 9 is to add a ping() for reconnecting the MySQL connection.
- Patch 10 is to add a handle_db_error() to handle the MySQL errors.
- Patch 11 is to rename the Telegram bot custom client.
How to set log channel ID for the Telegram bot:
1. Make a channel for log in the Telegram.
2. Copy the channel ID, if you unable to see the ID you can use API or
bot who has the feature, or use a 64gram desktop.
3. Paste the copied ID into the config.py in the telegram directory.
How to set log channel ID for the Discord bot:
1. Make a channel for log in your Discord server.
2. Copy the channel ID by right click and copy, if you unable to get the
ID you can go to your account settings, then enable the
`Developer mode` or use bot who has the feature.
3. Paste the copied ID into the config.py in the dscord directory.
How to use:
1. Execute the db.sql file in the daemon directory.
2. Setup .env file, the example is there with suffix .example, this
file name must remove the suffix name .example.
3. Set up the config.py in each bot directory, such as dscord and
telegram. The example is there with suffix .example & the file name
must remove suffix name .example.
4. Run `pip3 install -r requirements.txt` in each bot directory.
5. STORAGE_DIR env value must `storage` to make it work fine.
6. Run the bot by `python3 dc.py` or `python3 tg.py`.
Please give it a test and give me more comments or suggestion, thanks!
## Changelog
v2 -> v3:
- Add `except` block for both Discord and Telegram in the listener.py
- Fix grammatical errors for some commit messages
- Fix the ack certification prefix for Viro
v1 -> v2:
- Move Telegram bot runner
- Change the report_err() codes for both Telegram and Discord
- Change all commits title prefixes
- Change some commits descriptions
Signed-off-by: Muhammad Rizki <[email protected]>
---
Muhammad Rizki (11):
discord: Remove unnecessary try/except block
telegram: Perform graceful exit when interrupted by a signal
Add DaemonException() class
telegram: Refactor report_err() and move to the DaemonClient() class
telegram: Implement the DaemonException() and refactor report_err()
telegram: listener: Remove unnecessary try/except block
discord: add report_err() for the Discord bot
discord: Implement the report_err() and DaemonException() error class
discord: database: Add ping() method for reconnect MySQL
discord: listener: Add handle_db_error to handle the MySQL errors
telegram: Rename the Telegram bot custom client
daemon/dscord/database/core.py | 6 +++
daemon/dscord/gnuweeb/client.py | 8 +++
daemon/dscord/mailer/listener.py | 53 ++++++++++++++-----
daemon/exceptions.py | 18 +++++++
daemon/telegram/mailer/listener.py | 45 +++++++++-------
daemon/telegram/packages/__init__.py | 2 +-
daemon/telegram/packages/client.py | 10 +++-
daemon/telegram/packages/decorator.py | 2 +-
.../packages/plugins/callbacks/del_atom.py | 6 +--
.../packages/plugins/callbacks/del_chat.py | 6 +--
.../packages/plugins/commands/manage_atom.py | 10 ++--
.../plugins/commands/manage_broadcast.py | 10 ++--
.../packages/plugins/commands/scrape.py | 6 +--
daemon/tg.py | 8 ++-
14 files changed, 131 insertions(+), 59 deletions(-)
create mode 100644 daemon/exceptions.py
base-commit: d72337c346686b7faa48ee654c967dba1dfebea0
--
Muhammad Rizki
next reply other threads:[~2023-01-08 8:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-08 8:07 Muhammad Rizki [this message]
2023-01-08 8:07 ` [PATCH v3 01/11] discord: Remove unnecessary try/except block Muhammad Rizki
2023-01-08 8:07 ` [PATCH v3 02/11] telegram: Perform graceful exit when interrupted by a signal Muhammad Rizki
2023-01-08 8:07 ` [PATCH v3 03/11] Add DaemonException() class Muhammad Rizki
2023-01-08 8:07 ` [PATCH v3 04/11] telegram: Refactor report_err() and move to the DaemonClient() class Muhammad Rizki
2023-01-08 8:07 ` [PATCH v3 05/11] telegram: Implement the DaemonException() and refactor report_err() Muhammad Rizki
2023-01-08 8:07 ` [PATCH v3 06/11] telegram: listener: Remove unnecessary try/except block Muhammad Rizki
2023-01-08 8:07 ` [PATCH v3 07/11] discord: add report_err() for the Discord bot Muhammad Rizki
2023-01-08 8:07 ` [PATCH v3 08/11] discord: Implement the report_err() and DaemonException() error class Muhammad Rizki
2023-01-08 8:07 ` [PATCH v3 09/11] discord: database: Add ping() method for reconnect MySQL Muhammad Rizki
2023-01-08 8:07 ` [PATCH v3 10/11] discord: listener: Add handle_db_error to handle the MySQL errors Muhammad Rizki
2023-01-08 8:07 ` [PATCH v3 11/11] telegram: Rename the Telegram bot custom client Muhammad Rizki
2023-01-08 8:34 ` [PATCH v3 00/11] Improvements, refactors, and features 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] \
[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