From: Terry Geng Date: Tue, 3 Mar 2020 08:47:24 +0000 (+0800) Subject: fix: message too long on some extreme cases X-Git-Url: https://git.0d.be/?p=botaradio.git;a=commitdiff_plain;h=499186c738a13c36821ac4c328fd8bbab60255f5 fix: message too long on some extreme cases --- diff --git a/command.py b/command.py index ca56a72..a073df5 100644 --- a/command.py +++ b/command.py @@ -68,7 +68,7 @@ def send_multi_lines(bot, lines, text): for newline in lines: msg += br br = "
" - if len(msg) + len(newline) > 5000: + if (len(msg) + len(newline)) > (bot.mumble.get_max_message_length() - 4) != 0: # 4 == len("
") bot.send_msg(msg, text) msg = "" msg += newline @@ -668,6 +668,10 @@ def cmd_last(bot, user, text, command, parameter): def cmd_remove(bot, user, text, command, parameter): global log + if bot.download_in_progress: + bot.send_msg(constants.strings("cannot_change_when_download")) + return + # Allow to remove specific music into the queue with a number if parameter and parameter.isdigit() and int(parameter) > 0 \ and int(parameter) <= var.playlist.length(): diff --git a/configuration.default.ini b/configuration.default.ini index 52b80d7..ef38a99 100644 --- a/configuration.default.ini +++ b/configuration.default.ini @@ -190,6 +190,7 @@ not_in_my_channel = You're not in my channel, command refused! pm_not_allowed = Private message aren't allowed. too_long = This music is too long, skip! download_in_progress = Download of {item} in progress... +cannot_change_when_download = Downloading songs, please wait until the download completes. removing_item = Removed entry {item} from playlist. user_ban = You are banned, not allowed to do that! url_ban = This url is banned! diff --git a/media/playlist.py b/media/playlist.py index 5b6d17b..78cb870 100644 --- a/media/playlist.py +++ b/media/playlist.py @@ -24,7 +24,6 @@ def get_playlist_info(url, start_index=0, user=""): playlist_title = info['title'] for j in range(start_index, min(len(info['entries']), start_index + var.config.getint('bot', 'max_track_playlist'))): - print(info['entries'][j]) # Unknow String if No title into the json title = info['entries'][j]['title'] if 'title' in info['entries'][j] else "Unknown Title" # Add youtube url if the url in the json isn't a full url diff --git a/mumbleBot.py b/mumbleBot.py index b187cb5..ea8a014 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -407,6 +407,8 @@ class MumbleBot: # then no need to download return music + self.download_in_progress = True + url = music['url'] url_hash = hashlib.md5(url.encode()).hexdigest() @@ -469,6 +471,7 @@ class MumbleBot: music = util.get_music_tag_info(music) var.playlist.update(music, index) + self.download_in_progress = False return music def async_download_next(self):