From 83c458261cf07752e80a7446ac2a7a0e62d4079b Mon Sep 17 00:00:00 2001 From: elpatron68 Date: Sun, 28 Jul 2019 15:29:56 +0200 Subject: [PATCH] Fix message shortening --- mumbleBot.py | 54 +++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/mumbleBot.py b/mumbleBot.py index e669f71..f72ae6d 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -387,31 +387,37 @@ class MumbleBot: genre = s['genre'] # msg += f'{stationid}{stationname}{genre}{codec}/{bitrate}{country}' msg += '%s%s%s%s/%s%s' % (stationid, stationname, genre, codec, bitrate, country) - msg += '' - # Shorten table if message too long - if len(msg) <= 5000: - logging.debug('Result too long stage I') - msg = var.config.get('strings', 'rbqueryresult') + " :" + ' (shortened L1)' - msg += '\n' - for s in rb_stations: - stationid = s['id'] - stationname = s['stationname'] - # msg += f'' - msg += '' % (stationid, stationname) + msg += '
!rbplay IDStation Name
{stationid}{stationname}
%s%s
' + # Full message as html table + if len(msg) <= 5000: self.send_msg(msg, text) - else: - logging.debug('Result too long stage II') - msg = var.config.get('strings', 'rbqueryresult') + " :" + ' (shortened L2)' - msg += '!rbplay ID - Station Name' - for s in rb_stations: - stationid = s['id'] - stationname = s['stationname'][:12] - # msg += f'{stationid} - {stationname}' - msg += '%s - %s' % (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) + # Shorten message if message too long (stage I) + else: + logging.debug('Result too long stage I') + msg = var.config.get('strings', 'rbqueryresult') + " :" + ' (shortened L1)' + msg += '\n' + for s in rb_stations: + stationid = s['id'] + stationname = s['stationname'] + # msg += f'' + msg += '' % (stationid, stationname) + if len(msg) <= 5000: + self.send_msg(msg, text) + # Shorten message if message too long (stage II) + else: + logging.debug('Result too long stage II') + msg = var.config.get('strings', 'rbqueryresult') + " :" + ' (shortened L2)' + msg += '!rbplay ID - Station Name' + for s in rb_stations: + stationid = s['id'] + stationname = s['stationname'][:12] + # msg += f'{stationid} - {stationname}' + msg += '%s - %s' % (stationid, stationname) + if len(msg) <= 5000: + self.send_msg(msg, text) + # Message still too long + 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}
%s%s