Fix message shortening

This commit is contained in:
elpatron68 2019-07-28 15:29:56 +02:00
parent 715e27cc43
commit 83c458261c

View File

@ -388,8 +388,11 @@ class MumbleBot:
# msg += f'<tr><td>{stationid}</td><td>{stationname}</td><td>{genre}</td><td>{codec}/{bitrate}</td><td>{country}</td></tr>'
msg += '<tr><td>%s</td><td>%s</td><td>%s</td><td>%s/%s</td><td>%s</td></tr>' % (stationid, stationname, genre, codec, bitrate, country)
msg += '</table>'
# Shorten table if message too long
# Full message as html table
if len(msg) <= 5000:
self.send_msg(msg, 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<table><tr><th>!rbplay ID</th><th>Station Name</th></tr>'
@ -398,7 +401,9 @@ class MumbleBot:
stationname = s['stationname']
# msg += f'<tr><td>{stationid}</td><td>{stationname}</td>'
msg += '<tr><td>%s</td><td>%s</td>' % (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)'
@ -410,6 +415,7 @@ class MumbleBot:
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