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 autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.209]) by gnuweeb.org (Postfix) with ESMTPSA id 9CCDD8194D; Mon, 19 Dec 2022 23:57:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671494270; bh=Y2cSbkqEN2GTL0GBQIoPumkz2o4IrhFViIZ7k7BJ/mQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EL4LOFLjmMbdFtOY78j+qU8K0MKWDOXT+dUctqGrXkyJ6Sh7UfcPjpUfiLohe6Pok /jsGCBBVTaXYnBEJrRY+lLyjGRkykx8fZ6p8Z49GHTH1P6iRS6bF9wb/P4woc+IUHT Aeuz5/mF/RkmGwGeMC3BjplJHKwjTKGqsoapsg+xmZKcdHG0IqkPYypAXrSvxISZue CLOIuBUEJPG5fvZFWmjt2b9XrTBWdSi3g5EgiWZZy/O5NWg8wFyl4P1VbEVxyYSRoy sMcu63CWN1FQ9+MJiAPM1/k2usC9k5UyzBNuWHDZSkrV9sFCRGr1hX7pEGWGRuj+vM eZQGrucQbk3FA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v3 03/17] fix: utils: add a substr for the patch media caption Date: Tue, 20 Dec 2022 06:57:07 +0700 Message-Id: <20221219235721.126-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221219235721.126-1-kiizuha@gnuweeb.org> References: <20221219235721.126-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add a substr caption for the patch email to avoid media caption too long. Regarding this commit bb8855bf5e, it's forget to add a substr caption method, which is it will get media caption too long error for both Discord and Telegram bot. Signed-off-by: Muhammad Rizki --- daemon/atom/utils.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/daemon/atom/utils.py b/daemon/atom/utils.py index 8a6c1a8..0ba649a 100644 --- a/daemon/atom/utils.py +++ b/daemon/atom/utils.py @@ -246,9 +246,20 @@ def prepare_patch(mail: Message, text, url, platform: Platform): f.write(write_payload) - caption = "#patch #ml" + caption = f"#patch #ml\n{cap}" if platform is Platform.TELEGRAM: - caption += fix_utf8_char("\n" + cap, True) + # Telegram media caption is limit to 1024 + # set limit to 1021, because we will add "..." + if len(caption) >= 1024: + caption = caption[:1021] + "..." + + fixed = fix_utf8_char(caption, html_escape=True) + return tmp, file, fixed, url + + # Discord attachment caption limit about 1998 or 2000 + # set limit to 1995, because we will add "..." + if len(caption) >= 1998: + caption = caption[:1995] + "..." return tmp, file, caption, url -- Muhammad Rizki