From d78c48070943afaca635e3f76ea2cf2c50331cac Mon Sep 17 00:00:00 2001 From: elpatron68 Date: Sun, 28 Jul 2019 11:43:19 +0200 Subject: [PATCH] Shorten query results if too long --- mumbleBot.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/mumbleBot.py b/mumbleBot.py index df9b07a..94fb8e5 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -387,10 +387,28 @@ class MumbleBot: genre = s['genre'] msg += f'{stationid}{stationname}{genre}{codec}/{bitrate}{country}' msg += '' + # Shorten table if message too long if len(msg) < 5000: - self.send_msg(msg, text) + msg = var.config.get('strings', 'rbqueryresult') + " :" + ' (shortened L1)' + msg += '\n' else: - self.send_msg('Query result too long to post (> 5000 characters), please try another query.', text) + for s in rb_stations: + stationid = s['id'] + stationname = s['stationname'] + msg += f'' + if len(msg) < 5000: + self.send_msg(msg, text) + else: + msg = var.config.get('strings', 'rbqueryresult') + " :" + ' (shortened L2)' + msg += '!rbplay ID - Station Name' + for s in rb_stations: + stationid = s['id'] + stationname = s['stationname'] + msg += f'{stationid} - {stationname}' + if len(msg) < 5000: + self.send_msg(msg, text) + else: + self.send_msg('Query result too long to post (> 5000 characters), please try another query.', text) # Play a secific station (by id) from http://www.radio-browser.info API elif command == var.config.get('command', 'rb_play'): logging.debug('Play a station by ID')
!rbplay IDStation Name
{stationid}{stationname}