Skip to content

Commit

Permalink
[fix] Tweet length validation for tracks (emojis) (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanitodread authored Oct 19, 2021
1 parent a8b780e commit 1f2c16b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/gorrion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
1 change: 0 additions & 1 deletion tests/test_telegram_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 1f2c16b

Please sign in to comment.