feat: support relative volume adjustment (+N/-N)
!volume +10 increases by 10, !volume -5 decreases by 5. Out-of-range results (below 0 or above 100) are rejected. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -405,13 +405,14 @@ async def cmd_testtone(bot, message):
|
||||
await bot.reply(message, "Test tone complete")
|
||||
|
||||
|
||||
@command("volume", help="Music: !volume [0-100]")
|
||||
@command("volume", help="Music: !volume [0-100|+N|-N]")
|
||||
async def cmd_volume(bot, message):
|
||||
"""Get or set playback volume.
|
||||
|
||||
Usage:
|
||||
!volume Show current volume
|
||||
!volume <0-100> Set volume (takes effect immediately)
|
||||
!volume +N/-N Adjust volume relatively
|
||||
"""
|
||||
if not _is_mumble(bot):
|
||||
return
|
||||
@@ -422,12 +423,18 @@ async def cmd_volume(bot, message):
|
||||
await bot.reply(message, f"Volume: {ps['volume']}%")
|
||||
return
|
||||
|
||||
arg = parts[1].strip()
|
||||
relative = arg.startswith("+") or (arg.startswith("-") and arg != "-")
|
||||
|
||||
try:
|
||||
val = int(parts[1])
|
||||
val = int(arg)
|
||||
except ValueError:
|
||||
await bot.reply(message, "Usage: !volume <0-100>")
|
||||
await bot.reply(message, "Usage: !volume <0-100|+N|-N>")
|
||||
return
|
||||
|
||||
if relative:
|
||||
val = ps["volume"] + val
|
||||
|
||||
if val < 0 or val > 100:
|
||||
await bot.reply(message, "Volume must be 0-100")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user