Cleanup dl and cleaner play

This commit is contained in:
CramMK
2020-03-25 10:34:10 +01:00
parent 62ffb375bd
commit e8f270964a

View File

@@ -14,6 +14,7 @@ from discord.ext import commands
from discord.utils import get from discord.utils import get
from discord import FFmpegPCMAudio from discord import FFmpegPCMAudio
import os import os
import glob
import youtube_dl import youtube_dl
# COG INIT # COG INIT
@@ -22,6 +23,12 @@ class Voice(commands.Cog):
self.bot = bot self.bot = bot
# COG BODY # COG BODY
# Cleanup downloads
def remove_dls():
yt_files = glob.glob("youtube-*")
for f in yt_files:
os.remove(f)
@commands.command(name="join", aliases=["j"]) @commands.command(name="join", aliases=["j"])
@commands.guild_only() @commands.guild_only()
async def join(self, ctx): async def join(self, ctx):
@@ -43,7 +50,7 @@ class Voice(commands.Cog):
await ctx.send(f"`Joined {channel}!`") await ctx.send(f"`Joined {channel}!`")
@commands.command(name="leave", aliases=["quit, l"]) @commands.command(name="leave", aliases=["quit"])
@commands.guild_only() @commands.guild_only()
async def leave(self, ctx): async def leave(self, ctx):
""" """
@@ -55,6 +62,22 @@ class Voice(commands.Cog):
if voice and voice.is_connected(): if voice and voice.is_connected():
await voice.disconnect() await voice.disconnect()
await ctx.send(f"`Left {channel}!`") await ctx.send(f"`Left {channel}!`")
# cleanup
remove_dls()
else:
await ctx.send("I'm not connected to a channel!")
@commands.command(name="skip")
@commands.guild_only()
async def skip(self, ctx):
"""
Skips the current song: WIP!
"""
channel = ctx.message.author.voice.channel
voice = get(self.bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await ctx.send("`Skipping...`")
else: else:
await ctx.send("I'm not connected to a channel!") await ctx.send("I'm not connected to a channel!")
@@ -63,10 +86,13 @@ class Voice(commands.Cog):
@commands.command(name="play", aliases=["p"]) @commands.command(name="play", aliases=["p"])
@commands.guild_only() @commands.guild_only()
async def play(self, ctx, url: str): async def play(self, ctx, *query: str):
""" """
Plays music from YouTube Plays music from YouTube
""" """
# concat query tuple into string
url = " ".join(query)
youtube_dl.utils.bug_reports_message = lambda: '' youtube_dl.utils.bug_reports_message = lambda: ''
ytdl_format_options = { ytdl_format_options = {
'format': 'bestaudio/best', 'format': 'bestaudio/best',
@@ -131,7 +157,14 @@ class Voice(commands.Cog):
voice.play( voice.play(
player, player,
after=lambda e: print('Player error: %s' % e) if e else None) after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send(f"Now playing: {player.title}")
player_embed = discord.Embed(color.discord.Colour.blue())
player_embed.set_thumbal(url=player.thumbnail)
player_embed.add_field(name="Song", value=player.title)
player_embed.add_field(name="Uploader", value=player.uploader)
await ctx.send(player_embed)
# End of YouTube Player # End of YouTube Player