diff --git a/.drone.yml b/.drone.yml
index da54c2b..4bf22b1 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -3,18 +3,22 @@ type: docker
name: default
steps:
- - name: build
+ - name: build-web
image: node
commands:
- - cd web
- - npm install
- - npm run build
- - cd ..
+ - (cd web && npm install && npm run build)
+
+ - name: translate-web
+ image: python:3
+ commands:
+ - pip3 install jinja2
+ - (cd templates/ && ./translate.py)
- name: deploy-testing
image: debian
commands:
- - apt-get -qq update && apt-get -qq install git > /dev/null
+ - apt-get -qq update && apt-get -qq install git python3-requests > /dev/null
+ - (cd lang && ./sync_translation.py --client $TRADUORA_W_CLIENT --secret $TRADUORA_W_SECRET --push)
- sed -i 's/target_version = git/target_version = testing/' configuration.default.ini
- version=$(git rev-parse HEAD)
- echo "current git commit is $version"
@@ -53,7 +57,8 @@ steps:
- name: deploy-stable
image: debian
commands:
- - apt-get -qq update && apt-get -qq install jq curl git pandoc > /dev/null
+ - apt-get -qq update && apt-get -qq install jq curl git pandoc python3-requests > /dev/null
+ - (cd lang && ./sync_translation.py --client $TRADUORA_W_CLIENT --secret $TRADUORA_W_SECRET --push)
- sed -i 's/target_version = git/target_version = stable/' configuration.default.ini
- git fetch --tags
- version=$(git describe --abbrev=0 --tags)
@@ -85,6 +90,25 @@ steps:
when:
event:
- tag
+
+ - name: fetch-translate
+ image: debian
+ commands:
+ - apt update && apt install -y git python3-requests hub
+ - git branch bot-traduora && git checkout bot-traduora
+ - (cd lang/ && ./sync_translation.py --client $TRADUORA_R_CLIENT --secret $TRADUORA_R_SECRET --fetch)
+ - git add lang/* && git status
+ - git config --global user.email "github@azlux.fr" && git config --global user.name "azlux"
+ - "git commit -a -m 'Bot: update strings'"
+ - git remote set-url origin https://azlux:$GITHUB_API@github.com/azlux/botamusique/
+ - git push --set-upstream origin new-translations && git push
+ - "GITHUB_USER=\"azlux\" GITHUB_TOKEN=\"$GITHUB_API\" hub pull-request -m \"Bot: TRADUORA Update\""
+ when:
+ event:
+ - cron
+ cron:
+ - auto-fetch-lang
+
volumes:
- name: repo
diff --git a/.gitignore b/.gitignore
index e649d17..54ac0c2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -116,7 +116,7 @@ tmp/
*.db
-templates/*
+templates/*.html
# Pycharm
.idea/
diff --git a/README.md b/README.md
index dfed6a5..a26fd8e 100644
--- a/README.md
+++ b/README.md
@@ -91,9 +91,8 @@ cd botamusique
python3 -m venv venv
venv/bin/pip install wheel
venv/bin/pip install -r requirements.txt
-cd web
-npm install
-npm run build
+(cd web && npm install && npm run build)
+(cd templates/ && ./translate.py)
```
diff --git a/command.py b/command.py
index e86866a..29d4f48 100644
--- a/command.py
+++ b/command.py
@@ -6,7 +6,8 @@ import json
import re
import pymumble_py3 as pymumble
-import constants
+from constants import tr_cli as tr
+from constants import commands
import interface
import media.system
import util
@@ -22,56 +23,56 @@ log = logging.getLogger("bot")
def register_all_commands(bot):
- bot.register_command(constants.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(constants.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(constants.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(constants.commands('play'), cmd_play)
- bot.register_command(constants.commands('pause'), cmd_pause)
- bot.register_command(constants.commands('play_file'), cmd_play_file)
- bot.register_command(constants.commands('play_file_match'), cmd_play_file_match)
- bot.register_command(constants.commands('play_url'), cmd_play_url)
- bot.register_command(constants.commands('play_playlist'), cmd_play_playlist)
- bot.register_command(constants.commands('play_radio'), cmd_play_radio)
- bot.register_command(constants.commands('play_tag'), cmd_play_tags)
- bot.register_command(constants.commands('rb_query'), cmd_rb_query)
- bot.register_command(constants.commands('rb_play'), cmd_rb_play)
- bot.register_command(constants.commands('yt_search'), cmd_yt_search)
- bot.register_command(constants.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(constants.commands('stop'), cmd_stop)
- bot.register_command(constants.commands('clear'), cmd_clear)
- bot.register_command(constants.commands('kill'), cmd_kill, admin=True)
- bot.register_command(constants.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(constants.commands('volume'), cmd_volume)
- bot.register_command(constants.commands('ducking'), cmd_ducking)
- bot.register_command(constants.commands('ducking_threshold'), cmd_ducking_threshold)
- bot.register_command(constants.commands('ducking_volume'), cmd_ducking_volume)
- bot.register_command(constants.commands('current_music'), cmd_current_music)
- bot.register_command(constants.commands('skip'), cmd_skip)
- bot.register_command(constants.commands('last'), cmd_last)
- bot.register_command(constants.commands('remove'), cmd_remove)
- bot.register_command(constants.commands('list_file'), cmd_list_file)
- bot.register_command(constants.commands('queue'), cmd_queue)
- bot.register_command(constants.commands('random'), cmd_random)
- bot.register_command(constants.commands('repeat'), cmd_repeat)
- bot.register_command(constants.commands('mode'), cmd_mode)
- bot.register_command(constants.commands('add_tag'), cmd_add_tag)
- bot.register_command(constants.commands('remove_tag'), cmd_remove_tag)
- bot.register_command(constants.commands('find_tagged'), cmd_find_tagged)
- bot.register_command(constants.commands('search'), cmd_search_library)
- bot.register_command(constants.commands('add_from_shortlist'), cmd_shortlist)
- bot.register_command(constants.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(constants.commands('rescan'), cmd_refresh_cache, no_partial_match=True)
- bot.register_command(constants.commands('requests_webinterface_access'), cmd_web_access)
- bot.register_command(constants.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(constants.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('joinme'), cmd_joinme, access_outside_channel=True)
+ bot.register_command(commands('user_ban'), cmd_user_ban, no_partial_match=True, admin=True)
+ bot.register_command(commands('user_unban'), cmd_user_unban, 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(commands('url_ban'), cmd_url_ban, no_partial_match=True, admin=True)
+ bot.register_command(commands('url_unban'), cmd_url_unban, no_partial_match=True, admin=True)
+ bot.register_command(commands('play'), cmd_play)
+ bot.register_command(commands('pause'), cmd_pause)
+ bot.register_command(commands('play_file'), cmd_play_file)
+ bot.register_command(commands('play_file_match'), cmd_play_file_match)
+ bot.register_command(commands('play_url'), cmd_play_url)
+ bot.register_command(commands('play_playlist'), cmd_play_playlist)
+ bot.register_command(commands('play_radio'), cmd_play_radio)
+ bot.register_command(commands('play_tag'), cmd_play_tags)
+ bot.register_command(commands('rb_query'), cmd_rb_query)
+ bot.register_command(commands('rb_play'), cmd_rb_play)
+ bot.register_command(commands('yt_search'), cmd_yt_search)
+ bot.register_command(commands('yt_play'), cmd_yt_play)
+ bot.register_command(commands('help'), cmd_help, no_partial_match=False, access_outside_channel=True)
+ bot.register_command(commands('stop'), cmd_stop)
+ bot.register_command(commands('clear'), cmd_clear)
+ bot.register_command(commands('kill'), cmd_kill, admin=True)
+ bot.register_command(commands('update'), cmd_update, no_partial_match=True, admin=True)
+ bot.register_command(commands('stop_and_getout'), cmd_stop_and_getout)
+ bot.register_command(commands('volume'), cmd_volume)
+ bot.register_command(commands('ducking'), cmd_ducking)
+ bot.register_command(commands('ducking_threshold'), cmd_ducking_threshold)
+ bot.register_command(commands('ducking_volume'), cmd_ducking_volume)
+ bot.register_command(commands('current_music'), cmd_current_music)
+ bot.register_command(commands('skip'), cmd_skip)
+ bot.register_command(commands('last'), cmd_last)
+ bot.register_command(commands('remove'), cmd_remove)
+ bot.register_command(commands('list_file'), cmd_list_file)
+ bot.register_command(commands('queue'), cmd_queue)
+ bot.register_command(commands('random'), cmd_random)
+ bot.register_command(commands('repeat'), cmd_repeat)
+ bot.register_command(commands('mode'), cmd_mode)
+ bot.register_command(commands('add_tag'), cmd_add_tag)
+ bot.register_command(commands('remove_tag'), cmd_remove_tag)
+ bot.register_command(commands('find_tagged'), cmd_find_tagged)
+ bot.register_command(commands('search'), cmd_search_library)
+ bot.register_command(commands('add_from_shortlist'), cmd_shortlist)
+ bot.register_command(commands('delete_from_library'), cmd_delete_from_library)
+ bot.register_command(commands('drop_database'), cmd_drop_database, no_partial_match=True, admin=True)
+ bot.register_command(commands('rescan'), cmd_refresh_cache, no_partial_match=True)
+ bot.register_command(commands('requests_webinterface_access'), cmd_web_access)
+ bot.register_command(commands('add_webinterface_user'), cmd_web_user_add, admin=True)
+ bot.register_command(commands('remove_webinterface_user'), cmd_web_user_remove, admin=True)
+ bot.register_command(commands('list_webinterface_user'), cmd_web_user_list, admin=True)
+ bot.register_command(commands('change_user_password'), cmd_user_password, no_partial_match=True)
# Just for debug use
bot.register_command('rtrms', cmd_real_time_rms, True)
# bot.register_command('loop', cmd_loop_state, True)
@@ -160,7 +161,7 @@ def cmd_url_ban(bot, user, text, command, parameter):
var.cache.free_and_delete(item.id)
var.playlist.remove_by_id(item.id)
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):
@@ -184,14 +185,14 @@ def cmd_play(bot, user, text, command, parameter):
if params[0].isdigit() and 1 <= int(params[0]) <= len(var.playlist):
index = int(params[0])
else:
- bot.send_msg(constants.strings('invalid_index', index=parameter), text)
+ bot.send_msg(tr('invalid_index', index=parameter), text)
return
if len(params) > 1:
try:
start_at = util.parse_time(params[1])
except ValueError:
- bot.send_msg(constants.strings('bad_parameter', command=command), text)
+ bot.send_msg(tr('bad_parameter', command=command), text)
return
if len(var.playlist) > 0:
@@ -204,14 +205,14 @@ def cmd_play(bot, user, text, command, parameter):
bot.send_msg(var.playlist.current_item().format_current_playing(), text)
else:
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):
global log
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):
@@ -222,7 +223,7 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals
if music_wrappers:
var.playlist.append(music_wrappers[0])
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
# assume parameter is a folder
@@ -230,7 +231,7 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals
.and_equal('type', 'file')
.and_like('path', parameter + '%')), user)
if music_wrappers:
- msgs = [constants.strings('multiple_file_added')]
+ msgs = [tr('multiple_file_added')]
for music_wrapper in music_wrappers:
log.info("cmd: add to playlist: " + music_wrapper.format_debug_string())
@@ -249,20 +250,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)
var.playlist.append(music_wrapper)
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
elif len(matches) > 1:
song_shortlist = matches
- msgs = [constants.strings('multiple_matches')]
+ msgs = [tr('multiple_matches')]
for index, match in enumerate(matches):
msgs.append("{:d} - {:s} ({:s})".format(
index + 1, match['title'], match['path']))
- msgs.append(constants.strings("shortlist_instruction"))
+ msgs.append(tr("shortlist_instruction"))
send_multi_lines(bot, msgs, text)
return
if do_not_refresh_cache:
- bot.send_msg(constants.strings("no_file"), text)
+ bot.send_msg(tr("no_file"), text)
else:
var.cache.build_dir_cache()
cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=True)
@@ -273,7 +274,7 @@ def cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cach
if parameter:
file_dicts = var.music_db.query_music(Condition().and_equal('type', 'file'))
- msgs = [constants.strings('multiple_file_added') + "
"]
+ msgs = [tr('multiple_file_added') + ""]
try:
count = 0
music_wrappers = []
@@ -299,16 +300,16 @@ def cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cach
send_multi_lines_in_channel(bot, msgs, "")
else:
if do_not_refresh_cache:
- bot.send_msg(constants.strings("no_file"), text)
+ bot.send_msg(tr("no_file"), text)
else:
var.cache.build_dir_cache()
cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cache=True)
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)
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):
@@ -320,12 +321,12 @@ def cmd_play_url(bot, user, text, command, parameter):
var.playlist.append(music_wrapper)
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 I am the second item on the playlist. (I am the next one!)
bot.async_download_next()
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):
@@ -345,7 +346,7 @@ def cmd_play_playlist(bot, user, text, command, parameter):
for music in items:
log.info("cmd: add to playlist: " + music.format_debug_string())
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):
@@ -353,7 +354,7 @@ def cmd_play_radio(bot, user, text, command, parameter):
if not parameter:
all_radio = var.config.items('radio')
- msg = constants.strings('preconfigurated_radio')
+ msg = tr('preconfigurated_radio')
for i in all_radio:
comment = ""
if len(i[1].split(maxsplit=1)) == 2:
@@ -370,9 +371,9 @@ def cmd_play_radio(bot, user, text, command, parameter):
var.playlist.append(music_wrapper)
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:
- bot.send_msg(constants.strings('bad_url'), text)
+ bot.send_msg(tr('bad_url'), text)
def cmd_rb_query(bot, user, text, command, parameter):
@@ -381,13 +382,13 @@ def cmd_rb_query(bot, user, text, command, parameter):
log.info('cmd: Querying radio stations')
if not parameter:
log.debug('rbquery without parameter')
- msg = constants.strings('rb_query_empty')
+ msg = tr('rb_query_empty')
bot.send_msg(msg, text)
else:
log.debug('cmd: Found query parameter: ' + parameter)
rb = RadioBrowser()
rb_stations = rb.search(name=parameter, name_exact=False)
- msg = constants.strings('rb_query_result')
+ msg = tr('rb_query_result')
msg += '\n!rbplay ID | Station Name | Genre | Codec/Bitrate | Country |
'
if not rb_stations:
log.debug(f"cmd: No matches found for rbquery {parameter}")
@@ -408,7 +409,7 @@ def cmd_rb_query(bot, user, text, command, parameter):
# Shorten message if message too long (stage I)
else:
log.debug('Result too long stage I')
- msg = constants.strings('rb_query_result') + ' (shortened L1)'
+ msg = tr('rb_query_result') + ' (shortened L1)'
msg += '\n!rbplay ID | Station Name |
'
for s in rb_stations:
station_id = s['stationuuid']
@@ -420,7 +421,7 @@ def cmd_rb_query(bot, user, text, command, parameter):
# Shorten message if message too long (stage II)
else:
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'
for s in rb_stations:
station_id = s['stationuuid']
@@ -439,7 +440,7 @@ def cmd_rb_play(bot, user, text, command, parameter):
log.debug('cmd: Play a station by ID')
if not parameter:
log.debug('rbplay without parameter')
- msg = constants.strings('rb_play_empty')
+ msg = tr('rb_play_empty')
bot.send_msg(msg, text)
else:
log.debug('cmd: Retreiving url for station ID ' + parameter)
@@ -488,9 +489,9 @@ def cmd_yt_search(bot, user, text, command, parameter):
'title': result[1]
} 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)
- bot.send_msg(constants.strings('yt_result', result_table=msg), text)
+ bot.send_msg(tr('yt_result', result_table=msg), text)
else:
- bot.send_msg(constants.strings('yt_no_more'), text)
+ bot.send_msg(tr('yt_no_more'), text)
# if query
else:
@@ -501,11 +502,11 @@ def cmd_yt_search(bot, user, text, command, parameter):
song_shortlist = [{'type': 'url', 'url': "https://www.youtube.com/watch?v=" + result[0]}
for result in 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:
- bot.send_msg(constants.strings('yt_query_error'), text)
+ bot.send_msg(tr('yt_query_error'), text)
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):
@@ -529,16 +530,16 @@ def cmd_yt_play(bot, user, text, command, parameter):
url = "https://www.youtube.com/watch?v=" + yt_last_result[0][0]
cmd_play_url(bot, user, text, command, url)
else:
- bot.send_msg(constants.strings('yt_query_error'), text)
+ bot.send_msg(tr('yt_query_error'), text)
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):
global log
- bot.send_msg(constants.strings('help'), text)
+ bot.send_msg(tr('help'), text)
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):
@@ -549,14 +550,14 @@ def cmd_stop(bot, user, text, command, parameter):
cmd_clear(bot, user, text, command, parameter)
else:
bot.stop()
- bot.send_msg(constants.strings('stopped'), text)
+ bot.send_msg(tr('stopped'), text)
def cmd_clear(bot, user, text, command, parameter):
global log
bot.clear()
- bot.send_msg(constants.strings('cleared'), text)
+ bot.send_msg(tr('cleared'), text)
def cmd_kill(bot, user, text, command, parameter):
@@ -571,12 +572,12 @@ def cmd_update(bot, user, text, command, parameter):
if bot.is_admin(user):
bot.mumble.users[text.actor].send_text_message(
- constants.strings('start_updating'))
+ tr('start_updating'))
msg = util.update(bot.version)
bot.mumble.users[text.actor].send_text_message(msg)
else:
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):
@@ -595,11 +596,11 @@ def cmd_volume(bot, user, text, command, parameter):
# The volume is a percentage
if parameter and parameter.isdigit() and 0 <= int(parameter) <= 100:
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))
log.info(f'cmd: volume set to {float(parameter) / 100.0}')
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):
@@ -608,7 +609,7 @@ def cmd_ducking(bot, user, text, command, parameter):
if parameter == "" or parameter == "on":
bot.is_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)
log.info('cmd: ducking is on')
msg = "Ducking on."
@@ -641,11 +642,11 @@ def cmd_ducking_volume(bot, user, text, command, parameter):
# The volume is a percentage
if parameter and parameter.isdigit() and 0 <= int(parameter) <= 100:
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)
log.info(f'cmd: volume on ducking set to {parameter}')
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):
@@ -654,7 +655,7 @@ def cmd_current_music(bot, user, text, command, parameter):
if len(var.playlist) > 0:
bot.send_msg(var.playlist.current_item().format_current_playing(), text)
else:
- bot.send_msg(constants.strings('not_playing'), text)
+ bot.send_msg(tr('not_playing'), text)
def cmd_skip(bot, user, text, command, parameter):
@@ -667,7 +668,7 @@ def cmd_skip(bot, user, text, command, parameter):
bot.wait_for_ready = True
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):
@@ -677,7 +678,7 @@ def cmd_last(bot, user, text, command, parameter):
bot.interrupt()
var.playlist.point_to(len(var.playlist) - 1 - 1)
else:
- bot.send_msg(constants.strings('queue_empty'), text)
+ bot.send_msg(tr('queue_empty'), text)
def cmd_remove(bot, user, text, command, parameter):
@@ -690,8 +691,8 @@ def cmd_remove(bot, user, text, command, parameter):
if index == var.playlist.current_index:
removed = var.playlist[index]
- bot.send_msg(constants.strings('removing_item',
- item=removed.format_title()), text)
+ bot.send_msg(tr('removing_item',
+ item=removed.format_title()), text)
log.info("cmd: delete from playlist: " + removed.format_debug_string())
var.playlist.remove(index)
@@ -710,7 +711,7 @@ def cmd_remove(bot, user, text, command, parameter):
var.playlist.remove(index)
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):
@@ -722,7 +723,7 @@ def cmd_list_file(bot, user, text, command, parameter):
song_shortlist = files
- msgs = [constants.strings("multiple_file_found") + ""]
+ msgs = [tr("multiple_file_found") + ""]
try:
count = 0
for index, file in enumerate(files):
@@ -739,14 +740,14 @@ def cmd_list_file(bot, user, text, command, parameter):
if count != 0:
msgs.append("
")
if count > ITEMS_PER_PAGE:
- msgs.append(constants.strings("records_omitted"))
- msgs.append(constants.strings("shortlist_instruction"))
+ msgs.append(tr("records_omitted"))
+ msgs.append(tr("shortlist_instruction"))
send_multi_lines(bot, msgs, text, "")
else:
- bot.send_msg(constants.strings("no_file"), text)
+ bot.send_msg(tr("no_file"), text)
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)
@@ -754,10 +755,10 @@ def cmd_queue(bot, user, text, command, parameter):
global log
if len(var.playlist) == 0:
- msg = constants.strings('queue_empty')
+ msg = tr('queue_empty')
bot.send_msg(msg, text)
else:
- msgs = [constants.strings('queue_contents')]
+ msgs = [tr('queue_contents')]
for i, music in enumerate(var.playlist):
tags = ''
if len(music.item().tags) > 0:
@@ -797,25 +798,25 @@ def cmd_repeat(bot, user, text, command, parameter):
)
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:
- bot.send_msg(constants.strings("queue_empty"), text)
+ bot.send_msg(tr("queue_empty"), text)
def cmd_mode(bot, user, text, command, parameter):
global log
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
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:
var.db.set('playlist', 'playback_mode', parameter)
var.playlist = media.playlist.get_playlist(parameter, var.playlist)
log.info(f"command: playback mode changed to {parameter}.")
- bot.send_msg(constants.strings("change_mode", mode=var.playlist.mode,
- user=bot.mumble.users[text.actor]['name']), text)
+ bot.send_msg(tr("change_mode", mode=var.playlist.mode,
+ user=bot.mumble.users[text.actor]['name']), text)
if parameter == "random":
bot.interrupt()
bot.launch_music()
@@ -823,10 +824,10 @@ def cmd_mode(bot, user, text, command, parameter):
def cmd_play_tags(bot, user, text, command, parameter):
if not parameter:
- bot.send_msg(constants.strings('bad_parameter', command=command), text)
+ bot.send_msg(tr('bad_parameter', command=command), text)
return
- msgs = [constants.strings('multiple_file_added') + ""]
+ msgs = [tr('multiple_file_added') + ""]
count = 0
tags = parameter.split(",")
@@ -842,7 +843,7 @@ def cmd_play_tags(bot, user, text, command, parameter):
var.playlist.extend(music_wrappers)
send_multi_lines_in_channel(bot, msgs, "")
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):
@@ -866,19 +867,19 @@ def cmd_add_tag(bot, user, text, command, parameter):
if index.isdigit() and 1 <= int(index) <= len(var.playlist):
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()}")
- bot.send_msg(constants.strings("added_tags",
- tags=", ".join(tags),
- song=var.playlist[int(index) - 1].format_title()), text)
+ bot.send_msg(tr("added_tags",
+ tags=", ".join(tags),
+ song=var.playlist[int(index) - 1].format_title()), text)
return
elif index == "*":
for item in var.playlist:
item.add_tags(tags)
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
- 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):
@@ -903,15 +904,15 @@ def cmd_remove_tag(bot, user, text, command, parameter):
if tags[0] != "*":
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()}")
- bot.send_msg(constants.strings("removed_tags",
- tags=", ".join(tags),
- song=var.playlist[int(index) - 1].format_title()), text)
+ bot.send_msg(tr("removed_tags",
+ tags=", ".join(tags),
+ song=var.playlist[int(index) - 1].format_title()), text)
return
else:
var.playlist[int(index) - 1].clear_tags()
log.info(f"cmd: clear tags from song {var.playlist[int(index) - 1].format_debug_string()}")
- bot.send_msg(constants.strings("cleared_tags",
- song=var.playlist[int(index) - 1].format_title()), text)
+ bot.send_msg(tr("cleared_tags",
+ song=var.playlist[int(index) - 1].format_title()), text)
return
elif index == "*":
@@ -919,26 +920,26 @@ def cmd_remove_tag(bot, user, text, command, parameter):
for item in var.playlist:
item.remove_tags(tags)
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
else:
for item in var.playlist:
item.clear_tags()
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
- 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):
global song_shortlist
if not parameter:
- bot.send_msg(constants.strings('bad_parameter', command=command), text)
+ bot.send_msg(tr('bad_parameter', command=command), text)
return
- msgs = [constants.strings('multiple_file_found') + ""]
+ msgs = [tr('multiple_file_found') + ""]
count = 0
tags = parameter.split(",")
@@ -957,20 +958,20 @@ def cmd_find_tagged(bot, user, text, command, parameter):
if count != 0:
msgs.append("
")
if count > ITEMS_PER_PAGE:
- msgs.append(constants.strings("records_omitted"))
- msgs.append(constants.strings("shortlist_instruction"))
+ msgs.append(tr("records_omitted"))
+ msgs.append(tr("shortlist_instruction"))
send_multi_lines(bot, msgs, text, "")
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):
global song_shortlist
if not parameter:
- bot.send_msg(constants.strings('bad_parameter', command=command), text)
+ bot.send_msg(tr('bad_parameter', command=command), text)
return
- msgs = [constants.strings('multiple_file_found') + ""]
+ msgs = [tr('multiple_file_found') + ""]
count = 0
_keywords = parameter.split(" ")
@@ -988,7 +989,7 @@ def cmd_search_library(bot, user, text, command, parameter):
music_wrapper = get_cached_wrapper(items[0], user)
var.playlist.append(music_wrapper)
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:
for item in items:
count += 1
@@ -1002,19 +1003,19 @@ def cmd_search_library(bot, user, text, command, parameter):
if count != 0:
msgs.append("
")
if count > ITEMS_PER_PAGE:
- msgs.append(constants.strings("records_omitted"))
- msgs.append(constants.strings("shortlist_instruction"))
+ msgs.append(tr("records_omitted"))
+ msgs.append(tr("shortlist_instruction"))
send_multi_lines(bot, msgs, text, "")
else:
- bot.send_msg(constants.strings("no_file"), text)
+ bot.send_msg(tr("no_file"), text)
else:
- bot.send_msg(constants.strings("no_file"), text)
+ bot.send_msg(tr("no_file"), text)
def cmd_shortlist(bot, user, text, command, parameter):
global song_shortlist, log
if parameter.strip() == "*":
- msgs = [constants.strings('multiple_file_added') + ""]
+ msgs = [tr('multiple_file_added') + ""]
music_wrappers = []
for kwargs in song_shortlist:
kwargs['user'] = user
@@ -1032,11 +1033,11 @@ def cmd_shortlist(bot, user, text, command, parameter):
try:
indexes = [int(i) for i in parameter.split(" ")]
except ValueError:
- bot.send_msg(constants.strings('bad_parameter', command=command), text)
+ bot.send_msg(tr('bad_parameter', command=command), text)
return
if len(indexes) > 1:
- msgs = [constants.strings('multiple_file_added') + ""]
+ msgs = [tr('multiple_file_added') + ""]
music_wrappers = []
for index in indexes:
if 1 <= index <= len(song_shortlist):
@@ -1048,7 +1049,7 @@ def cmd_shortlist(bot, user, text, command, parameter):
msgs.append("- [{}] {}
".format(music_wrapper.item().type, music_wrapper.item().title))
else:
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
var.playlist.extend(music_wrappers)
@@ -1064,10 +1065,10 @@ def cmd_shortlist(bot, user, text, command, parameter):
music_wrapper = get_cached_wrapper_from_scrap(**kwargs)
var.playlist.append(music_wrapper)
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
- 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):
@@ -1075,11 +1076,11 @@ def cmd_delete_from_library(bot, user, text, command, parameter):
try:
indexes = [int(i) for i in parameter.split(" ")]
except ValueError:
- bot.send_msg(constants.strings('bad_parameter', command=command), text)
+ bot.send_msg(tr('bad_parameter', command=command), text)
return
if len(indexes) > 1:
- msgs = [constants.strings('multiple_file_added') + "