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.125.209]) by gnuweeb.org (Postfix) with ESMTPSA id 15EE9819D2; Wed, 21 Dec 2022 01:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671586457; bh=uuH9tpqMyqsugY4kKWaFEniPoxhVA91wU9DmPRTsJPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TXKykheIYUfw+VoAJtOlAZMnHuMuS014AaC0NJ42fdnnAbbFyOOMDsC7FmFOvby0q 6kZDtjZRTo7hOpgqTbT/o/5R+2Ylov5RbRWwrTPdbjhZ/Q75SYJ5AF5JSaDpPKW7DG cTuGi/0ji/+7v+AI2sOhI/ZEkuSlUq/EaUO2jlk5mjtWKg5sZiUZ5YezpWzh0XGB7I XHR1Wstl49ZeyCB+Kr1Kya/OPA3g8S1JZ6ondaqBUH05coVvm2uKI0fjawpzntGu+m v5nLW1M/KTZHr51w/qEySoZAQVILqW7U/V6ExZ079CHwRGM4C+1uYsV1+uB2hD9wUh v6xXBqB+5EJog== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v4 03/17] fix: utils: add a substr for the patch media caption Date: Wed, 21 Dec 2022 08:33:33 +0700 Message-Id: <20221221013347.1704-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221221013347.1704-1-kiizuha@gnuweeb.org> References: <20221221013347.1704-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Commit bb8855bf5e344 ("Fix the storage management after the refactor was happened") did not care with the caption length when sending an attachment. This leads to error when the caption length hits the limit. Add a substr() call to cut the caption if it's too long to avoid such an error. P.S.: at the "was happened" part. Corrected-by: Alviro Iskandar Setiawan 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 6597c41..ed59812 100644 --- a/daemon/atom/utils.py +++ b/daemon/atom/utils.py @@ -248,9 +248,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