refactor: Rename constants.string into tr.
This commit is contained in:
338
command.py
338
command.py
@ -6,7 +6,7 @@ import json
|
|||||||
import re
|
import re
|
||||||
import pymumble_py3 as pymumble
|
import pymumble_py3 as pymumble
|
||||||
|
|
||||||
import constants
|
from constants import tr, commands
|
||||||
import interface
|
import interface
|
||||||
import media.system
|
import media.system
|
||||||
import util
|
import util
|
||||||
@ -22,56 +22,56 @@ log = logging.getLogger("bot")
|
|||||||
|
|
||||||
|
|
||||||
def register_all_commands(bot):
|
def register_all_commands(bot):
|
||||||
bot.register_command(constants.commands('joinme'), cmd_joinme, access_outside_channel=True)
|
bot.register_command(commands('joinme'), cmd_joinme, access_outside_channel=True)
|
||||||
bot.register_command(constants.commands('user_ban'), cmd_user_ban, no_partial_match=True, admin=True)
|
bot.register_command(commands('user_ban'), cmd_user_ban, no_partial_match=True, admin=True)
|
||||||
bot.register_command(constants.commands('user_unban'), cmd_user_unban, no_partial_match=True, admin=True)
|
bot.register_command(commands('user_unban'), cmd_user_unban, no_partial_match=True, admin=True)
|
||||||
bot.register_command(constants.commands('url_ban_list'), cmd_url_ban_list, no_partial_match=True, admin=True)
|
bot.register_command(commands('url_ban_list'), cmd_url_ban_list, no_partial_match=True, admin=True)
|
||||||
bot.register_command(constants.commands('url_ban'), cmd_url_ban, no_partial_match=True, admin=True)
|
bot.register_command(commands('url_ban'), cmd_url_ban, no_partial_match=True, admin=True)
|
||||||
bot.register_command(constants.commands('url_unban'), cmd_url_unban, no_partial_match=True, admin=True)
|
bot.register_command(commands('url_unban'), cmd_url_unban, no_partial_match=True, admin=True)
|
||||||
bot.register_command(constants.commands('play'), cmd_play)
|
bot.register_command(commands('play'), cmd_play)
|
||||||
bot.register_command(constants.commands('pause'), cmd_pause)
|
bot.register_command(commands('pause'), cmd_pause)
|
||||||
bot.register_command(constants.commands('play_file'), cmd_play_file)
|
bot.register_command(commands('play_file'), cmd_play_file)
|
||||||
bot.register_command(constants.commands('play_file_match'), cmd_play_file_match)
|
bot.register_command(commands('play_file_match'), cmd_play_file_match)
|
||||||
bot.register_command(constants.commands('play_url'), cmd_play_url)
|
bot.register_command(commands('play_url'), cmd_play_url)
|
||||||
bot.register_command(constants.commands('play_playlist'), cmd_play_playlist)
|
bot.register_command(commands('play_playlist'), cmd_play_playlist)
|
||||||
bot.register_command(constants.commands('play_radio'), cmd_play_radio)
|
bot.register_command(commands('play_radio'), cmd_play_radio)
|
||||||
bot.register_command(constants.commands('play_tag'), cmd_play_tags)
|
bot.register_command(commands('play_tag'), cmd_play_tags)
|
||||||
bot.register_command(constants.commands('rb_query'), cmd_rb_query)
|
bot.register_command(commands('rb_query'), cmd_rb_query)
|
||||||
bot.register_command(constants.commands('rb_play'), cmd_rb_play)
|
bot.register_command(commands('rb_play'), cmd_rb_play)
|
||||||
bot.register_command(constants.commands('yt_search'), cmd_yt_search)
|
bot.register_command(commands('yt_search'), cmd_yt_search)
|
||||||
bot.register_command(constants.commands('yt_play'), cmd_yt_play)
|
bot.register_command(commands('yt_play'), cmd_yt_play)
|
||||||
bot.register_command(constants.commands('help'), cmd_help, no_partial_match=False, access_outside_channel=True)
|
bot.register_command(commands('help'), cmd_help, no_partial_match=False, access_outside_channel=True)
|
||||||
bot.register_command(constants.commands('stop'), cmd_stop)
|
bot.register_command(commands('stop'), cmd_stop)
|
||||||
bot.register_command(constants.commands('clear'), cmd_clear)
|
bot.register_command(commands('clear'), cmd_clear)
|
||||||
bot.register_command(constants.commands('kill'), cmd_kill, admin=True)
|
bot.register_command(commands('kill'), cmd_kill, admin=True)
|
||||||
bot.register_command(constants.commands('update'), cmd_update, no_partial_match=True, admin=True)
|
bot.register_command(commands('update'), cmd_update, no_partial_match=True, admin=True)
|
||||||
bot.register_command(constants.commands('stop_and_getout'), cmd_stop_and_getout)
|
bot.register_command(commands('stop_and_getout'), cmd_stop_and_getout)
|
||||||
bot.register_command(constants.commands('volume'), cmd_volume)
|
bot.register_command(commands('volume'), cmd_volume)
|
||||||
bot.register_command(constants.commands('ducking'), cmd_ducking)
|
bot.register_command(commands('ducking'), cmd_ducking)
|
||||||
bot.register_command(constants.commands('ducking_threshold'), cmd_ducking_threshold)
|
bot.register_command(commands('ducking_threshold'), cmd_ducking_threshold)
|
||||||
bot.register_command(constants.commands('ducking_volume'), cmd_ducking_volume)
|
bot.register_command(commands('ducking_volume'), cmd_ducking_volume)
|
||||||
bot.register_command(constants.commands('current_music'), cmd_current_music)
|
bot.register_command(commands('current_music'), cmd_current_music)
|
||||||
bot.register_command(constants.commands('skip'), cmd_skip)
|
bot.register_command(commands('skip'), cmd_skip)
|
||||||
bot.register_command(constants.commands('last'), cmd_last)
|
bot.register_command(commands('last'), cmd_last)
|
||||||
bot.register_command(constants.commands('remove'), cmd_remove)
|
bot.register_command(commands('remove'), cmd_remove)
|
||||||
bot.register_command(constants.commands('list_file'), cmd_list_file)
|
bot.register_command(commands('list_file'), cmd_list_file)
|
||||||
bot.register_command(constants.commands('queue'), cmd_queue)
|
bot.register_command(commands('queue'), cmd_queue)
|
||||||
bot.register_command(constants.commands('random'), cmd_random)
|
bot.register_command(commands('random'), cmd_random)
|
||||||
bot.register_command(constants.commands('repeat'), cmd_repeat)
|
bot.register_command(commands('repeat'), cmd_repeat)
|
||||||
bot.register_command(constants.commands('mode'), cmd_mode)
|
bot.register_command(commands('mode'), cmd_mode)
|
||||||
bot.register_command(constants.commands('add_tag'), cmd_add_tag)
|
bot.register_command(commands('add_tag'), cmd_add_tag)
|
||||||
bot.register_command(constants.commands('remove_tag'), cmd_remove_tag)
|
bot.register_command(commands('remove_tag'), cmd_remove_tag)
|
||||||
bot.register_command(constants.commands('find_tagged'), cmd_find_tagged)
|
bot.register_command(commands('find_tagged'), cmd_find_tagged)
|
||||||
bot.register_command(constants.commands('search'), cmd_search_library)
|
bot.register_command(commands('search'), cmd_search_library)
|
||||||
bot.register_command(constants.commands('add_from_shortlist'), cmd_shortlist)
|
bot.register_command(commands('add_from_shortlist'), cmd_shortlist)
|
||||||
bot.register_command(constants.commands('delete_from_library'), cmd_delete_from_library)
|
bot.register_command(commands('delete_from_library'), cmd_delete_from_library)
|
||||||
bot.register_command(constants.commands('drop_database'), cmd_drop_database, no_partial_match=True, admin=True)
|
bot.register_command(commands('drop_database'), cmd_drop_database, no_partial_match=True, admin=True)
|
||||||
bot.register_command(constants.commands('rescan'), cmd_refresh_cache, no_partial_match=True)
|
bot.register_command(commands('rescan'), cmd_refresh_cache, no_partial_match=True)
|
||||||
bot.register_command(constants.commands('requests_webinterface_access'), cmd_web_access)
|
bot.register_command(commands('requests_webinterface_access'), cmd_web_access)
|
||||||
bot.register_command(constants.commands('add_webinterface_user'), cmd_web_user_add, admin=True)
|
bot.register_command(commands('add_webinterface_user'), cmd_web_user_add, admin=True)
|
||||||
bot.register_command(constants.commands('remove_webinterface_user'), cmd_web_user_remove, admin=True)
|
bot.register_command(commands('remove_webinterface_user'), cmd_web_user_remove, admin=True)
|
||||||
bot.register_command(constants.commands('list_webinterface_user'), cmd_web_user_list, admin=True)
|
bot.register_command(commands('list_webinterface_user'), cmd_web_user_list, admin=True)
|
||||||
bot.register_command(constants.commands('change_user_password'), cmd_user_password, no_partial_match=True)
|
bot.register_command(commands('change_user_password'), cmd_user_password, no_partial_match=True)
|
||||||
# Just for debug use
|
# Just for debug use
|
||||||
bot.register_command('rtrms', cmd_real_time_rms, True)
|
bot.register_command('rtrms', cmd_real_time_rms, True)
|
||||||
# bot.register_command('loop', cmd_loop_state, True)
|
# bot.register_command('loop', cmd_loop_state, True)
|
||||||
@ -160,7 +160,7 @@ def cmd_url_ban(bot, user, text, command, parameter):
|
|||||||
var.cache.free_and_delete(item.id)
|
var.cache.free_and_delete(item.id)
|
||||||
var.playlist.remove_by_id(item.id)
|
var.playlist.remove_by_id(item.id)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_url_ban_list(bot, user, text, command, parameter):
|
def cmd_url_ban_list(bot, user, text, command, parameter):
|
||||||
@ -184,14 +184,14 @@ def cmd_play(bot, user, text, command, parameter):
|
|||||||
if params[0].isdigit() and 1 <= int(params[0]) <= len(var.playlist):
|
if params[0].isdigit() and 1 <= int(params[0]) <= len(var.playlist):
|
||||||
index = int(params[0])
|
index = int(params[0])
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('invalid_index', index=parameter), text)
|
bot.send_msg(tr('invalid_index', index=parameter), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(params) > 1:
|
if len(params) > 1:
|
||||||
try:
|
try:
|
||||||
start_at = util.parse_time(params[1])
|
start_at = util.parse_time(params[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(var.playlist) > 0:
|
if len(var.playlist) > 0:
|
||||||
@ -204,14 +204,14 @@ def cmd_play(bot, user, text, command, parameter):
|
|||||||
bot.send_msg(var.playlist.current_item().format_current_playing(), text)
|
bot.send_msg(var.playlist.current_item().format_current_playing(), text)
|
||||||
else:
|
else:
|
||||||
bot.is_pause = False
|
bot.is_pause = False
|
||||||
bot.send_msg(constants.strings('queue_empty'), text)
|
bot.send_msg(tr('queue_empty'), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_pause(bot, user, text, command, parameter):
|
def cmd_pause(bot, user, text, command, parameter):
|
||||||
global log
|
global log
|
||||||
|
|
||||||
bot.pause()
|
bot.pause()
|
||||||
bot.send_channel_msg(constants.strings('paused'))
|
bot.send_channel_msg(tr('paused'))
|
||||||
|
|
||||||
|
|
||||||
def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=False):
|
def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=False):
|
||||||
@ -222,7 +222,7 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals
|
|||||||
if music_wrappers:
|
if music_wrappers:
|
||||||
var.playlist.append(music_wrappers[0])
|
var.playlist.append(music_wrappers[0])
|
||||||
log.info("cmd: add to playlist: " + music_wrappers[0].format_debug_string())
|
log.info("cmd: add to playlist: " + music_wrappers[0].format_debug_string())
|
||||||
bot.send_msg(constants.strings('file_added', item=music_wrappers[0].format_song_string()), text)
|
bot.send_msg(tr('file_added', item=music_wrappers[0].format_song_string()), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
# assume parameter is a folder
|
# assume parameter is a folder
|
||||||
@ -230,7 +230,7 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals
|
|||||||
.and_equal('type', 'file')
|
.and_equal('type', 'file')
|
||||||
.and_like('path', parameter + '%')), user)
|
.and_like('path', parameter + '%')), user)
|
||||||
if music_wrappers:
|
if music_wrappers:
|
||||||
msgs = [constants.strings('multiple_file_added')]
|
msgs = [tr('multiple_file_added')]
|
||||||
|
|
||||||
for music_wrapper in music_wrappers:
|
for music_wrapper in music_wrappers:
|
||||||
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
||||||
@ -249,20 +249,20 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals
|
|||||||
music_wrapper = get_cached_wrapper_from_dict(matches[0], user)
|
music_wrapper = get_cached_wrapper_from_dict(matches[0], user)
|
||||||
var.playlist.append(music_wrapper)
|
var.playlist.append(music_wrapper)
|
||||||
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
||||||
bot.send_msg(constants.strings('file_added', item=music_wrapper.format_song_string()), text)
|
bot.send_msg(tr('file_added', item=music_wrapper.format_song_string()), text)
|
||||||
return
|
return
|
||||||
elif len(matches) > 1:
|
elif len(matches) > 1:
|
||||||
song_shortlist = matches
|
song_shortlist = matches
|
||||||
msgs = [constants.strings('multiple_matches')]
|
msgs = [tr('multiple_matches')]
|
||||||
for index, match in enumerate(matches):
|
for index, match in enumerate(matches):
|
||||||
msgs.append("<b>{:d}</b> - <b>{:s}</b> ({:s})".format(
|
msgs.append("<b>{:d}</b> - <b>{:s}</b> ({:s})".format(
|
||||||
index + 1, match['title'], match['path']))
|
index + 1, match['title'], match['path']))
|
||||||
msgs.append(constants.strings("shortlist_instruction"))
|
msgs.append(tr("shortlist_instruction"))
|
||||||
send_multi_lines(bot, msgs, text)
|
send_multi_lines(bot, msgs, text)
|
||||||
return
|
return
|
||||||
|
|
||||||
if do_not_refresh_cache:
|
if do_not_refresh_cache:
|
||||||
bot.send_msg(constants.strings("no_file"), text)
|
bot.send_msg(tr("no_file"), text)
|
||||||
else:
|
else:
|
||||||
var.cache.build_dir_cache()
|
var.cache.build_dir_cache()
|
||||||
cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=True)
|
cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=True)
|
||||||
@ -273,7 +273,7 @@ def cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cach
|
|||||||
|
|
||||||
if parameter:
|
if parameter:
|
||||||
file_dicts = var.music_db.query_music(Condition().and_equal('type', 'file'))
|
file_dicts = var.music_db.query_music(Condition().and_equal('type', 'file'))
|
||||||
msgs = [constants.strings('multiple_file_added') + "<ul>"]
|
msgs = [tr('multiple_file_added') + "<ul>"]
|
||||||
try:
|
try:
|
||||||
count = 0
|
count = 0
|
||||||
music_wrappers = []
|
music_wrappers = []
|
||||||
@ -299,16 +299,16 @@ def cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cach
|
|||||||
send_multi_lines_in_channel(bot, msgs, "")
|
send_multi_lines_in_channel(bot, msgs, "")
|
||||||
else:
|
else:
|
||||||
if do_not_refresh_cache:
|
if do_not_refresh_cache:
|
||||||
bot.send_msg(constants.strings("no_file"), text)
|
bot.send_msg(tr("no_file"), text)
|
||||||
else:
|
else:
|
||||||
var.cache.build_dir_cache()
|
var.cache.build_dir_cache()
|
||||||
cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cache=True)
|
cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cache=True)
|
||||||
|
|
||||||
except re.error as e:
|
except re.error as e:
|
||||||
msg = constants.strings('wrong_pattern', error=str(e))
|
msg = tr('wrong_pattern', error=str(e))
|
||||||
bot.send_msg(msg, text)
|
bot.send_msg(msg, text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_play_url(bot, user, text, command, parameter):
|
def cmd_play_url(bot, user, text, command, parameter):
|
||||||
@ -320,12 +320,12 @@ def cmd_play_url(bot, user, text, command, parameter):
|
|||||||
var.playlist.append(music_wrapper)
|
var.playlist.append(music_wrapper)
|
||||||
|
|
||||||
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
||||||
bot.send_msg(constants.strings('file_added', item=music_wrapper.format_song_string()), text)
|
bot.send_msg(tr('file_added', item=music_wrapper.format_song_string()), text)
|
||||||
if len(var.playlist) == 2:
|
if len(var.playlist) == 2:
|
||||||
# If I am the second item on the playlist. (I am the next one!)
|
# If I am the second item on the playlist. (I am the next one!)
|
||||||
bot.async_download_next()
|
bot.async_download_next()
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_play_playlist(bot, user, text, command, parameter):
|
def cmd_play_playlist(bot, user, text, command, parameter):
|
||||||
@ -345,7 +345,7 @@ def cmd_play_playlist(bot, user, text, command, parameter):
|
|||||||
for music in items:
|
for music in items:
|
||||||
log.info("cmd: add to playlist: " + music.format_debug_string())
|
log.info("cmd: add to playlist: " + music.format_debug_string())
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings("playlist_fetching_failed"), text)
|
bot.send_msg(tr("playlist_fetching_failed"), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_play_radio(bot, user, text, command, parameter):
|
def cmd_play_radio(bot, user, text, command, parameter):
|
||||||
@ -353,7 +353,7 @@ def cmd_play_radio(bot, user, text, command, parameter):
|
|||||||
|
|
||||||
if not parameter:
|
if not parameter:
|
||||||
all_radio = var.config.items('radio')
|
all_radio = var.config.items('radio')
|
||||||
msg = constants.strings('preconfigurated_radio')
|
msg = tr('preconfigurated_radio')
|
||||||
for i in all_radio:
|
for i in all_radio:
|
||||||
comment = ""
|
comment = ""
|
||||||
if len(i[1].split(maxsplit=1)) == 2:
|
if len(i[1].split(maxsplit=1)) == 2:
|
||||||
@ -370,9 +370,9 @@ def cmd_play_radio(bot, user, text, command, parameter):
|
|||||||
|
|
||||||
var.playlist.append(music_wrapper)
|
var.playlist.append(music_wrapper)
|
||||||
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
||||||
bot.send_msg(constants.strings('file_added', item=music_wrapper.format_song_string()), text)
|
bot.send_msg(tr('file_added', item=music_wrapper.format_song_string()), text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('bad_url'), text)
|
bot.send_msg(tr('bad_url'), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_rb_query(bot, user, text, command, parameter):
|
def cmd_rb_query(bot, user, text, command, parameter):
|
||||||
@ -381,13 +381,13 @@ def cmd_rb_query(bot, user, text, command, parameter):
|
|||||||
log.info('cmd: Querying radio stations')
|
log.info('cmd: Querying radio stations')
|
||||||
if not parameter:
|
if not parameter:
|
||||||
log.debug('rbquery without parameter')
|
log.debug('rbquery without parameter')
|
||||||
msg = constants.strings('rb_query_empty')
|
msg = tr('rb_query_empty')
|
||||||
bot.send_msg(msg, text)
|
bot.send_msg(msg, text)
|
||||||
else:
|
else:
|
||||||
log.debug('cmd: Found query parameter: ' + parameter)
|
log.debug('cmd: Found query parameter: ' + parameter)
|
||||||
rb = RadioBrowser()
|
rb = RadioBrowser()
|
||||||
rb_stations = rb.search(name=parameter, name_exact=False)
|
rb_stations = rb.search(name=parameter, name_exact=False)
|
||||||
msg = constants.strings('rb_query_result')
|
msg = tr('rb_query_result')
|
||||||
msg += '\n<table><tr><th>!rbplay ID</th><th>Station Name</th><th>Genre</th><th>Codec/Bitrate</th><th>Country</th></tr>'
|
msg += '\n<table><tr><th>!rbplay ID</th><th>Station Name</th><th>Genre</th><th>Codec/Bitrate</th><th>Country</th></tr>'
|
||||||
if not rb_stations:
|
if not rb_stations:
|
||||||
log.debug(f"cmd: No matches found for rbquery {parameter}")
|
log.debug(f"cmd: No matches found for rbquery {parameter}")
|
||||||
@ -408,7 +408,7 @@ def cmd_rb_query(bot, user, text, command, parameter):
|
|||||||
# Shorten message if message too long (stage I)
|
# Shorten message if message too long (stage I)
|
||||||
else:
|
else:
|
||||||
log.debug('Result too long stage I')
|
log.debug('Result too long stage I')
|
||||||
msg = constants.strings('rb_query_result') + ' (shortened L1)'
|
msg = tr('rb_query_result') + ' (shortened L1)'
|
||||||
msg += '\n<table><tr><th>!rbplay ID</th><th>Station Name</th></tr>'
|
msg += '\n<table><tr><th>!rbplay ID</th><th>Station Name</th></tr>'
|
||||||
for s in rb_stations:
|
for s in rb_stations:
|
||||||
station_id = s['stationuuid']
|
station_id = s['stationuuid']
|
||||||
@ -420,7 +420,7 @@ def cmd_rb_query(bot, user, text, command, parameter):
|
|||||||
# Shorten message if message too long (stage II)
|
# Shorten message if message too long (stage II)
|
||||||
else:
|
else:
|
||||||
log.debug('Result too long stage II')
|
log.debug('Result too long stage II')
|
||||||
msg = constants.strings('rb_query_result') + ' (shortened L2)'
|
msg = tr('rb_query_result') + ' (shortened L2)'
|
||||||
msg += '!rbplay ID - Station Name'
|
msg += '!rbplay ID - Station Name'
|
||||||
for s in rb_stations:
|
for s in rb_stations:
|
||||||
station_id = s['stationuuid']
|
station_id = s['stationuuid']
|
||||||
@ -439,7 +439,7 @@ def cmd_rb_play(bot, user, text, command, parameter):
|
|||||||
log.debug('cmd: Play a station by ID')
|
log.debug('cmd: Play a station by ID')
|
||||||
if not parameter:
|
if not parameter:
|
||||||
log.debug('rbplay without parameter')
|
log.debug('rbplay without parameter')
|
||||||
msg = constants.strings('rb_play_empty')
|
msg = tr('rb_play_empty')
|
||||||
bot.send_msg(msg, text)
|
bot.send_msg(msg, text)
|
||||||
else:
|
else:
|
||||||
log.debug('cmd: Retreiving url for station ID ' + parameter)
|
log.debug('cmd: Retreiving url for station ID ' + parameter)
|
||||||
@ -488,9 +488,9 @@ def cmd_yt_search(bot, user, text, command, parameter):
|
|||||||
'title': result[1]
|
'title': result[1]
|
||||||
} for result in yt_last_result[yt_last_page * item_per_page: item_per_page]]
|
} for result in yt_last_result[yt_last_page * item_per_page: item_per_page]]
|
||||||
msg = _yt_format_result(yt_last_result, yt_last_page * item_per_page, item_per_page)
|
msg = _yt_format_result(yt_last_result, yt_last_page * item_per_page, item_per_page)
|
||||||
bot.send_msg(constants.strings('yt_result', result_table=msg), text)
|
bot.send_msg(tr('yt_result', result_table=msg), text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('yt_no_more'), text)
|
bot.send_msg(tr('yt_no_more'), text)
|
||||||
|
|
||||||
# if query
|
# if query
|
||||||
else:
|
else:
|
||||||
@ -501,11 +501,11 @@ def cmd_yt_search(bot, user, text, command, parameter):
|
|||||||
song_shortlist = [{'type': 'url', 'url': "https://www.youtube.com/watch?v=" + result[0]}
|
song_shortlist = [{'type': 'url', 'url': "https://www.youtube.com/watch?v=" + result[0]}
|
||||||
for result in results[0: item_per_page]]
|
for result in results[0: item_per_page]]
|
||||||
msg = _yt_format_result(results, 0, item_per_page)
|
msg = _yt_format_result(results, 0, item_per_page)
|
||||||
bot.send_msg(constants.strings('yt_result', result_table=msg), text)
|
bot.send_msg(tr('yt_result', result_table=msg), text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('yt_query_error'), text)
|
bot.send_msg(tr('yt_query_error'), text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def _yt_format_result(results, start, count):
|
def _yt_format_result(results, start, count):
|
||||||
@ -529,16 +529,16 @@ def cmd_yt_play(bot, user, text, command, parameter):
|
|||||||
url = "https://www.youtube.com/watch?v=" + yt_last_result[0][0]
|
url = "https://www.youtube.com/watch?v=" + yt_last_result[0][0]
|
||||||
cmd_play_url(bot, user, text, command, url)
|
cmd_play_url(bot, user, text, command, url)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('yt_query_error'), text)
|
bot.send_msg(tr('yt_query_error'), text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_help(bot, user, text, command, parameter):
|
def cmd_help(bot, user, text, command, parameter):
|
||||||
global log
|
global log
|
||||||
bot.send_msg(constants.strings('help'), text)
|
bot.send_msg(tr('help'), text)
|
||||||
if bot.is_admin(user):
|
if bot.is_admin(user):
|
||||||
bot.send_msg(constants.strings('admin_help'), text)
|
bot.send_msg(tr('admin_help'), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_stop(bot, user, text, command, parameter):
|
def cmd_stop(bot, user, text, command, parameter):
|
||||||
@ -549,14 +549,14 @@ def cmd_stop(bot, user, text, command, parameter):
|
|||||||
cmd_clear(bot, user, text, command, parameter)
|
cmd_clear(bot, user, text, command, parameter)
|
||||||
else:
|
else:
|
||||||
bot.stop()
|
bot.stop()
|
||||||
bot.send_msg(constants.strings('stopped'), text)
|
bot.send_msg(tr('stopped'), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_clear(bot, user, text, command, parameter):
|
def cmd_clear(bot, user, text, command, parameter):
|
||||||
global log
|
global log
|
||||||
|
|
||||||
bot.clear()
|
bot.clear()
|
||||||
bot.send_msg(constants.strings('cleared'), text)
|
bot.send_msg(tr('cleared'), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_kill(bot, user, text, command, parameter):
|
def cmd_kill(bot, user, text, command, parameter):
|
||||||
@ -571,12 +571,12 @@ def cmd_update(bot, user, text, command, parameter):
|
|||||||
|
|
||||||
if bot.is_admin(user):
|
if bot.is_admin(user):
|
||||||
bot.mumble.users[text.actor].send_text_message(
|
bot.mumble.users[text.actor].send_text_message(
|
||||||
constants.strings('start_updating'))
|
tr('start_updating'))
|
||||||
msg = util.update(bot.version)
|
msg = util.update(bot.version)
|
||||||
bot.mumble.users[text.actor].send_text_message(msg)
|
bot.mumble.users[text.actor].send_text_message(msg)
|
||||||
else:
|
else:
|
||||||
bot.mumble.users[text.actor].send_text_message(
|
bot.mumble.users[text.actor].send_text_message(
|
||||||
constants.strings('not_admin'))
|
tr('not_admin'))
|
||||||
|
|
||||||
|
|
||||||
def cmd_stop_and_getout(bot, user, text, command, parameter):
|
def cmd_stop_and_getout(bot, user, text, command, parameter):
|
||||||
@ -595,11 +595,11 @@ def cmd_volume(bot, user, text, command, parameter):
|
|||||||
# The volume is a percentage
|
# The volume is a percentage
|
||||||
if parameter and parameter.isdigit() and 0 <= int(parameter) <= 100:
|
if parameter and parameter.isdigit() and 0 <= int(parameter) <= 100:
|
||||||
bot.volume_helper.set_volume(float(parameter) / 100.0)
|
bot.volume_helper.set_volume(float(parameter) / 100.0)
|
||||||
bot.send_msg(constants.strings('change_volume', volume=parameter, user=bot.mumble.users[text.actor]['name']), text)
|
bot.send_msg(tr('change_volume', volume=parameter, user=bot.mumble.users[text.actor]['name']), text)
|
||||||
var.db.set('bot', 'volume', str(float(parameter) / 100.0))
|
var.db.set('bot', 'volume', str(float(parameter) / 100.0))
|
||||||
log.info(f'cmd: volume set to {float(parameter) / 100.0}')
|
log.info(f'cmd: volume set to {float(parameter) / 100.0}')
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('current_volume', volume=int(bot.volume_helper.plain_volume_set * 100)), text)
|
bot.send_msg(tr('current_volume', volume=int(bot.volume_helper.plain_volume_set * 100)), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_ducking(bot, user, text, command, parameter):
|
def cmd_ducking(bot, user, text, command, parameter):
|
||||||
@ -608,7 +608,7 @@ def cmd_ducking(bot, user, text, command, parameter):
|
|||||||
if parameter == "" or parameter == "on":
|
if parameter == "" or parameter == "on":
|
||||||
bot.is_ducking = True
|
bot.is_ducking = True
|
||||||
var.db.set('bot', 'ducking', True)
|
var.db.set('bot', 'ducking', True)
|
||||||
bot.mumble.callbacks.set_callback(pymumble.constants.PYMUMBLE_CLBK_SOUNDRECEIVED, bot.ducking_sound_received)
|
bot.mumble.callbacks.set_callback(pymumble.c.PYMUMBLE_CLBK_SOUNDRECEIVED, bot.ducking_sound_received)
|
||||||
bot.mumble.set_receive_sound(True)
|
bot.mumble.set_receive_sound(True)
|
||||||
log.info('cmd: ducking is on')
|
log.info('cmd: ducking is on')
|
||||||
msg = "Ducking on."
|
msg = "Ducking on."
|
||||||
@ -641,11 +641,11 @@ def cmd_ducking_volume(bot, user, text, command, parameter):
|
|||||||
# The volume is a percentage
|
# The volume is a percentage
|
||||||
if parameter and parameter.isdigit() and 0 <= int(parameter) <= 100:
|
if parameter and parameter.isdigit() and 0 <= int(parameter) <= 100:
|
||||||
bot.volume_helper.set_ducking_volume(float(parameter) / 100.0)
|
bot.volume_helper.set_ducking_volume(float(parameter) / 100.0)
|
||||||
bot.send_msg(constants.strings('change_ducking_volume', volume=parameter, user=bot.mumble.users[text.actor]['name']), text)
|
bot.send_msg(tr('change_ducking_volume', volume=parameter, user=bot.mumble.users[text.actor]['name']), text)
|
||||||
var.db.set('bot', 'ducking_volume', float(parameter) / 100.0)
|
var.db.set('bot', 'ducking_volume', float(parameter) / 100.0)
|
||||||
log.info(f'cmd: volume on ducking set to {parameter}')
|
log.info(f'cmd: volume on ducking set to {parameter}')
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('current_ducking_volume', volume=int(bot.volume_helper.plain_ducking_volume_set * 100)), text)
|
bot.send_msg(tr('current_ducking_volume', volume=int(bot.volume_helper.plain_ducking_volume_set * 100)), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_current_music(bot, user, text, command, parameter):
|
def cmd_current_music(bot, user, text, command, parameter):
|
||||||
@ -654,7 +654,7 @@ def cmd_current_music(bot, user, text, command, parameter):
|
|||||||
if len(var.playlist) > 0:
|
if len(var.playlist) > 0:
|
||||||
bot.send_msg(var.playlist.current_item().format_current_playing(), text)
|
bot.send_msg(var.playlist.current_item().format_current_playing(), text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('not_playing'), text)
|
bot.send_msg(tr('not_playing'), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_skip(bot, user, text, command, parameter):
|
def cmd_skip(bot, user, text, command, parameter):
|
||||||
@ -667,7 +667,7 @@ def cmd_skip(bot, user, text, command, parameter):
|
|||||||
bot.wait_for_ready = True
|
bot.wait_for_ready = True
|
||||||
|
|
||||||
if len(var.playlist) == 0:
|
if len(var.playlist) == 0:
|
||||||
bot.send_msg(constants.strings('queue_empty'), text)
|
bot.send_msg(tr('queue_empty'), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_last(bot, user, text, command, parameter):
|
def cmd_last(bot, user, text, command, parameter):
|
||||||
@ -677,7 +677,7 @@ def cmd_last(bot, user, text, command, parameter):
|
|||||||
bot.interrupt()
|
bot.interrupt()
|
||||||
var.playlist.point_to(len(var.playlist) - 1 - 1)
|
var.playlist.point_to(len(var.playlist) - 1 - 1)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('queue_empty'), text)
|
bot.send_msg(tr('queue_empty'), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_remove(bot, user, text, command, parameter):
|
def cmd_remove(bot, user, text, command, parameter):
|
||||||
@ -690,8 +690,8 @@ def cmd_remove(bot, user, text, command, parameter):
|
|||||||
|
|
||||||
if index == var.playlist.current_index:
|
if index == var.playlist.current_index:
|
||||||
removed = var.playlist[index]
|
removed = var.playlist[index]
|
||||||
bot.send_msg(constants.strings('removing_item',
|
bot.send_msg(tr('removing_item',
|
||||||
item=removed.format_title()), text)
|
item=removed.format_title()), text)
|
||||||
log.info("cmd: delete from playlist: " + removed.format_debug_string())
|
log.info("cmd: delete from playlist: " + removed.format_debug_string())
|
||||||
|
|
||||||
var.playlist.remove(index)
|
var.playlist.remove(index)
|
||||||
@ -710,7 +710,7 @@ def cmd_remove(bot, user, text, command, parameter):
|
|||||||
var.playlist.remove(index)
|
var.playlist.remove(index)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_list_file(bot, user, text, command, parameter):
|
def cmd_list_file(bot, user, text, command, parameter):
|
||||||
@ -722,7 +722,7 @@ def cmd_list_file(bot, user, text, command, parameter):
|
|||||||
|
|
||||||
song_shortlist = files
|
song_shortlist = files
|
||||||
|
|
||||||
msgs = [constants.strings("multiple_file_found") + "<ul>"]
|
msgs = [tr("multiple_file_found") + "<ul>"]
|
||||||
try:
|
try:
|
||||||
count = 0
|
count = 0
|
||||||
for index, file in enumerate(files):
|
for index, file in enumerate(files):
|
||||||
@ -739,14 +739,14 @@ def cmd_list_file(bot, user, text, command, parameter):
|
|||||||
if count != 0:
|
if count != 0:
|
||||||
msgs.append("</ul>")
|
msgs.append("</ul>")
|
||||||
if count > ITEMS_PER_PAGE:
|
if count > ITEMS_PER_PAGE:
|
||||||
msgs.append(constants.strings("records_omitted"))
|
msgs.append(tr("records_omitted"))
|
||||||
msgs.append(constants.strings("shortlist_instruction"))
|
msgs.append(tr("shortlist_instruction"))
|
||||||
send_multi_lines(bot, msgs, text, "")
|
send_multi_lines(bot, msgs, text, "")
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings("no_file"), text)
|
bot.send_msg(tr("no_file"), text)
|
||||||
|
|
||||||
except re.error as e:
|
except re.error as e:
|
||||||
msg = constants.strings('wrong_pattern', error=str(e))
|
msg = tr('wrong_pattern', error=str(e))
|
||||||
bot.send_msg(msg, text)
|
bot.send_msg(msg, text)
|
||||||
|
|
||||||
|
|
||||||
@ -754,10 +754,10 @@ def cmd_queue(bot, user, text, command, parameter):
|
|||||||
global log
|
global log
|
||||||
|
|
||||||
if len(var.playlist) == 0:
|
if len(var.playlist) == 0:
|
||||||
msg = constants.strings('queue_empty')
|
msg = tr('queue_empty')
|
||||||
bot.send_msg(msg, text)
|
bot.send_msg(msg, text)
|
||||||
else:
|
else:
|
||||||
msgs = [constants.strings('queue_contents')]
|
msgs = [tr('queue_contents')]
|
||||||
for i, music in enumerate(var.playlist):
|
for i, music in enumerate(var.playlist):
|
||||||
tags = ''
|
tags = ''
|
||||||
if len(music.item().tags) > 0:
|
if len(music.item().tags) > 0:
|
||||||
@ -797,25 +797,25 @@ def cmd_repeat(bot, user, text, command, parameter):
|
|||||||
)
|
)
|
||||||
log.info("bot: add to playlist: " + music.format_debug_string())
|
log.info("bot: add to playlist: " + music.format_debug_string())
|
||||||
|
|
||||||
bot.send_channel_msg(constants.strings("repeat", song=music.format_song_string(), n=str(repeat)))
|
bot.send_channel_msg(tr("repeat", song=music.format_song_string(), n=str(repeat)))
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings("queue_empty"), text)
|
bot.send_msg(tr("queue_empty"), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_mode(bot, user, text, command, parameter):
|
def cmd_mode(bot, user, text, command, parameter):
|
||||||
global log
|
global log
|
||||||
|
|
||||||
if not parameter:
|
if not parameter:
|
||||||
bot.send_msg(constants.strings("current_mode", mode=var.playlist.mode), text)
|
bot.send_msg(tr("current_mode", mode=var.playlist.mode), text)
|
||||||
return
|
return
|
||||||
if parameter not in ["one-shot", "repeat", "random", "autoplay"]:
|
if parameter not in ["one-shot", "repeat", "random", "autoplay"]:
|
||||||
bot.send_msg(constants.strings('unknown_mode', mode=parameter), text)
|
bot.send_msg(tr('unknown_mode', mode=parameter), text)
|
||||||
else:
|
else:
|
||||||
var.db.set('playlist', 'playback_mode', parameter)
|
var.db.set('playlist', 'playback_mode', parameter)
|
||||||
var.playlist = media.playlist.get_playlist(parameter, var.playlist)
|
var.playlist = media.playlist.get_playlist(parameter, var.playlist)
|
||||||
log.info(f"command: playback mode changed to {parameter}.")
|
log.info(f"command: playback mode changed to {parameter}.")
|
||||||
bot.send_msg(constants.strings("change_mode", mode=var.playlist.mode,
|
bot.send_msg(tr("change_mode", mode=var.playlist.mode,
|
||||||
user=bot.mumble.users[text.actor]['name']), text)
|
user=bot.mumble.users[text.actor]['name']), text)
|
||||||
if parameter == "random":
|
if parameter == "random":
|
||||||
bot.interrupt()
|
bot.interrupt()
|
||||||
bot.launch_music()
|
bot.launch_music()
|
||||||
@ -823,10 +823,10 @@ def cmd_mode(bot, user, text, command, parameter):
|
|||||||
|
|
||||||
def cmd_play_tags(bot, user, text, command, parameter):
|
def cmd_play_tags(bot, user, text, command, parameter):
|
||||||
if not parameter:
|
if not parameter:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
msgs = [constants.strings('multiple_file_added') + "<ul>"]
|
msgs = [tr('multiple_file_added') + "<ul>"]
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
tags = parameter.split(",")
|
tags = parameter.split(",")
|
||||||
@ -842,7 +842,7 @@ def cmd_play_tags(bot, user, text, command, parameter):
|
|||||||
var.playlist.extend(music_wrappers)
|
var.playlist.extend(music_wrappers)
|
||||||
send_multi_lines_in_channel(bot, msgs, "")
|
send_multi_lines_in_channel(bot, msgs, "")
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings("no_file"), text)
|
bot.send_msg(tr("no_file"), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_add_tag(bot, user, text, command, parameter):
|
def cmd_add_tag(bot, user, text, command, parameter):
|
||||||
@ -866,19 +866,19 @@ def cmd_add_tag(bot, user, text, command, parameter):
|
|||||||
if index.isdigit() and 1 <= int(index) <= len(var.playlist):
|
if index.isdigit() and 1 <= int(index) <= len(var.playlist):
|
||||||
var.playlist[int(index) - 1].add_tags(tags)
|
var.playlist[int(index) - 1].add_tags(tags)
|
||||||
log.info(f"cmd: add tags {', '.join(tags)} to song {var.playlist[int(index) - 1].format_debug_string()}")
|
log.info(f"cmd: add tags {', '.join(tags)} to song {var.playlist[int(index) - 1].format_debug_string()}")
|
||||||
bot.send_msg(constants.strings("added_tags",
|
bot.send_msg(tr("added_tags",
|
||||||
tags=", ".join(tags),
|
tags=", ".join(tags),
|
||||||
song=var.playlist[int(index) - 1].format_title()), text)
|
song=var.playlist[int(index) - 1].format_title()), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
elif index == "*":
|
elif index == "*":
|
||||||
for item in var.playlist:
|
for item in var.playlist:
|
||||||
item.add_tags(tags)
|
item.add_tags(tags)
|
||||||
log.info(f"cmd: add tags {', '.join(tags)} to song {item.format_debug_string()}")
|
log.info(f"cmd: add tags {', '.join(tags)} to song {item.format_debug_string()}")
|
||||||
bot.send_msg(constants.strings("added_tags_to_all", tags=", ".join(tags)), text)
|
bot.send_msg(tr("added_tags_to_all", tags=", ".join(tags)), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_remove_tag(bot, user, text, command, parameter):
|
def cmd_remove_tag(bot, user, text, command, parameter):
|
||||||
@ -903,15 +903,15 @@ def cmd_remove_tag(bot, user, text, command, parameter):
|
|||||||
if tags[0] != "*":
|
if tags[0] != "*":
|
||||||
var.playlist[int(index) - 1].remove_tags(tags)
|
var.playlist[int(index) - 1].remove_tags(tags)
|
||||||
log.info(f"cmd: remove tags {', '.join(tags)} from song {var.playlist[int(index) - 1].format_debug_string()}")
|
log.info(f"cmd: remove tags {', '.join(tags)} from song {var.playlist[int(index) - 1].format_debug_string()}")
|
||||||
bot.send_msg(constants.strings("removed_tags",
|
bot.send_msg(tr("removed_tags",
|
||||||
tags=", ".join(tags),
|
tags=", ".join(tags),
|
||||||
song=var.playlist[int(index) - 1].format_title()), text)
|
song=var.playlist[int(index) - 1].format_title()), text)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
var.playlist[int(index) - 1].clear_tags()
|
var.playlist[int(index) - 1].clear_tags()
|
||||||
log.info(f"cmd: clear tags from song {var.playlist[int(index) - 1].format_debug_string()}")
|
log.info(f"cmd: clear tags from song {var.playlist[int(index) - 1].format_debug_string()}")
|
||||||
bot.send_msg(constants.strings("cleared_tags",
|
bot.send_msg(tr("cleared_tags",
|
||||||
song=var.playlist[int(index) - 1].format_title()), text)
|
song=var.playlist[int(index) - 1].format_title()), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
elif index == "*":
|
elif index == "*":
|
||||||
@ -919,26 +919,26 @@ def cmd_remove_tag(bot, user, text, command, parameter):
|
|||||||
for item in var.playlist:
|
for item in var.playlist:
|
||||||
item.remove_tags(tags)
|
item.remove_tags(tags)
|
||||||
log.info(f"cmd: remove tags {', '.join(tags)} from song {item.format_debug_string()}")
|
log.info(f"cmd: remove tags {', '.join(tags)} from song {item.format_debug_string()}")
|
||||||
bot.send_msg(constants.strings("removed_tags_from_all", tags=", ".join(tags)), text)
|
bot.send_msg(tr("removed_tags_from_all", tags=", ".join(tags)), text)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
for item in var.playlist:
|
for item in var.playlist:
|
||||||
item.clear_tags()
|
item.clear_tags()
|
||||||
log.info(f"cmd: clear tags from song {item.format_debug_string()}")
|
log.info(f"cmd: clear tags from song {item.format_debug_string()}")
|
||||||
bot.send_msg(constants.strings("cleared_tags_from_all"), text)
|
bot.send_msg(tr("cleared_tags_from_all"), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_find_tagged(bot, user, text, command, parameter):
|
def cmd_find_tagged(bot, user, text, command, parameter):
|
||||||
global song_shortlist
|
global song_shortlist
|
||||||
|
|
||||||
if not parameter:
|
if not parameter:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
msgs = [constants.strings('multiple_file_found') + "<ul>"]
|
msgs = [tr('multiple_file_found') + "<ul>"]
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
tags = parameter.split(",")
|
tags = parameter.split(",")
|
||||||
@ -957,20 +957,20 @@ def cmd_find_tagged(bot, user, text, command, parameter):
|
|||||||
if count != 0:
|
if count != 0:
|
||||||
msgs.append("</ul>")
|
msgs.append("</ul>")
|
||||||
if count > ITEMS_PER_PAGE:
|
if count > ITEMS_PER_PAGE:
|
||||||
msgs.append(constants.strings("records_omitted"))
|
msgs.append(tr("records_omitted"))
|
||||||
msgs.append(constants.strings("shortlist_instruction"))
|
msgs.append(tr("shortlist_instruction"))
|
||||||
send_multi_lines(bot, msgs, text, "")
|
send_multi_lines(bot, msgs, text, "")
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings("no_file"), text)
|
bot.send_msg(tr("no_file"), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_search_library(bot, user, text, command, parameter):
|
def cmd_search_library(bot, user, text, command, parameter):
|
||||||
global song_shortlist
|
global song_shortlist
|
||||||
if not parameter:
|
if not parameter:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
msgs = [constants.strings('multiple_file_found') + "<ul>"]
|
msgs = [tr('multiple_file_found') + "<ul>"]
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
_keywords = parameter.split(" ")
|
_keywords = parameter.split(" ")
|
||||||
@ -988,7 +988,7 @@ def cmd_search_library(bot, user, text, command, parameter):
|
|||||||
music_wrapper = get_cached_wrapper(items[0], user)
|
music_wrapper = get_cached_wrapper(items[0], user)
|
||||||
var.playlist.append(music_wrapper)
|
var.playlist.append(music_wrapper)
|
||||||
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
||||||
bot.send_channel_msg(constants.strings('file_added', item=music_wrapper.format_song_string()))
|
bot.send_channel_msg(tr('file_added', item=music_wrapper.format_song_string()))
|
||||||
else:
|
else:
|
||||||
for item in items:
|
for item in items:
|
||||||
count += 1
|
count += 1
|
||||||
@ -1002,19 +1002,19 @@ def cmd_search_library(bot, user, text, command, parameter):
|
|||||||
if count != 0:
|
if count != 0:
|
||||||
msgs.append("</ul>")
|
msgs.append("</ul>")
|
||||||
if count > ITEMS_PER_PAGE:
|
if count > ITEMS_PER_PAGE:
|
||||||
msgs.append(constants.strings("records_omitted"))
|
msgs.append(tr("records_omitted"))
|
||||||
msgs.append(constants.strings("shortlist_instruction"))
|
msgs.append(tr("shortlist_instruction"))
|
||||||
send_multi_lines(bot, msgs, text, "")
|
send_multi_lines(bot, msgs, text, "")
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings("no_file"), text)
|
bot.send_msg(tr("no_file"), text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings("no_file"), text)
|
bot.send_msg(tr("no_file"), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_shortlist(bot, user, text, command, parameter):
|
def cmd_shortlist(bot, user, text, command, parameter):
|
||||||
global song_shortlist, log
|
global song_shortlist, log
|
||||||
if parameter.strip() == "*":
|
if parameter.strip() == "*":
|
||||||
msgs = [constants.strings('multiple_file_added') + "<ul>"]
|
msgs = [tr('multiple_file_added') + "<ul>"]
|
||||||
music_wrappers = []
|
music_wrappers = []
|
||||||
for kwargs in song_shortlist:
|
for kwargs in song_shortlist:
|
||||||
kwargs['user'] = user
|
kwargs['user'] = user
|
||||||
@ -1032,11 +1032,11 @@ def cmd_shortlist(bot, user, text, command, parameter):
|
|||||||
try:
|
try:
|
||||||
indexes = [int(i) for i in parameter.split(" ")]
|
indexes = [int(i) for i in parameter.split(" ")]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(indexes) > 1:
|
if len(indexes) > 1:
|
||||||
msgs = [constants.strings('multiple_file_added') + "<ul>"]
|
msgs = [tr('multiple_file_added') + "<ul>"]
|
||||||
music_wrappers = []
|
music_wrappers = []
|
||||||
for index in indexes:
|
for index in indexes:
|
||||||
if 1 <= index <= len(song_shortlist):
|
if 1 <= index <= len(song_shortlist):
|
||||||
@ -1048,7 +1048,7 @@ def cmd_shortlist(bot, user, text, command, parameter):
|
|||||||
msgs.append("<li>[{}] <b>{}</b></li>".format(music_wrapper.item().type, music_wrapper.item().title))
|
msgs.append("<li>[{}] <b>{}</b></li>".format(music_wrapper.item().type, music_wrapper.item().title))
|
||||||
else:
|
else:
|
||||||
var.playlist.extend(music_wrappers)
|
var.playlist.extend(music_wrappers)
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
var.playlist.extend(music_wrappers)
|
var.playlist.extend(music_wrappers)
|
||||||
@ -1064,10 +1064,10 @@ def cmd_shortlist(bot, user, text, command, parameter):
|
|||||||
music_wrapper = get_cached_wrapper_from_scrap(**kwargs)
|
music_wrapper = get_cached_wrapper_from_scrap(**kwargs)
|
||||||
var.playlist.append(music_wrapper)
|
var.playlist.append(music_wrapper)
|
||||||
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
|
||||||
bot.send_channel_msg(constants.strings('file_added', item=music_wrapper.format_song_string()))
|
bot.send_channel_msg(tr('file_added', item=music_wrapper.format_song_string()))
|
||||||
return
|
return
|
||||||
|
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_delete_from_library(bot, user, text, command, parameter):
|
def cmd_delete_from_library(bot, user, text, command, parameter):
|
||||||
@ -1075,11 +1075,11 @@ def cmd_delete_from_library(bot, user, text, command, parameter):
|
|||||||
try:
|
try:
|
||||||
indexes = [int(i) for i in parameter.split(" ")]
|
indexes = [int(i) for i in parameter.split(" ")]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(indexes) > 1:
|
if len(indexes) > 1:
|
||||||
msgs = [constants.strings('multiple_file_added') + "<ul>"]
|
msgs = [tr('multiple_file_added') + "<ul>"]
|
||||||
count = 0
|
count = 0
|
||||||
for index in indexes:
|
for index in indexes:
|
||||||
if 1 <= index <= len(song_shortlist):
|
if 1 <= index <= len(song_shortlist):
|
||||||
@ -1092,11 +1092,11 @@ def cmd_delete_from_library(bot, user, text, command, parameter):
|
|||||||
var.cache.free_and_delete(music_dict['id'])
|
var.cache.free_and_delete(music_dict['id'])
|
||||||
count += 1
|
count += 1
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
if count == 0:
|
if count == 0:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
msgs.append("</ul>")
|
msgs.append("</ul>")
|
||||||
@ -1108,13 +1108,13 @@ def cmd_delete_from_library(bot, user, text, command, parameter):
|
|||||||
music_dict = song_shortlist[index - 1]
|
music_dict = song_shortlist[index - 1]
|
||||||
if 'id' in music_dict:
|
if 'id' in music_dict:
|
||||||
music_wrapper = get_cached_wrapper_by_id(music_dict['id'], user)
|
music_wrapper = get_cached_wrapper_by_id(music_dict['id'], user)
|
||||||
bot.send_msg(constants.strings('file_deleted', item=music_wrapper.format_song_string()), text)
|
bot.send_msg(tr('file_deleted', item=music_wrapper.format_song_string()), text)
|
||||||
log.info("cmd: remove from library: " + music_wrapper.format_debug_string())
|
log.info("cmd: remove from library: " + music_wrapper.format_debug_string())
|
||||||
var.playlist.remove_by_id(music_dict['id'])
|
var.playlist.remove_by_id(music_dict['id'])
|
||||||
var.cache.free_and_delete(music_dict['id'])
|
var.cache.free_and_delete(music_dict['id'])
|
||||||
return
|
return
|
||||||
|
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_drop_database(bot, user, text, command, parameter):
|
def cmd_drop_database(bot, user, text, command, parameter):
|
||||||
@ -1126,9 +1126,9 @@ def cmd_drop_database(bot, user, text, command, parameter):
|
|||||||
var.music_db.drop_table()
|
var.music_db.drop_table()
|
||||||
var.music_db = MusicDatabase(var.settings_db_path)
|
var.music_db = MusicDatabase(var.settings_db_path)
|
||||||
log.info("command: database dropped.")
|
log.info("command: database dropped.")
|
||||||
bot.send_msg(constants.strings('database_dropped'), text)
|
bot.send_msg(tr('database_dropped'), text)
|
||||||
else:
|
else:
|
||||||
bot.mumble.users[text.actor].send_text_message(constants.strings('not_admin'))
|
bot.mumble.users[text.actor].send_text_message(tr('not_admin'))
|
||||||
|
|
||||||
|
|
||||||
def cmd_refresh_cache(bot, user, text, command, parameter):
|
def cmd_refresh_cache(bot, user, text, command, parameter):
|
||||||
@ -1136,9 +1136,9 @@ def cmd_refresh_cache(bot, user, text, command, parameter):
|
|||||||
if bot.is_admin(user):
|
if bot.is_admin(user):
|
||||||
var.cache.build_dir_cache()
|
var.cache.build_dir_cache()
|
||||||
log.info("command: Local file cache refreshed.")
|
log.info("command: Local file cache refreshed.")
|
||||||
bot.send_msg(constants.strings('cache_refreshed'), text)
|
bot.send_msg(tr('cache_refreshed'), text)
|
||||||
else:
|
else:
|
||||||
bot.mumble.users[text.actor].send_text_message(constants.strings('not_admin'))
|
bot.mumble.users[text.actor].send_text_message(tr('not_admin'))
|
||||||
|
|
||||||
|
|
||||||
def cmd_web_access(bot, user, text, command, parameter):
|
def cmd_web_access(bot, user, text, command, parameter):
|
||||||
@ -1164,12 +1164,12 @@ def cmd_web_access(bot, user, text, command, parameter):
|
|||||||
else:
|
else:
|
||||||
access_address = var.config.get("webinterface", "access_address")
|
access_address = var.config.get("webinterface", "access_address")
|
||||||
|
|
||||||
bot.send_msg(constants.strings('webpage_address', address=access_address), text)
|
bot.send_msg(tr('webpage_address', address=access_address), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_user_password(bot, user, text, command, parameter):
|
def cmd_user_password(bot, user, text, command, parameter):
|
||||||
if not parameter:
|
if not parameter:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
user_info = var.db.get("user", user, fallback='{}')
|
user_info = var.db.get("user", user, fallback='{}')
|
||||||
@ -1178,12 +1178,12 @@ def cmd_user_password(bot, user, text, command, parameter):
|
|||||||
|
|
||||||
var.db.set("user", user, json.dumps(user_dict))
|
var.db.set("user", user, json.dumps(user_dict))
|
||||||
|
|
||||||
bot.send_msg(constants.strings('user_password_set'), text)
|
bot.send_msg(tr('user_password_set'), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_web_user_add(bot, user, text, command, parameter):
|
def cmd_web_user_add(bot, user, text, command, parameter):
|
||||||
if not parameter:
|
if not parameter:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
auth_method = var.config.get("webinterface", "auth_method")
|
auth_method = var.config.get("webinterface", "auth_method")
|
||||||
@ -1193,14 +1193,14 @@ def cmd_web_user_add(bot, user, text, command, parameter):
|
|||||||
if parameter not in web_users:
|
if parameter not in web_users:
|
||||||
web_users.append(parameter)
|
web_users.append(parameter)
|
||||||
var.db.set("privilege", "web_access", json.dumps(web_users))
|
var.db.set("privilege", "web_access", json.dumps(web_users))
|
||||||
bot.send_msg(constants.strings('web_user_list', users=", ".join(web_users)), text)
|
bot.send_msg(tr('web_user_list', users=", ".join(web_users)), text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('command_disabled', command=command), text)
|
bot.send_msg(tr('command_disabled', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_web_user_remove(bot, user, text, command, parameter):
|
def cmd_web_user_remove(bot, user, text, command, parameter):
|
||||||
if not parameter:
|
if not parameter:
|
||||||
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
bot.send_msg(tr('bad_parameter', command=command), text)
|
||||||
return
|
return
|
||||||
|
|
||||||
auth_method = var.config.get("webinterface", "auth_method")
|
auth_method = var.config.get("webinterface", "auth_method")
|
||||||
@ -1210,9 +1210,9 @@ def cmd_web_user_remove(bot, user, text, command, parameter):
|
|||||||
if parameter in web_users:
|
if parameter in web_users:
|
||||||
web_users.remove(parameter)
|
web_users.remove(parameter)
|
||||||
var.db.set("privilege", "web_access", json.dumps(web_users))
|
var.db.set("privilege", "web_access", json.dumps(web_users))
|
||||||
bot.send_msg(constants.strings('web_user_list', users=", ".join(web_users)), text)
|
bot.send_msg(tr('web_user_list', users=", ".join(web_users)), text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('command_disabled', command=command), text)
|
bot.send_msg(tr('command_disabled', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
def cmd_web_user_list(bot, user, text, command, parameter):
|
def cmd_web_user_list(bot, user, text, command, parameter):
|
||||||
@ -1220,9 +1220,9 @@ def cmd_web_user_list(bot, user, text, command, parameter):
|
|||||||
|
|
||||||
if auth_method == 'password':
|
if auth_method == 'password':
|
||||||
web_users = json.loads(var.db.get("privilege", "web_access", fallback='[]'))
|
web_users = json.loads(var.db.get("privilege", "web_access", fallback='[]'))
|
||||||
bot.send_msg(constants.strings('web_user_list', users=", ".join(web_users)), text)
|
bot.send_msg(tr('web_user_list', users=", ".join(web_users)), text)
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('command_disabled', command=command), text)
|
bot.send_msg(tr('command_disabled', command=command), text)
|
||||||
|
|
||||||
|
|
||||||
# Just for debug use
|
# Just for debug use
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import variables as var
|
import variables as var
|
||||||
|
|
||||||
|
|
||||||
def strings(option, *argv, **kwargs):
|
def tr(option, *argv, **kwargs):
|
||||||
try:
|
try:
|
||||||
string = var.config.get("strings", option)
|
string = var.config.get("strings", option)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -75,7 +75,7 @@ class FileItem(BaseItem):
|
|||||||
if not os.path.exists(self.uri()):
|
if not os.path.exists(self.uri()):
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"file: music file missed for %s" % self.format_debug_string())
|
"file: music file missed for %s" % self.format_debug_string())
|
||||||
raise ValidationFailedError(constants.strings('file_missed', file=self.path))
|
raise ValidationFailedError(constants.tr('file_missed', file=self.path))
|
||||||
|
|
||||||
if self.duration == 0:
|
if self.duration == 0:
|
||||||
self.duration = util.get_media_duration(self.uri())
|
self.duration = util.get_media_duration(self.uri())
|
||||||
@ -185,14 +185,14 @@ class FileItem(BaseItem):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def format_song_string(self, user):
|
def format_song_string(self, user):
|
||||||
return constants.strings("file_item",
|
return constants.tr("file_item",
|
||||||
title=self.title,
|
title=self.title,
|
||||||
artist=self.artist if self.artist else '??',
|
artist=self.artist if self.artist else '??',
|
||||||
user=user
|
user=user
|
||||||
)
|
)
|
||||||
|
|
||||||
def format_current_playing(self, user):
|
def format_current_playing(self, user):
|
||||||
display = constants.strings("now_playing", item=self.format_song_string(user))
|
display = constants.tr("now_playing", item=self.format_song_string(user))
|
||||||
if self.thumbnail:
|
if self.thumbnail:
|
||||||
thumbnail_html = '<img width="80" src="data:image/jpge;base64,' + \
|
thumbnail_html = '<img width="80" src="data:image/jpge;base64,' + \
|
||||||
self.thumbnail + '"/>'
|
self.thumbnail + '"/>'
|
||||||
@ -208,4 +208,4 @@ class FileItem(BaseItem):
|
|||||||
return title
|
return title
|
||||||
|
|
||||||
def display_type(self):
|
def display_type(self):
|
||||||
return constants.strings("file")
|
return constants.tr("file")
|
||||||
|
@ -147,18 +147,18 @@ class RadioItem(BaseItem):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def format_song_string(self, user):
|
def format_song_string(self, user):
|
||||||
return constants.strings("radio_item",
|
return constants.tr("radio_item",
|
||||||
url=self.url,
|
url=self.url,
|
||||||
title=get_radio_title(self.url), # the title of current song
|
title=get_radio_title(self.url), # the title of current song
|
||||||
name=self.title, # the title of radio station
|
name=self.title, # the title of radio station
|
||||||
user=user
|
user=user
|
||||||
)
|
)
|
||||||
|
|
||||||
def format_current_playing(self, user):
|
def format_current_playing(self, user):
|
||||||
return constants.strings("now_playing", item=self.format_song_string(user))
|
return constants.tr("now_playing", item=self.format_song_string(user))
|
||||||
|
|
||||||
def format_title(self):
|
def format_title(self):
|
||||||
return self.title if self.title else self.url
|
return self.title if self.title else self.url
|
||||||
|
|
||||||
def display_type(self):
|
def display_type(self):
|
||||||
return constants.strings("radio")
|
return constants.tr("radio")
|
||||||
|
18
media/url.py
18
media/url.py
@ -99,7 +99,7 @@ class URLItem(BaseItem):
|
|||||||
# Check the length, useful in case of playlist, it wasn't checked before)
|
# Check the length, useful in case of playlist, it wasn't checked before)
|
||||||
log.info(
|
log.info(
|
||||||
"url: " + self.url + " has a duration of " + str(self.duration / 60) + " min -- too long")
|
"url: " + self.url + " has a duration of " + str(self.duration / 60) + " min -- too long")
|
||||||
raise ValidationFailedError(constants.strings('too_long', song=self.title))
|
raise ValidationFailedError(constants.tr('too_long', song=self.title))
|
||||||
else:
|
else:
|
||||||
self.ready = "validated"
|
self.ready = "validated"
|
||||||
self.version += 1 # notify wrapper to save me
|
self.version += 1 # notify wrapper to save me
|
||||||
@ -138,7 +138,7 @@ class URLItem(BaseItem):
|
|||||||
if not succeed:
|
if not succeed:
|
||||||
self.ready = 'failed'
|
self.ready = 'failed'
|
||||||
self.log.error("url: error while fetching info from the URL")
|
self.log.error("url: error while fetching info from the URL")
|
||||||
raise ValidationFailedError(constants.strings('unable_download', item=self.format_title()))
|
raise ValidationFailedError(constants.tr('unable_download', item=self.format_title()))
|
||||||
|
|
||||||
def _download(self):
|
def _download(self):
|
||||||
media.system.clear_tmp_folder(var.tmp_folder, var.config.getint('bot', 'tmp_folder_max_size'))
|
media.system.clear_tmp_folder(var.tmp_folder, var.config.getint('bot', 'tmp_folder_max_size'))
|
||||||
@ -193,7 +193,7 @@ class URLItem(BaseItem):
|
|||||||
os.remove(f)
|
os.remove(f)
|
||||||
self.ready = "failed"
|
self.ready = "failed"
|
||||||
self.downloading = False
|
self.downloading = False
|
||||||
raise PreparationFailedError(constants.strings('unable_download', item=self.format_title()))
|
raise PreparationFailedError(constants.tr('unable_download', item=self.format_title()))
|
||||||
|
|
||||||
def _read_thumbnail_from_file(self, path_thumbnail):
|
def _read_thumbnail_from_file(self, path_thumbnail):
|
||||||
if os.path.isfile(path_thumbnail):
|
if os.path.isfile(path_thumbnail):
|
||||||
@ -226,14 +226,14 @@ class URLItem(BaseItem):
|
|||||||
|
|
||||||
def format_song_string(self, user):
|
def format_song_string(self, user):
|
||||||
if self.ready in ['validated', 'yes']:
|
if self.ready in ['validated', 'yes']:
|
||||||
return constants.strings("url_item",
|
return constants.tr("url_item",
|
||||||
title=self.title if self.title else "??",
|
title=self.title if self.title else "??",
|
||||||
url=self.url,
|
url=self.url,
|
||||||
user=user)
|
user=user)
|
||||||
return self.url
|
return self.url
|
||||||
|
|
||||||
def format_current_playing(self, user):
|
def format_current_playing(self, user):
|
||||||
display = constants.strings("now_playing", item=self.format_song_string(user))
|
display = constants.tr("now_playing", item=self.format_song_string(user))
|
||||||
|
|
||||||
if self.thumbnail:
|
if self.thumbnail:
|
||||||
thumbnail_html = '<img width="80" src="data:image/jpge;base64,' + \
|
thumbnail_html = '<img width="80" src="data:image/jpge;base64,' + \
|
||||||
@ -246,4 +246,4 @@ class URLItem(BaseItem):
|
|||||||
return self.title if self.title.strip() else self.url
|
return self.title if self.title.strip() else self.url
|
||||||
|
|
||||||
def display_type(self):
|
def display_type(self):
|
||||||
return constants.strings("url")
|
return constants.tr("url")
|
||||||
|
@ -96,15 +96,15 @@ class PlaylistURLItem(URLItem):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def format_song_string(self, user):
|
def format_song_string(self, user):
|
||||||
return constants.strings("url_from_playlist_item",
|
return constants.tr("url_from_playlist_item",
|
||||||
title=self.title,
|
title=self.title,
|
||||||
url=self.url,
|
url=self.url,
|
||||||
playlist_url=self.playlist_url,
|
playlist_url=self.playlist_url,
|
||||||
playlist=self.playlist_title,
|
playlist=self.playlist_title,
|
||||||
user=user)
|
user=user)
|
||||||
|
|
||||||
def format_current_playing(self, user):
|
def format_current_playing(self, user):
|
||||||
display = constants.strings("now_playing", item=self.format_song_string(user))
|
display = constants.tr("now_playing", item=self.format_song_string(user))
|
||||||
|
|
||||||
if self.thumbnail:
|
if self.thumbnail:
|
||||||
thumbnail_html = '<img width="80" src="data:image/jpge;base64,' + \
|
thumbnail_html = '<img width="80" src="data:image/jpge;base64,' + \
|
||||||
@ -114,4 +114,4 @@ class PlaylistURLItem(URLItem):
|
|||||||
return display
|
return display
|
||||||
|
|
||||||
def display_type(self):
|
def display_type(self):
|
||||||
return constants.strings("url_from_playlist")
|
return constants.tr("url_from_playlist")
|
||||||
|
40
mumbleBot.py
40
mumbleBot.py
@ -23,7 +23,7 @@ from packaging import version
|
|||||||
|
|
||||||
import util
|
import util
|
||||||
import command
|
import command
|
||||||
import constants
|
from constants import tr, commands
|
||||||
from database import SettingsDatabase, MusicDatabase, DatabaseMigration
|
from database import SettingsDatabase, MusicDatabase, DatabaseMigration
|
||||||
import media.system
|
import media.system
|
||||||
from media.item import ValidationFailedError, PreparationFailedError
|
from media.item import ValidationFailedError, PreparationFailedError
|
||||||
@ -118,7 +118,7 @@ class MumbleBot:
|
|||||||
self.mumble.start() # start the mumble thread
|
self.mumble.start() # start the mumble thread
|
||||||
self.mumble.is_ready() # wait for the connection
|
self.mumble.is_ready() # wait for the connection
|
||||||
|
|
||||||
if self.mumble.connected >= pymumble_py3.constants.PYMUMBLE_CONN_STATE_FAILED:
|
if self.mumble.connected >= pymumble.constants.PYMUMBLE_CONN_STATE_FAILED:
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
self.set_comment()
|
self.set_comment()
|
||||||
@ -179,7 +179,7 @@ class MumbleBot:
|
|||||||
if not last_startup_version or version.parse(last_startup_version) < version.parse(self.version):
|
if not last_startup_version or version.parse(last_startup_version) < version.parse(self.version):
|
||||||
var.db.set("bot", "version", self.version)
|
var.db.set("bot", "version", self.version)
|
||||||
changelog = util.fetch_changelog()
|
changelog = util.fetch_changelog()
|
||||||
self.send_channel_msg(constants.strings("update_successful", version=self.version, changelog=changelog))
|
self.send_channel_msg(tr("update_successful", version=self.version, changelog=changelog))
|
||||||
|
|
||||||
# Set the CTRL+C shortcut
|
# Set the CTRL+C shortcut
|
||||||
def ctrl_caught(self, signal, frame):
|
def ctrl_caught(self, signal, frame):
|
||||||
@ -206,7 +206,7 @@ class MumbleBot:
|
|||||||
self.log.info(f"update: new version {new_version} found, current installed version {self.version}.")
|
self.log.info(f"update: new version {new_version} found, current installed version {self.version}.")
|
||||||
self.log.info(f"update: changelog: {changelog}")
|
self.log.info(f"update: changelog: {changelog}")
|
||||||
changelog = changelog.replace("\n", "<br>")
|
changelog = changelog.replace("\n", "<br>")
|
||||||
self.send_channel_msg(constants.strings('new_version_found', new_version=new_version, changelog=changelog))
|
self.send_channel_msg(tr('new_version_found', new_version=new_version, changelog=changelog))
|
||||||
else:
|
else:
|
||||||
self.log.debug("update: no new version found.")
|
self.log.debug("update: no new version found.")
|
||||||
|
|
||||||
@ -263,13 +263,13 @@ class MumbleBot:
|
|||||||
# Anti stupid guy function
|
# Anti stupid guy function
|
||||||
if not self.is_admin(user) and not var.config.getboolean('bot', 'allow_private_message') and text.session:
|
if not self.is_admin(user) and not var.config.getboolean('bot', 'allow_private_message') and text.session:
|
||||||
self.mumble.users[text.actor].send_text_message(
|
self.mumble.users[text.actor].send_text_message(
|
||||||
constants.strings('pm_not_allowed'))
|
tr('pm_not_allowed'))
|
||||||
return
|
return
|
||||||
|
|
||||||
for i in var.db.items("user_ban"):
|
for i in var.db.items("user_ban"):
|
||||||
if user.lower() == i[0]:
|
if user.lower() == i[0]:
|
||||||
self.mumble.users[text.actor].send_text_message(
|
self.mumble.users[text.actor].send_text_message(
|
||||||
constants.strings('user_ban'))
|
tr('user_ban'))
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.is_admin(user) and parameter:
|
if not self.is_admin(user) and parameter:
|
||||||
@ -278,7 +278,7 @@ class MumbleBot:
|
|||||||
for i in var.db.items("url_ban"):
|
for i in var.db.items("url_ban"):
|
||||||
if input_url == i[0]:
|
if input_url == i[0]:
|
||||||
self.mumble.users[text.actor].send_text_message(
|
self.mumble.users[text.actor].send_text_message(
|
||||||
constants.strings('url_ban'))
|
tr('url_ban'))
|
||||||
return
|
return
|
||||||
|
|
||||||
command_exc = ""
|
command_exc = ""
|
||||||
@ -299,15 +299,15 @@ class MumbleBot:
|
|||||||
|
|
||||||
elif len(matches) > 1:
|
elif len(matches) > 1:
|
||||||
self.mumble.users[text.actor].send_text_message(
|
self.mumble.users[text.actor].send_text_message(
|
||||||
constants.strings('which_command', commands="<br>".join(matches)))
|
tr('which_command', commands="<br>".join(matches)))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.mumble.users[text.actor].send_text_message(
|
self.mumble.users[text.actor].send_text_message(
|
||||||
constants.strings('bad_command', command=command))
|
tr('bad_command', command=command))
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.cmd_handle[command_exc]['admin'] and not self.is_admin(user):
|
if self.cmd_handle[command_exc]['admin'] and not self.is_admin(user):
|
||||||
self.mumble.users[text.actor].send_text_message(constants.strings('not_admin'))
|
self.mumble.users[text.actor].send_text_message(tr('not_admin'))
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.cmd_handle[command_exc]['access_outside_channel'] \
|
if not self.cmd_handle[command_exc]['access_outside_channel'] \
|
||||||
@ -315,7 +315,7 @@ class MumbleBot:
|
|||||||
and not var.config.getboolean('bot', 'allow_other_channel_message') \
|
and not var.config.getboolean('bot', 'allow_other_channel_message') \
|
||||||
and self.mumble.users[text.actor]['channel_id'] != self.mumble.users.myself['channel_id']:
|
and self.mumble.users[text.actor]['channel_id'] != self.mumble.users.myself['channel_id']:
|
||||||
self.mumble.users[text.actor].send_text_message(
|
self.mumble.users[text.actor].send_text_message(
|
||||||
constants.strings('not_in_my_channel'))
|
tr('not_in_my_channel'))
|
||||||
return
|
return
|
||||||
|
|
||||||
self.cmd_handle[command_exc]['handle'](self, user, text, command_exc, parameter)
|
self.cmd_handle[command_exc]['handle'](self, user, text, command_exc, parameter)
|
||||||
@ -323,7 +323,7 @@ class MumbleBot:
|
|||||||
error_traceback = traceback.format_exc()
|
error_traceback = traceback.format_exc()
|
||||||
error = error_traceback.rstrip().split("\n")[-1]
|
error = error_traceback.rstrip().split("\n")[-1]
|
||||||
self.log.error(f"bot: command {command_exc} failed with error: {error_traceback}\n")
|
self.log.error(f"bot: command {command_exc} failed with error: {error_traceback}\n")
|
||||||
self.send_msg(constants.strings('error_executing_command', command=command_exc, error=error), text)
|
self.send_msg(tr('error_executing_command', command=command_exc, error=error), text)
|
||||||
|
|
||||||
def send_msg(self, msg, text):
|
def send_msg(self, msg, text):
|
||||||
msg = msg.encode('utf-8', 'ignore').decode('utf-8')
|
msg = msg.encode('utf-8', 'ignore').decode('utf-8')
|
||||||
@ -355,7 +355,7 @@ class MumbleBot:
|
|||||||
if var.config.get("bot", "when_nobody_in_channel") == "pause_resume":
|
if var.config.get("bot", "when_nobody_in_channel") == "pause_resume":
|
||||||
self.resume()
|
self.resume()
|
||||||
elif var.config.get("bot", "when_nobody_in_channel") == "pause":
|
elif var.config.get("bot", "when_nobody_in_channel") == "pause":
|
||||||
self.send_channel_msg(constants.strings("auto_paused"))
|
self.send_channel_msg(tr("auto_paused"))
|
||||||
|
|
||||||
elif len(own_channel.get_users()) == 1:
|
elif len(own_channel.get_users()) == 1:
|
||||||
# if the bot is the only user left in the channel
|
# if the bot is the only user left in the channel
|
||||||
@ -436,7 +436,7 @@ class MumbleBot:
|
|||||||
self.log.info("bot: current music isn't ready, start downloading.")
|
self.log.info("bot: current music isn't ready, start downloading.")
|
||||||
self.async_download(item)
|
self.async_download(item)
|
||||||
self.send_channel_msg(
|
self.send_channel_msg(
|
||||||
constants.strings('download_in_progress', item=item.format_title()))
|
tr('download_in_progress', item=item.format_title()))
|
||||||
|
|
||||||
def _download(self, item):
|
def _download(self, item):
|
||||||
ver = item.version
|
ver = item.version
|
||||||
@ -514,7 +514,7 @@ class MumbleBot:
|
|||||||
self.log.error("bot: with ffmpeg error: %s", self.last_ffmpeg_err)
|
self.log.error("bot: with ffmpeg error: %s", self.last_ffmpeg_err)
|
||||||
self.last_ffmpeg_err = ""
|
self.last_ffmpeg_err = ""
|
||||||
|
|
||||||
self.send_channel_msg(constants.strings('unable_play', item=current.format_title()))
|
self.send_channel_msg(tr('unable_play', item=current.format_title()))
|
||||||
var.playlist.remove_by_id(current.id)
|
var.playlist.remove_by_id(current.id)
|
||||||
var.cache.free_and_delete(current.id)
|
var.cache.free_and_delete(current.id)
|
||||||
|
|
||||||
@ -720,9 +720,11 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument("--config", dest='config', type=str, default='configuration.ini',
|
parser.add_argument("--config", dest='config', type=str, default='configuration.ini',
|
||||||
help='Load configuration from this file. Default: configuration.ini')
|
help='Load configuration from this file. Default: configuration.ini')
|
||||||
parser.add_argument("--db", dest='db', type=str,
|
parser.add_argument("--db", dest='db', type=str,
|
||||||
default=None, help='settings database file. Default: settings-{username_of_the_bot}.db')
|
default=None, help='Settings database file. Default: settings-{username_of_the_bot}.db')
|
||||||
parser.add_argument("--music-db", dest='music_db', type=str,
|
parser.add_argument("--music-db", dest='music_db', type=str,
|
||||||
default=None, help='music library database file. Default: music.db')
|
default=None, help='Music library database file. Default: music.db')
|
||||||
|
parser.add_argument("--lang", dest='lang', type=str, default='en_US',
|
||||||
|
help='Preferred language.')
|
||||||
|
|
||||||
parser.add_argument("-q", "--quiet", dest="quiet",
|
parser.add_argument("-q", "--quiet", dest="quiet",
|
||||||
action="store_true", help="Only Error logs")
|
action="store_true", help="Only Error logs")
|
||||||
@ -814,6 +816,10 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
var.music_folder = util.solve_filepath(var.config.get('bot', 'music_folder'))
|
var.music_folder = util.solve_filepath(var.config.get('bot', 'music_folder'))
|
||||||
var.tmp_folder = util.solve_filepath(var.config.get('bot', 'tmp_folder'))
|
var.tmp_folder = util.solve_filepath(var.config.get('bot', 'tmp_folder'))
|
||||||
|
|
||||||
|
# ======================
|
||||||
|
# Prepare Cache
|
||||||
|
# ======================
|
||||||
var.cache = MusicCache(var.music_db)
|
var.cache = MusicCache(var.music_db)
|
||||||
|
|
||||||
if var.config.getboolean("bot", "refresh_cache_on_startup", fallback=True):
|
if var.config.getboolean("bot", "refresh_cache_on_startup", fallback=True):
|
||||||
|
Reference in New Issue
Block a user