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.198]) by gnuweeb.org (Postfix) with ESMTPSA id AD24481549; Wed, 9 Nov 2022 02:50:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1667962226; bh=a66oPPgNQrCfmj0rLquBCoWAfwHwl4CJ9eqIP/4xb9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pvzqJpnHr6m0MRqZU9/lBR7cbfDo0EGZOonSSj5NQbXBUpxQCDLQq3KtgNRiEtmV5 uqtuciydq9+GI+8uoWjU85F0lDlzc0bNxhZ01WwJUQYLslqdaIgSwkQm9Rs9oFTq7x dlyNI2q7r9+d7Nd5+XIK6rPEvJourzpiymVyFHRivjBtn48mAThoaT4GfTkSQ8ygI2 nC9jXF3iWQD7FgFrM224PLxnFj+Cp/4Xi77WSYwjRxnKycr1y/4XDGRqdO4p7NXByC oQhVlRD3XIhaCg+MXS0/FMIw4g6GCPnpTTgE1A7es1vgbZwHiNb8qQug01iCKGZeGr 6DcXhiDuMYllQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 03/17] fix: utils: add a substr for the patch media caption Date: Wed, 9 Nov 2022 09:49:48 +0700 Message-Id: <20221109025002.258-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221109025002.258-1-kiizuha@gnuweeb.org> References: <20221109025002.258-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add a substr caption for the patch email to avoid MediaCaptionTooLong for the Telegram bot. Regarding to commit 125111a7, its forget to add a substring to trim the media caption for the Telegram bot, because Telegram only allow media caption to 1024 only, so trim it to 1020. Fixes: 125111a7 ("daemon: Full refactor everything about scraper") Signed-off-by: Muhammad Rizki --- daemon/atom/utils.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/daemon/atom/utils.py b/daemon/atom/utils.py index 9483d26..2e85461 100644 --- a/daemon/atom/utils.py +++ b/daemon/atom/utils.py @@ -186,9 +186,11 @@ def create_template(thread: Message, platform: Platform, to=None, cc=None): cc = extract_list("cc", thread) if platform is Platform.TELEGRAM: substr = 4000 + media_substr = 1010 border = f"\n{'-'*72}" else: substr = 1900 + media_substr = None border = f"\n{'-'*80}" subject = thread.get('subject') @@ -201,15 +203,18 @@ def create_template(thread: Message, platform: Platform, to=None, cc=None): if is_patch: ret += content - else: - ret += content.strip().replace("\t", " ") + if not media_substr: + return ret, files, is_patch - if len(ret) >= substr: - ret = ret[:substr] + "..." + if len(ret) >= media_substr: + return ret[:media_substr] + "...", files, is_patch - ret = fix_utf8_char(ret, platform is Platform.TELEGRAM) - ret += border + ret += content.strip().replace("\t", " "*8) + if len(ret) >= substr: + ret = ret[:substr] + "..." + ret = fix_utf8_char(ret, platform is Platform.TELEGRAM) + ret += border return ret, files, is_patch -- Muhammad Rizki