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 kanazawa.. (unknown [101.128.126.198]) by gnuweeb.org (Postfix) with ESMTPSA id D697280632; Fri, 4 Nov 2022 18:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1667585401; bh=GWMsHHW4jTucfx/y3wPgvzsiLT/Bun/zht7zZlhdri0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mee46ax8pYvCWCbXgYW9iAPTLOp153mdjVZ51s2W8xdjrhgAmFQK3VQkAiEeAd98q CVjBVtpdUHJeEhHlHgzYnDpV3tgQ3SVTKXdZ7Z33Ts5jY/Qd695D5ZXbVav6QbAzxy 7pXJXMup8fBWX1psXnOm+eg28++Zgy4i55SCvQioyn4VObXnmgdxLXqZWzEIDxKJuX 9VAnCRDOVLTMbdtn/0CBqm/zqby0L+he9cabJeenL10nl1UMkoi8giE/OfknN9LtSk uDaM8rVpyZCRvx8YswU1aD5ywHP1XN4Teel0sygujNdY2GFl1sqsp7MbyVjZPAx8U5 LtPTadhlTKZwQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 09/15] telegram: Add send_log_file() in the DaemonClient() Date: Sat, 5 Nov 2022 01:09:16 +0700 Message-Id: <20221104180931.3852-10-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104180931.3852-1-kiizuha@gnuweeb.org> References: <20221104180931.3852-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add send_log_file() to the DaemonClient() class and declare a variable LOG_CHANNEL_ID in the config.py.example. Signed-off-by: Muhammad Rizki --- daemon/telegram/config.py.example | 4 ++++ daemon/telegram/packages/client.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/daemon/telegram/config.py.example b/daemon/telegram/config.py.example index 3818d27..221e0c1 100644 --- a/daemon/telegram/config.py.example +++ b/daemon/telegram/config.py.example @@ -4,6 +4,10 @@ from pyrogram.types import Message # Insert Telegram admin id in the list below ADMINS = [] +# Insert Telegram channel ID to send the log file +# type (int) +LOG_CHANNEL_ID = + async def adm_flt(_, __, m: Message): return m.from_user.id in ADMINS diff --git a/daemon/telegram/packages/client.py b/daemon/telegram/packages/client.py index eb282eb..6c83a5a 100644 --- a/daemon/telegram/packages/client.py +++ b/daemon/telegram/packages/client.py @@ -11,6 +11,7 @@ from email.message import Message from atom import utils from enums import Platform from logger import BotLogger +from telegram import config from telegram.database import DB from .decorator import handle_flood @@ -26,6 +27,16 @@ class DaemonClient(Client): self.logger = logger + @handle_flood + async def send_log_file(self, caption: str): + filename = self.logger.handlers[0].baseFilename + await self.send_document( + config.LOG_CHANNEL_ID, + filename, + caption=caption + ) + + @handle_flood async def send_text_email( self, -- Muhammad Rizki