Rework volume to have a default volume set for every song that plays
This commit is contained in:
parent
bd7b5a5ca5
commit
cbd522991a
|
@ -24,6 +24,17 @@ class VoiceState:
|
||||||
self.required_skips = 0
|
self.required_skips = 0
|
||||||
self.skip_votes = set()
|
self.skip_votes = set()
|
||||||
self.audio_player = bot.loop.create_task(self.audio_player_task())
|
self.audio_player = bot.loop.create_task(self.audio_player_task())
|
||||||
|
self._volume = 50
|
||||||
|
|
||||||
|
@property
|
||||||
|
def volume(self):
|
||||||
|
return self._volume
|
||||||
|
|
||||||
|
@volume.setter
|
||||||
|
def volume(self, v):
|
||||||
|
self._volume = v
|
||||||
|
if self.voice and self.voice.source:
|
||||||
|
self.voice.source.volume = v
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def voice(self):
|
def voice(self):
|
||||||
|
@ -57,7 +68,7 @@ class VoiceState:
|
||||||
before_options='-nostdin',
|
before_options='-nostdin',
|
||||||
options='-vn -b:a 128k'
|
options='-vn -b:a 128k'
|
||||||
)
|
)
|
||||||
source = PCMVolumeTransformer(source)
|
source = PCMVolumeTransformer(source, volume=self.volume)
|
||||||
self.voice.play(source, after=self.after)
|
self.voice.play(source, after=self.after)
|
||||||
self.current.start_time = time.time()
|
self.current.start_time = time.time()
|
||||||
|
|
||||||
|
@ -351,15 +362,15 @@ class Music:
|
||||||
"""Sets the volume of the currently playing song."""
|
"""Sets the volume of the currently playing song."""
|
||||||
|
|
||||||
state = self.voice_states.get(ctx.message.guild.id)
|
state = self.voice_states.get(ctx.message.guild.id)
|
||||||
if state is None or state.voice is None or state.voice.source is None:
|
value = value / 100
|
||||||
await ctx.send("Not playing anything right now, please set volume after playing something")
|
if state is None or state.voice is None:
|
||||||
|
await ctx.send("I need to be in a channel before my volume can be set")
|
||||||
elif value is None:
|
elif value is None:
|
||||||
volume = state.voice.source.volume
|
await ctx.send('Current volume is {:.0%}'.format(state.voice.source.volume))
|
||||||
await ctx.send("Current volume is {}".format(volume))
|
elif value > 1.0:
|
||||||
elif value > 200:
|
await ctx.send("Sorry but the max volume is 100%")
|
||||||
await ctx.send("Sorry but the max volume is 200")
|
else:
|
||||||
elif state.playing:
|
state.volume = value
|
||||||
state.voice.source.volume = value / 100
|
|
||||||
await ctx.send('Set the volume to {:.0%}'.format(state.voice.source.volume))
|
await ctx.send('Set the volume to {:.0%}'.format(state.voice.source.volume))
|
||||||
|
|
||||||
@commands.command(pass_context=True)
|
@commands.command(pass_context=True)
|
||||||
|
|
Loading…
Reference in a new issue