Save volume entries; handle some playlist quirks
This commit is contained in:
parent
e307a5262c
commit
7f261a81fa
|
@ -1,5 +1,5 @@
|
||||||
from .voice_utilities import *
|
from .voice_utilities import *
|
||||||
from discord import FFmpegPCMAudio, PCMVolumeTransformer
|
from discord import PCMVolumeTransformer
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
@ -21,7 +21,7 @@ if not discord.opus.is_loaded():
|
||||||
|
|
||||||
|
|
||||||
class VoiceState:
|
class VoiceState:
|
||||||
def __init__(self, guild, bot, user_queue=False):
|
def __init__(self, guild, bot, user_queue=False, volume=None):
|
||||||
self.guild = guild
|
self.guild = guild
|
||||||
self.songs = Playlist(bot)
|
self.songs = Playlist(bot)
|
||||||
self.djs = deque()
|
self.djs = deque()
|
||||||
|
@ -31,7 +31,7 @@ class VoiceState:
|
||||||
self.skip_votes = set()
|
self.skip_votes = set()
|
||||||
self.user_queue = user_queue
|
self.user_queue = user_queue
|
||||||
self.loop = bot.loop
|
self.loop = bot.loop
|
||||||
self._volume = .5
|
self._volume = volume or .5
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volume(self):
|
def volume(self):
|
||||||
|
@ -377,8 +377,10 @@ class Music:
|
||||||
|
|
||||||
# If we have connnected, create our voice state
|
# If we have connnected, create our voice state
|
||||||
queue_type = self.bot.db.load('server_settings', key=channel.guild.id, pluck='queue_type')
|
queue_type = self.bot.db.load('server_settings', key=channel.guild.id, pluck='queue_type')
|
||||||
|
volume = self.bot.db.load('server_settings', key=channel.guild.id, pluck='volume')
|
||||||
user_queue = queue_type == "user"
|
user_queue = queue_type == "user"
|
||||||
self.voice_states[channel.guild.id] = VoiceState(channel.guild, self.bot, user_queue=user_queue)
|
self.voice_states[channel.guild.id] = VoiceState(channel.guild, self.bot, user_queue=user_queue,
|
||||||
|
volume=volume)
|
||||||
|
|
||||||
# If we can send messages, edit it to let the channel know we have succesfully joined
|
# If we can send messages, edit it to let the channel know we have succesfully joined
|
||||||
if msg:
|
if msg:
|
||||||
|
@ -469,7 +471,8 @@ class Music:
|
||||||
"""Imports a song into the current voice queue"""
|
"""Imports a song into the current voice queue"""
|
||||||
# If we don't have a voice state yet, create one
|
# If we don't have a voice state yet, create one
|
||||||
if not self.bot.db.load('server_settings', key=ctx.message.guild.id, pluck='playlists_allowed'):
|
if not self.bot.db.load('server_settings', key=ctx.message.guild.id, pluck='playlists_allowed'):
|
||||||
await ctx.send("You cannot import playlists at this time; the {}allowplaylists command can be used to change this setting".format(ctx.prefix))
|
await ctx.send("You cannot import playlists at this time; the {}allowplaylists command can be used to "
|
||||||
|
"change this setting".format(ctx.prefix))
|
||||||
return
|
return
|
||||||
if ctx.message.guild.id not in self.voice_states:
|
if ctx.message.guild.id not in self.voice_states:
|
||||||
if not await ctx.invoke(self.join):
|
if not await ctx.invoke(self.join):
|
||||||
|
@ -490,7 +493,16 @@ class Music:
|
||||||
return
|
return
|
||||||
|
|
||||||
song = re.sub('[<>\[\]]', '', song)
|
song = re.sub('[<>\[\]]', '', song)
|
||||||
await self.import_playlist(song, ctx)
|
# Check if we've got the list variable in the URL, if so lets just use this
|
||||||
|
playlist_id = re.search(r'list=(.+)', song)
|
||||||
|
if playlist_id:
|
||||||
|
song = playlist_id.group(1)
|
||||||
|
try:
|
||||||
|
await self.import_playlist(song, ctx)
|
||||||
|
except WrongEntryTypeError:
|
||||||
|
await ctx.send("This URL is not a playlist! If you want to play this song just use `play`")
|
||||||
|
except ExtractionError:
|
||||||
|
await ctx.send("Failed to download {}! If this is not a playlist, use the `play` command".format(song))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
@ -537,6 +549,9 @@ class Music:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
entry = await self.add_entry(song, ctx)
|
entry = await self.add_entry(song, ctx)
|
||||||
|
# This error only happens if Discord has derped, and the voice state didn't get created succesfully
|
||||||
|
except KeyError:
|
||||||
|
await ctx.send("Sorry, but I failed to connect! Please try again!")
|
||||||
except LiveStreamError as e:
|
except LiveStreamError as e:
|
||||||
await ctx.send(str(e))
|
await ctx.send(str(e))
|
||||||
except WrongEntryTypeError:
|
except WrongEntryTypeError:
|
||||||
|
@ -586,6 +601,8 @@ class Music:
|
||||||
await ctx.send("Sorry but the max volume is 100%")
|
await ctx.send("Sorry but the max volume is 100%")
|
||||||
else:
|
else:
|
||||||
state.volume = value
|
state.volume = value
|
||||||
|
entry = {'server_id': str(ctx.message.guild.id), 'volume': value}
|
||||||
|
self.bot.db.save('server_settings', entry)
|
||||||
await ctx.send('Set the volume to {:.0%}'.format(state.volume))
|
await ctx.send('Set the volume to {:.0%}'.format(state.volume))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
|
|
Loading…
Reference in a new issue