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 24DA07E3B8; Tue, 3 Jan 2023 06:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1672727821; bh=xto6dGnrWZ+PYUFdWn4tsAWF6dThVUj+1PYbUzRysL4=; h=From:To:Cc:Subject:Date:From; b=K0fuyNjfhjmFpHfYz7Ze7TAoWwo7pNIMLS84CPj2xFBhxFs4IeR4LI8o45H1Sq4le eHVEmyLiA8WaTfkZXydBMoulr+Y++mov+V5dHN5h4lz8sEdFbOieBVQneih94HnVt4 vkcVe7h5dLZwEkmGeTkqhDm7SFtzdK76JyHEfQJKEDkHX8286dcitSIZb3HNUkgCH0 QfS4o+UgJsg8WWEbQqrehhGt9RXFkiLAeT+YFh3REccMsnw8i4DH2t4ugO4a96Mp8O hVlS7MccDKoQ2iw4QxsbqAnIJKOhFdop4pTKLg2dBaaP+VH6OzvaWcBKAsdLZiHxHY gdUNerklUbJZg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 00/13] Improvements, refactors, and features Date: Tue, 3 Jan 2023 13:36:28 +0700 Message-Id: <20230103063641.1680-1-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Hir sir, This is v1 of Improvements, refactors, and features. This series is to move a function, code Improvements, add a function, and add an error class. 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, 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. Refactors: - Move report_err() to the DaemonTelegram() for the Telegram bot. - Remove try/except for both bots in their listener.py. - Ensure the Telegram bot has been started, so start the client earlier. - Rename the Telegram bot custom client to "DaemonTelegram". There are 13 patches in this series: - Patch 1 is to remove unnecessary try/except in the listener for DC bot. - Patch 2 is to move report_err() from listener to DaemonTelegram(). - Patch 3 is to ensure the Telegram bot has been started before interact. - Patch 4 is to added DaemonException() error class to handle error. - Patch 5 is to implement the DaemonException() error class for the TG. - Patch 6 is to remove unnecessary try/except in the listener for TG bot - Patch 7 is to added report_err() for the Discord bot in the client. - Patch 8 is to implement the report_err() in the Discord mail listener. - Patch 9 is to added ping() method to reconnect MySQL connection for DC. - Patch 10 is to added handle_db_error() in the listener for the DC bot. - Patch 11 is to handle MySQL connection error in the listener for the DC - Patch 12 is to implement the DaemonException() error class for the DC. - Patch 13 is to rename the Telegram bot custom client to DaemonTelegram() 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! Signed-off-by: Muhammad Rizki --- Muhammad Rizki (13): refactor(discord): Remove unnecessary try/except block refactor(telegram): Move report_err() to the DaemonClient() class refactor(telegram)!: Ensure the Telegram bot has been started feat: add DaemonException() class feat(telegram): Implement the DaemonException() class refactor(telegram/mailer)!: Remove unnecessary try/except block feat(discord): add report_err() for the Discord bot feat(discord): Implement the report_err() feat(discord/database): Add ping() method feat(discord): Add handle_db_error in the listener.py feat(discord): Handle MySQL connection error in the mail listener feat(discord): Implement the DaemonException for handle error refactor(telegram)!: Rename the Telegram bot custom client daemon/dscord/database/core.py | 6 +++ daemon/dscord/gnuweeb/client.py | 8 ++++ daemon/dscord/mailer/listener.py | 48 ++++++++++++++----- daemon/exceptions.py | 18 +++++++ daemon/telegram/mailer/listener.py | 36 +++++++------- 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 | 11 +++-- 14 files changed, 120 insertions(+), 59 deletions(-) create mode 100644 daemon/exceptions.py base-commit: d72337c346686b7faa48ee654c967dba1dfebea0 -- Muhammad Rizki