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:
Caleb Leinz (he/him)
2022-07-12 09:13:10 -07:00
committed by GitHub
parent 0650e7279f
commit a50a067641
5 changed files with 42 additions and 6 deletions

View File

@ -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