Implementation for setting max volume (#336)
* Added support for creating a max volume * Fixed db function calls * Fixed issue with max volume always adjusting volume
This commit is contained in:
parent
0650e7279f
commit
a50a067641
34
command.py
34
command.py
@ -70,6 +70,7 @@ def register_all_commands(bot):
|
||||
bot.register_command(commands('kill'), cmd_kill, admin=True)
|
||||
bot.register_command(commands('list_webinterface_user'), cmd_web_user_list, admin=True)
|
||||
bot.register_command(commands('remove_webinterface_user'), cmd_web_user_remove, admin=True)
|
||||
bot.register_command(commands('max_volume'), cmd_max_volume, admin=True)
|
||||
bot.register_command(commands('update'), cmd_update, 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_ban_list'), cmd_url_ban_list, no_partial_match=True, admin=True)
|
||||
@ -673,15 +674,38 @@ def cmd_volume(bot, user, text, command, parameter):
|
||||
global log
|
||||
|
||||
# The volume is a percentage
|
||||
max_vol = min(int(var.config.getfloat('bot', 'max_volume') * 100), 100.0)
|
||||
if var.db.has_option('bot', 'max_volume'):
|
||||
max_vol = float(var.db.get('bot', 'max_volume')) * 100.0
|
||||
if parameter and parameter.isdigit() and 0 <= int(parameter) <= 100:
|
||||
bot.volume_helper.set_volume(float(parameter) / 100.0)
|
||||
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}')
|
||||
if int(parameter) <= max_vol:
|
||||
vol = int(parameter)
|
||||
bot.send_msg(tr('change_volume', volume=int(parameter), user=bot.mumble.users[text.actor]['name']), text)
|
||||
else:
|
||||
vol = max_vol
|
||||
bot.send_msg(tr('max_volume', max=int(vol)), text)
|
||||
bot.volume_helper.set_volume(float(vol) / 100.0)
|
||||
var.db.set('bot', 'volume', str(float(vol) / 100.0))
|
||||
log.info(f'cmd: volume set to {float(vol) / 100.0}')
|
||||
else:
|
||||
bot.send_msg(tr('current_volume', volume=int(bot.volume_helper.plain_volume_set * 100)), text)
|
||||
|
||||
|
||||
def cmd_max_volume(bot, user, text, command, parameter):
|
||||
global log
|
||||
|
||||
if parameter and parameter.isdigit() and 0 <= int(parameter) <= 100:
|
||||
max_vol = float(parameter) / 100.0
|
||||
var.db.set('bot', 'max_volume', float(parameter) / 100.0)
|
||||
bot.send_msg(tr('change_max_volume', max=parameter, user=bot.mumble.users[text.actor]['name']), text)
|
||||
if int(bot.volume_helper.plain_volume_set) > max_vol:
|
||||
bot.volume_helper.set_volume(max_vol)
|
||||
log.info(f'cmd: max volume set to {max_vol}')
|
||||
else:
|
||||
max_vol = var.config.getfloat('bot', 'max_volume') * 100.0
|
||||
if var.db.has_option('bot', 'max_volume'):
|
||||
max_vol = var.db.getfloat('bot', 'max_volume') * 100.0
|
||||
bot.send_msg(tr('current_max_volume', max=int(max_vol)), text)
|
||||
|
||||
def cmd_ducking(bot, user, text, command, parameter):
|
||||
global log
|
||||
|
||||
|
@ -49,6 +49,7 @@ language = en_US
|
||||
logfile =
|
||||
max_track_duration = 60
|
||||
max_track_playlist = 20
|
||||
max_volume = 1.0
|
||||
music_database_path = music.db
|
||||
music_folder = music_folder/
|
||||
pip3_path = venv/bin/pip
|
||||
@ -117,6 +118,7 @@ kill = kill
|
||||
last = last
|
||||
list_file = listfile
|
||||
list_webinterface_user = webuserlist
|
||||
max_volume = maxvolume
|
||||
mode = mode
|
||||
pause = pause
|
||||
play = p, play
|
||||
|
@ -111,6 +111,9 @@ port = 64738
|
||||
# and reload it the next time it start. It requires save_music_library to be True to function.
|
||||
#save_playlist = True
|
||||
|
||||
# 'max_volume': Maximum volume able to be set by users. 0.0 - 1.0
|
||||
#max_volume = 0.8
|
||||
|
||||
# 'max_track_playlist': Maximum track played when a playlist is added.
|
||||
#max_track_playlist = 20
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
"bad_url": "Bad URL requested.",
|
||||
"cache_refreshed": "Cache refreshed!",
|
||||
"change_ducking_volume": "Volume on ducking set to {volume} by {user}.",
|
||||
"change_max_volume": "Max volume set to {max} by {user}",
|
||||
"change_mode": "Playback mode set to <i>{mode}</i> by {user}.",
|
||||
"change_volume": "Volume set to {volume} by {user}.",
|
||||
"cleared": "Playlist emptied.",
|
||||
@ -16,6 +17,7 @@
|
||||
"cleared_tags_from_all": "Removed all tags from songs on the playlist.",
|
||||
"command_disabled": "{command}: command disabled!",
|
||||
"current_ducking_volume": "Volume on ducking: {volume}.",
|
||||
"current_max_volume": "Current max volume: {max}.",
|
||||
"current_mode": "Current playback mode is <i>{mode}</i>.",
|
||||
"current_volume": "Current volume: {volume}.",
|
||||
"database_dropped": "Database dropped. All records have gone.",
|
||||
@ -29,6 +31,7 @@
|
||||
"help": "<h3>Commands</h3>\n<b>Control</b>\n<ul>\n<li> <b>!<u>w</u>eb</b> - get the URL of the web interface, if enabled. </li>\n<li> <b>!play </b> (or <b>!p</b>) [{num}] [{start_from}] - resume from pausing / start to play (the num-th song is num if given) </li>\n<li> <b>!<u>pa</u>use </b> - pause </li>\n<li> <b>!<u>st</u>op </b> - stop playing </li>\n<li> <b>!<u>sk</u>ip </b> - jump to the next song </li>\n<li> <b>!<u>la</u>st </b> - jump to the last song </li>\n<li> <b>!<u>v</u>olume </b> {volume} - get or change the volume (from 0 to 100) </li>\n<li> <b>!<u>m</u>ode </b> [{mode}] - get or set the playback mode, {mode} should be one of <i>one-shot</i> (remove\nitem once played), <i>repeat</i> (looping through the playlist), <i>random</i> (randomize the playlist),\n<i>autoplay</i> (randomly grab something from the music library).</li>\n<li> <b>!duck </b> on/off - enable or disable ducking function </li>\n<li> <b>!duckv </b> {volume} - set the volume of the bot when ducking is activated </li>\n<li> <b>!<u>duckt</u>hres </b> - set the threshold of volume to activate ducking (3000 by default) </li>\n<li> <b>!<u>o</u>ust </b> - stop playing and go to default channel </li>\n</ul>\n<b>Playlist</b>\n<ul>\n<li> <b>!<u>n</u>ow </b> (or <b>!np</b>) - display the current song </li>\n<li> <b>!<u>q</u>ueue </b> - display items in the playlist </li>\n<li> <b>!<u>t</u>ag </b> {tags} - add all items with tags {tags}, tags separated by \",\". </li>\n<li> <b>!file </b>(or <b>!f</b>) {path/folder/keyword} - add a single file to the playlist by its path or keyword in its path. </li>\n<li> <b>!<u>filem</u>atch </b>(or <b>!fm</b>) {pattern} - add all files that match regex {pattern} </li>\n<li> <b>!<u>ur</u>l </b> {url} - add Youtube or SoundCloud music </li>\n<li> <b>!<u>playl</u>ist </b> {url} [{offset}] - add all items in a Youtube or SoundCloud playlist, and start with the {offset}-th item </li>\n<li> <b>!<u>rad</u>io </b> {url} - append a radio {url} to the playlist </li>\n<li> <b>!<u>rbq</u>uery </b> {keyword} - query http://www.radio-browser.info for a radio station </li>\n<li> <b>!<u>rbp</u>lay </b> {id} - play a radio station with {id} (eg. !rbplay 96746) </li>\n<li> <b>!<u>ys</u>earch </b> {keywords} - query youtube. Use <i>!ysearch -n</i> to turn the page. </li>\n<li> <b>!<u>yp</u>lay </b> {keywords} - add the first search result of {keywords} into the playlist.</li>\n<li> <b>!<u>sh</u>ortlist </b> (or <b>!sl</b>) {indexes/*} - add {indexes}-th item (or all items if * is given) on the shortlist. </li>\n<li> <b>!rm </b> {num} - remove the num-th song on the playlist </li>\n<li> <b>!<u>rep</u>eat </b> [{num}] - repeat current song {num} (1 by default) times.</li>\n<li> <b>!<u>ran</u>dom </b> - randomize the playlist.</li>\n</ul>\n<b>Music Library</b>\n<ul>\n<li> <b>!<u>se</u>arch </b> {keywords} - find item with {keywords} in the music library, keywords separated by space.</li>\n<li> <b>!<u>li</u>stfile </b> [{pattern}] - display list of available files (whose paths match the regex pattern if {pattern} is given) </li>\n<li> <b>!<u>addt</u>ag </b> [{index}] {tags} - add {tags} to {index}-th(current song if {index} is omitted) item on the playlist, tags separated by \",\". </li>\n<li> <b>!<u>addt</u>ag </b> * {tags} - add {tags} to all items on the playlist. </li>\n<li> <b>!<u>un</u>tag </b> [{index/*}] {tags}/* - remove {tags}/all tags from {index}-th(current song if {index} is omitted) item on the playlist. </li>\n<li> <b>!<u>fin</u>dtagged </b> (or <b>!ft</b>) {tags} - find item with {tags} in the music library. </li>\n<li> <b>!<u>del</u>ete </b> {index} - delete {index}-th item on the shortlist from the music library. </li>\n</ul>\n<b>Other</b>\n<ul>\n<li> <b>!<u>j</u>oinme {token} </b> - join your own channel with {token}.</li>\n<li> <b>!<u>password</u> {password} </b> - change your password, used to access the web interface.</li>\n</ul>",
|
||||
"invalid_index": "Invalid index <i>{index}</i>. Use <i>!queue</i> to see the playlist.",
|
||||
"last_song_on_the_queue": "Last one on the queue.",
|
||||
"max_volume": "Volume exceeds max volume of {max}. Setting volume to max.",
|
||||
"multiple_file_added": "Multiple items added:",
|
||||
"multiple_file_deleted": "Multiple items deleted from the library:",
|
||||
"multiple_file_found": "Found:",
|
||||
@ -167,4 +170,4 @@
|
||||
"url_placeholder": "URL...",
|
||||
"volume_slider": "Volume Slider"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,9 +137,13 @@ class MumbleBot:
|
||||
# ====== Volume ======
|
||||
self.volume_helper = util.VolumeHelper()
|
||||
|
||||
max_vol = var.config.getfloat('bot', 'max_volume')
|
||||
if var.db.has_option('bot', 'max_volume'):
|
||||
max_vol = var.db.getfloat('bot', 'max_volume')
|
||||
_volume = var.config.getfloat('bot', 'volume')
|
||||
if var.db.has_option('bot', 'volume'):
|
||||
_volume = var.db.getfloat('bot', 'volume')
|
||||
_volume = min(_volume, max_vol)
|
||||
self.volume_helper.set_volume(_volume)
|
||||
|
||||
self.is_ducking = False
|
||||
|
Loading…
x
Reference in New Issue
Block a user