Make properties private
This commit is contained in:
parent
a27733675e
commit
b55b3a3f0d
24
src/bot.py
24
src/bot.py
|
@ -17,9 +17,9 @@ youtube_dl.utils.bug_reports_message = lambda: ''
|
||||||
|
|
||||||
class Music(commands.Cog):
|
class Music(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self._bot = bot
|
||||||
self.queue = asyncio.Queue()
|
self._queue = asyncio.Queue()
|
||||||
self.queue_lock = asyncio.Lock()
|
self._queue_lock = asyncio.Lock()
|
||||||
self._ytdl_format_options = {
|
self._ytdl_format_options = {
|
||||||
'format': 'bestaudio/best',
|
'format': 'bestaudio/best',
|
||||||
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
|
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
|
||||||
|
@ -36,34 +36,34 @@ class Music(commands.Cog):
|
||||||
self._ffmpeg_options = {
|
self._ffmpeg_options = {
|
||||||
'options': '-vn'
|
'options': '-vn'
|
||||||
}
|
}
|
||||||
self.ytdl = youtube_dl.YoutubeDL(self._ytdl_format_options)
|
self._ytdl = youtube_dl.YoutubeDL(self._ytdl_format_options)
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
self.handle_playback.start()
|
self._handle_playback.start()
|
||||||
|
|
||||||
@tasks.loop()
|
@tasks.loop()
|
||||||
async def handle_playback(self):
|
async def _handle_playback(self):
|
||||||
while True:
|
while True:
|
||||||
await self.queue_lock.acquire()
|
await self._queue_lock.acquire()
|
||||||
ctx, url, title = await self.queue.get()
|
ctx, url, title = await self._queue.get()
|
||||||
audio = discord.FFmpegPCMAudio(url, **self._ffmpeg_options)
|
audio = discord.FFmpegPCMAudio(url, **self._ffmpeg_options)
|
||||||
|
|
||||||
def after(err):
|
def after(err):
|
||||||
if err:
|
if err:
|
||||||
print(f"Player error: {err}")
|
print(f"Player error: {err}")
|
||||||
self.queue.task_done()
|
self._queue.task_done()
|
||||||
self.queue_lock.release()
|
self._queue_lock.release()
|
||||||
ctx.voice_client.play(audio, after=after)
|
ctx.voice_client.play(audio, after=after)
|
||||||
await ctx.send(f"Now playing: {title}")
|
await ctx.send(f"Now playing: {title}")
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def play(self, ctx, *, url):
|
async def play(self, ctx, *, url):
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
data = self.ytdl.extract_info(url, download=False)
|
data = self._ytdl.extract_info(url, download=False)
|
||||||
if 'entries' in data:
|
if 'entries' in data:
|
||||||
data = data['entries'][0]
|
data = data['entries'][0]
|
||||||
title = data.get('title')
|
title = data.get('title')
|
||||||
url = data.get('url')
|
url = data.get('url')
|
||||||
await self.queue.put((ctx, url, title))
|
await self._queue.put((ctx, url, title))
|
||||||
if ctx.voice_client.is_playing():
|
if ctx.voice_client.is_playing():
|
||||||
await ctx.send(f"Queued: {title}")
|
await ctx.send(f"Queued: {title}")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue