From 62ffb375bdbeb977c987239c50737da832fff16b Mon Sep 17 00:00:00 2001 From: CramMK Date: Thu, 13 Feb 2020 23:40:41 +0100 Subject: [PATCH] YT works, fixed some things --- aquabot.py | 2 +- cogs/anime.py | 3 +- cogs/general.py | 1 - cogs/help.py | 5 +- cogs/utility.py | 18 ++++--- cogs/voice.py | 123 ++++++++++++++++++++++++------------------------ 6 files changed, 75 insertions(+), 77 deletions(-) diff --git a/aquabot.py b/aquabot.py index a0eae7a..29cdb0b 100644 --- a/aquabot.py +++ b/aquabot.py @@ -50,7 +50,7 @@ async def activity(): status = f"{new_activity[1]} | {loadconfig.__prefix__}aquabot" activity = discord.Activity(name=status, type=new_activity[0]) await bot.change_presence(activity=activity) - await asyncio.sleep(10) # Time in minutes + await asyncio.sleep(10*60) # Time in minutes # BOT STARTING EVENT @bot.event diff --git a/cogs/anime.py b/cogs/anime.py index b6d0e72..556bcf4 100644 --- a/cogs/anime.py +++ b/cogs/anime.py @@ -32,8 +32,9 @@ class Anime(commands.Cog): @commands.command(name="waifumedia") async def waifumedia(self, ctx, waifu: str): """ - Sends a random pic of a waifu (list in config/media.py) + Sends a random pic of a waifu """ + # config/media.py try: media = random.choice(loadconfig.__media_waifu__[waifu]) await ctx.send(media) diff --git a/cogs/general.py b/cogs/general.py index c6c9b20..12df62d 100644 --- a/cogs/general.py +++ b/cogs/general.py @@ -26,7 +26,6 @@ class General(commands.Cog): """ embed = discord.Embed(colour=discord.Colour.blue()) embed.set_thumbnail(url=ctx.me.avatar_url) - embed.set_image(url=ctx.me.avatar_url) embed.add_field(name="Owner", value=self.bot.AppInfo.owner, inline=True) embed.add_field(name="Command Prefix", value=loadconfig.__prefix__, inline=True) diff --git a/cogs/help.py b/cogs/help.py index 231673b..668f466 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -22,9 +22,8 @@ class Help(commands.Cog): """ response = ( "I'm the usele... divine AquaBot!\n" - "If you need help. try using the `help` command!" - ) - await ctx.send(response) + "If you need help. try using the `help` command!") + await ctx.send(response) # COG ENDING diff --git a/cogs/utility.py b/cogs/utility.py index 8563858..ca105b1 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -20,21 +20,19 @@ class Utility(commands.Cog): # COG BODY @commands.command(name="invitelink", aliases=["invite"]) - async def invite_link(self, ctx, age: int, uses: int, unique: bool): + async def invite_link(self, ctx): """ Sends the server's invitelink to chat """ - if age is None: - age = 60 - if uses is None: - uses = 100 - if unique is None: - unique = True + age = 60 * 10 + uses = 100 + unique = True - link = await bot.create_invite( + channel = ctx.message.channel + link = await channel.create_invite( max_age = age, max_uses = uses, - unique = uses, + unique = unique, reason = "Created by AquaBot") link_embed = discord.Embed(color=discord.Colour.blue()) @@ -44,7 +42,7 @@ class Utility(commands.Cog): inline=True) link_embed.set_footer( text=f"Age: {age}, Uses: {uses}, Unique: {unique}", - icon_url=loadconfig.__avater__ + icon_url=loadconfig.__avatar__ ) await ctx.send(embed=link_embed) diff --git a/cogs/voice.py b/cogs/voice.py index 8117c05..1166e59 100644 --- a/cogs/voice.py +++ b/cogs/voice.py @@ -59,77 +59,78 @@ class Voice(commands.Cog): await ctx.send("I'm not connected to a channel!") - # Begin of YouTube Player - youtube_dl.utils.bug_reports_message = lambda: '' - ytdl_format_options = { - 'format': 'bestaudio/best', - 'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s', - 'restrictfilenames': True, - 'noplaylist': True, - 'nocheckcertificate': True, - 'ignoreerrors': False, - 'logtostderr': False, - 'quiet': True, - 'no_warnings': True, - 'default_search': 'auto', - 'source_address': '0.0.0.0' - } - ffmpeg_options = { - 'options': '-vn' - } - ytdl = youtube_dl.YoutubeDL(ytdl_format_options) - class YTDLSource(discord.PCMVolumeTransformer): - def __init__(self, source, *, data, volume=0.5): - super().__init__(source, volume) - - self.data = data - - self.title = data.get('title') - self.url = data.get('url') - - # Maybe i can make a fancy embed out of this? - self.uploader = data.get('uploader') - self.uploader_url = data.get('uploader_url') - date = data.get('upload_date') - self.upload_date = date[6:8] + '.' + date[4:6] + '.' + date[0:4] - self.title = data.get('title') - self.thumbnail = data.get('thumbnail') - self.description = data.get('description') - self.duration = self.parse_duration(int(data.get('duration'))) - self.tags = data.get('tags') - self.url = data.get('webpage_url') - self.views = data.get('view_count') - self.likes = data.get('like_count') - self.dislikes = data.get('dislike_count') - self.stream_url = data.get('url') - - @classmethod - async def from_url(cls, url, *, loop=None, stream=False): - loop = loop or asyncio.get_event_loop() - data = await loop.run_in_executor( - None, - lambda: ytdl.extract_info(url, download=not stream)) - - if 'entries' in data: - # take first item from a playlist - data = data['entries'][0] - - filename = data['url'] if stream else ytdl.prepare_filename(data) - return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data) - + # Begin of YouTube Player + @commands.command(name="play", aliases=["p"]) @commands.guild_only() async def play(self, ctx, url: str): """ Plays music from YouTube """ - voice = get(bot.voice_clients, guild=ctx.guild) + youtube_dl.utils.bug_reports_message = lambda: '' + ytdl_format_options = { + 'format': 'bestaudio/best', + 'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s', + 'restrictfilenames': True, + 'noplaylist': True, + 'nocheckcertificate': True, + 'ignoreerrors': False, + 'logtostderr': False, + 'quiet': True, + 'no_warnings': True, + 'default_search': 'auto', + 'source_address': '0.0.0.0' + } + ffmpeg_options = { + 'options': '-vn' + } + ytdl = youtube_dl.YoutubeDL(ytdl_format_options) + class YTDLSource(discord.PCMVolumeTransformer): + def __init__(self, source, *, data, volume=0.5): + super().__init__(source, volume) + + self.data = data + + self.title = data.get('title') + self.url = data.get('url') + + # Maybe i can make a fancy embed out of this? + self.uploader = data.get('uploader') + self.uploader_url = data.get('uploader_url') + date = data.get('upload_date') + self.upload_date = date[6:8] + '.' + date[4:6] + '.' + date[0:4] + self.title = data.get('title') + self.thumbnail = data.get('thumbnail') + self.description = data.get('description') +# self.duration = self.parse_duration(int(data.get('duration'))) + self.tags = data.get('tags') + self.url = data.get('webpage_url') + self.views = data.get('view_count') + self.likes = data.get('like_count') + self.dislikes = data.get('dislike_count') + self.stream_url = data.get('url') + + @classmethod + async def from_url(cls, url, *, loop=None, stream=False): + loop = loop or asyncio.get_event_loop() + data = await loop.run_in_executor( + None, + lambda: ytdl.extract_info(url, download=not stream)) + + if 'entries' in data: + # take first item from a playlist + data = data['entries'][0] + + filename = data['url'] if stream else ytdl.prepare_filename(data) + return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data) + + voice = get(self.bot.voice_clients, guild=ctx.guild) async with ctx.typing(): player = await YTDLSource.from_url(url, loop=self.bot.loop) - ctx.voice.play( + voice.play( 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}") # End of YouTube Player