From 1f2c16b7402c237dfb4b47f0fa0afeb3bff7bd19 Mon Sep 17 00:00:00 2001 From: Juan Sandoval Date: Mon, 18 Oct 2021 20:11:22 -0700 Subject: [PATCH] [fix] Tweet length validation for tracks (emojis) (#47) --- src/gorrion.py | 5 ++++- tests/test_telegram_bot.py | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gorrion.py b/src/gorrion.py index 1259ce9..0457c2a 100644 --- a/src/gorrion.py +++ b/src/gorrion.py @@ -123,7 +123,10 @@ def build_status(self, album: Album, config: TweetConfig): return tweet_status def is_valid_tweet_status(self, status: str) -> bool: - return len(status) <= self._twitter.max_tweet_length + # Tracks command injects clock emoji ⏳ which counts as two characters for Twitter. We need to add one more + # character for each ⏳. + extra_chars = ' ' * status.count('⏳') + return len(status + extra_chars) <= self._twitter.max_tweet_length def lyrics_to_tweets(self, lyrics: list) -> list: lyric_tweets = [] diff --git a/tests/test_telegram_bot.py b/tests/test_telegram_bot.py index 2eb33d0..e6348f5 100644 --- a/tests/test_telegram_bot.py +++ b/tests/test_telegram_bot.py @@ -188,7 +188,6 @@ def test_process_playing_album_command_with_error(self, gorrion_mock, bot_mock, @patch('src.telegram_bot.Bot') @patch('src.telegram_bot.Gorrion') def test_process_playing_album_with_tracks_command(self, gorrion_mock, bot_mock, update_mock): - tweet = PublishedTweet(id_='1', tweet='tweet1', entity=None) update = MagicMock() update.message.text = '/tracks' update.message.chat.id = '123'