mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Allow mid-song volume changes (#346)
This commit is contained in:
parent
6b51b12c12
commit
ebab92f61d
@ -342,9 +342,7 @@ class Audio:
|
|||||||
song_filename = os.path.join(self.cache_path, filename)
|
song_filename = os.path.join(self.cache_path, filename)
|
||||||
|
|
||||||
use_avconv = self.settings["AVCONV"]
|
use_avconv = self.settings["AVCONV"]
|
||||||
volume = self.get_server_settings(server)["VOLUME"] / 100
|
options = '-b:a 64k -bufsize 64k'
|
||||||
options = \
|
|
||||||
'-filter "volume=volume={}" -b:a 64k -bufsize 64k'.format(volume)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
voice_client.audio_player.process.kill()
|
voice_client.audio_player.process.kill()
|
||||||
@ -359,6 +357,10 @@ class Audio:
|
|||||||
voice_client.audio_player = voice_client.create_ffmpeg_player(
|
voice_client.audio_player = voice_client.create_ffmpeg_player(
|
||||||
song_filename, use_avconv=use_avconv, options=options)
|
song_filename, use_avconv=use_avconv, options=options)
|
||||||
|
|
||||||
|
# Set initial volume
|
||||||
|
vol = self.get_server_settings(server)['VOLUME'] / 100
|
||||||
|
voice_client.audio_player.volume = vol
|
||||||
|
|
||||||
return voice_client # Just for ease of use, it's modified in-place
|
return voice_client # Just for ease of use, it's modified in-place
|
||||||
|
|
||||||
# TODO: _current_playlist
|
# TODO: _current_playlist
|
||||||
@ -1012,17 +1014,28 @@ class Audio:
|
|||||||
|
|
||||||
@audioset.command(pass_context=True, name="volume", no_pm=True)
|
@audioset.command(pass_context=True, name="volume", no_pm=True)
|
||||||
@checks.mod_or_permissions(manage_messages=True)
|
@checks.mod_or_permissions(manage_messages=True)
|
||||||
async def audioset_volume(self, ctx, percent: int):
|
async def audioset_volume(self, ctx, percent: int=None):
|
||||||
"""Sets the volume (0 - 100)"""
|
"""Sets the volume (0 - 100)
|
||||||
|
Note: volume may be set up to 200 but you may experience clipping."""
|
||||||
server = ctx.message.server
|
server = ctx.message.server
|
||||||
if percent >= 0 and percent <= 100:
|
if percent is None:
|
||||||
|
vol = self.get_server_settings(server)['VOLUME']
|
||||||
|
msg = "Volume is currently set to %d%%" % vol
|
||||||
|
elif percent >= 0 and percent <= 200:
|
||||||
self.set_server_setting(server, "VOLUME", percent)
|
self.set_server_setting(server, "VOLUME", percent)
|
||||||
await self.bot.say("Volume is now set at " + str(percent) +
|
msg = "Volume is now set to %d." % percent
|
||||||
". It will take effect after the current"
|
if percent > 100:
|
||||||
" track.")
|
msg += "\nWarning: volume levels above 100 may result in clipping"
|
||||||
|
|
||||||
|
# Set volume of playing audio
|
||||||
|
vc = self.voice_client(server)
|
||||||
|
if vc:
|
||||||
|
vc.audio_player.volume = percent / 100
|
||||||
|
|
||||||
self.save_settings()
|
self.save_settings()
|
||||||
else:
|
else:
|
||||||
await self.bot.say("Volume must be between 0 and 100.")
|
msg = "Volume must be between 0 and 100."
|
||||||
|
await self.bot.say(msg)
|
||||||
|
|
||||||
@audioset.command(pass_context=True, name="vote", no_pm=True,
|
@audioset.command(pass_context=True, name="vote", no_pm=True,
|
||||||
hidden=True, enabled=False)
|
hidden=True, enabled=False)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user