From 7ccf2be96188e074df2368668274c208f70d0caa Mon Sep 17 00:00:00 2001 From: Benjamin O'Brien Date: Sun, 4 Oct 2020 12:09:59 -0500 Subject: [PATCH] Join, Leave, Stop & De/Encrypt --- commands/entertainment/decrypt.py | 47 ++++++++++++++++++++++++++++ commands/entertainment/encrypt.py | 51 +++++++++++++++++++++++++++++++ commands/misc/bio.py | 4 +-- commands/misc/card.py | 6 ++-- commands/music/join.py | 38 +++++++++++++++++++++++ commands/music/leave.py | 44 ++++++++++++++++++++++++++ commands/music/play.py | 10 +++++- commands/music/stop.py | 44 ++++++++++++++++++++++++++ 8 files changed, 239 insertions(+), 5 deletions(-) create mode 100644 commands/entertainment/decrypt.py create mode 100644 commands/entertainment/encrypt.py create mode 100644 commands/music/join.py create mode 100644 commands/music/leave.py create mode 100644 commands/music/stop.py diff --git a/commands/entertainment/decrypt.py b/commands/entertainment/decrypt.py new file mode 100644 index 0000000..9805f91 --- /dev/null +++ b/commands/entertainment/decrypt.py @@ -0,0 +1,47 @@ +# Modules +import base64 +import discord + +from assets.prism import Tools +from discord.ext import commands + +# Main Command Class +class Decrypt(commands.Cog): + + def __init__(self, bot): + self.bot = bot + self.desc = "Decrypt some text using the base64 format." + self.usage = "decrypt [text]" + + @commands.command() + async def decrypt(self, ctx, *, text: str = None): + + if not text: + + return await ctx.send(embed = Tools.error("No text specified to decrypt.")) + + try: + + encrypted = base64.b64decode(text.encode("ascii")).decode("ascii") + + except: + + return await ctx.send(embed = Tools.error("Sorry, your text couldn't be decrypted.")) + + embed = discord.Embed(title = "Decryption Results", description = f"```\n{encrypted}\n```", color = 0x126bf1) + + embed.set_author(name = " | Decrypt", icon_url = self.bot.user.avatar_url) + + embed.set_footer(text = f" | Requested by {ctx.author}.", icon_url = ctx.author.avatar_url) + + try: + + return await ctx.send(embed = embed) + + except: + + return await ctx.send(embed = Tools.error("Failed to send the embed, check your text.")) + +# Link to bot +def setup(bot): + bot.add_cog(Decrypt(bot)) diff --git a/commands/entertainment/encrypt.py b/commands/entertainment/encrypt.py new file mode 100644 index 0000000..30a1f3d --- /dev/null +++ b/commands/entertainment/encrypt.py @@ -0,0 +1,51 @@ +# Modules +import base64 +import discord + +from assets.prism import Tools +from discord.ext import commands + +# Main Command Class +class Encrypt(commands.Cog): + + def __init__(self, bot): + self.bot = bot + self.desc = "Encrypts some text using the base64 format." + self.usage = "encrypt [text]" + + @commands.command() + async def encrypt(self, ctx, *, text: str = None): + + if not text: + + return await ctx.send(embed = Tools.error("No text specified to encrypt.")) + + elif len(text) > 200: + + return await ctx.send(embed = Tools.error("Text is too long, it should be 200 at max.")) + + try: + + encrypted = base64.b64encode(text.encode("ascii")).decode("ascii") + + except: + + return await ctx.send(embed = Tools.error("Sorry, your text couldn't be encrypted.")) + + embed = discord.Embed(title = "Encryption Results", description = f"```\n{encrypted}\n```", color = 0x126bf1) + + embed.set_author(name = " | Encrypt", icon_url = self.bot.user.avatar_url) + + embed.set_footer(text = f" | Requested by {ctx.author}.", icon_url = ctx.author.avatar_url) + + try: + + return await ctx.send(embed = embed) + + except: + + return await ctx.send(embed = Tools.error("Failed to send the embed, check your text.")) + +# Link to bot +def setup(bot): + bot.add_cog(Encrypt(bot)) diff --git a/commands/misc/bio.py b/commands/misc/bio.py index 15816ab..e3e1ea9 100644 --- a/commands/misc/bio.py +++ b/commands/misc/bio.py @@ -20,9 +20,9 @@ async def biography(self, ctx, *, bio: str = None): return await ctx.send(embed = Tools.error("Please specify a biography.")) - elif len(bio) > 200: + elif len(bio) > 40: - return await ctx.send(embed = Tools.error("You're biography is way too long.")) + return await ctx.send(embed = Tools.error("You're biography is way too long (40 characters max).")) db = json.loads(open("db/users", "r").read()) diff --git a/commands/misc/card.py b/commands/misc/card.py index 98e9b13..4f41615 100644 --- a/commands/misc/card.py +++ b/commands/misc/card.py @@ -46,9 +46,11 @@ def font(size, font = "Thin"): draw.text((450, 10), f"{ctx.author.name}#{ctx.author.discriminator}", font = font(200, "Regular"), fill = (255, 255, 255)) - draw.line((0, 425) + (3000, 425), fill = (255, 255, 255)) + draw.line((10, 425) + (3000, 425), fill = (255, 255, 255), width = 10) - draw.text((450, 225), f"Level {user['data']['levels']['level']}", font = font(150), fill = (255, 255, 255)) + draw.text((450, 225), f"Level {user['data']['levels']['level']}", font = font(150), fill = (225, 225, 225)) + + draw.text((10, 450), f"\"{user['data']['bio']}\"", font = font(125), fill = (255, 255, 255)) # Package the image imgByteArr = BytesIO() diff --git a/commands/music/join.py b/commands/music/join.py new file mode 100644 index 0000000..7b38150 --- /dev/null +++ b/commands/music/join.py @@ -0,0 +1,38 @@ +# Modules +import discord +from assets.prism import Tools + +from discord.ext import commands + +# Main Command Class +class Join(commands.Cog): + + def __init__(self, bot): + self.bot = bot + self.desc = "Connects to your voice channel." + self.usage = "join" + + @commands.command(aliases = ["connect"]) + async def join(self, ctx): + + if not ctx.author.voice: + + return await ctx.send(embed = Tools.error("You aren't in a voice channel.")) + + voice = discord.utils.get(self.bot.voice_clients, guild = ctx.guild) + + if voice: + + await voice.move_to(ctx.author.voice.channel) + + return await ctx.send(embed = discord.Embed(description = f":wave: **Moved to #{ctx.author.voice.channel.name}.**", color = 0x126bf1)) + + else: + + await ctx.author.voice.channel.connect() + + return await ctx.send(embed = discord.Embed(description = f":wave: **Connected to #{ctx.author.voice.channel.name}.**", color = 0x126bf1)) + +# Link to bot +def setup(bot): + bot.add_cog(Join(bot)) diff --git a/commands/music/leave.py b/commands/music/leave.py new file mode 100644 index 0000000..058cad0 --- /dev/null +++ b/commands/music/leave.py @@ -0,0 +1,44 @@ +# Modules +import discord +from assets.prism import Tools + +from discord.ext import commands + +# Main Command Class +class Leave(commands.Cog): + + def __init__(self, bot): + self.bot = bot + self.desc = "Makes Prism leave your voice channel." + self.usage = "leave" + + @commands.command(aliases = ["disconnect", "dsc", "fuckoff"]) + async def leave(self, ctx): + + if not ctx.author.voice: + + return await ctx.send(embed = Tools.error("You aren't in a voice channel.")) + + voice = discord.utils.get(self.bot.voice_clients, guild = ctx.guild) + + if not voice: + + return await ctx.send(embed = Tools.error("Prism isn't in a voice channel.")) + + elif voice.is_playing(): + + try: + + voice.stop() + + except: + + pass + + await voice.disconnect() + + return await ctx.send(embed = discord.Embed(description = f":wave: **Left the voice channel.**", color = 0x126bf1)) + +# Link to bot +def setup(bot): + bot.add_cog(Leave(bot)) diff --git a/commands/music/play.py b/commands/music/play.py index c0fe790..d1e7a2c 100644 --- a/commands/music/play.py +++ b/commands/music/play.py @@ -30,6 +30,10 @@ async def play(self, ctx, url: str = None): voice = await ctx.author.voice.channel.connect() + elif voice.is_playing(): + + voice.stop() + with youtube_dl.YoutubeDL({}) as ytdl: info = ytdl.extract_info(url, download = False) @@ -40,7 +44,11 @@ async def play(self, ctx, url: str = None): voice.source.volume = 1 - return await ctx.send(embed = discord.Embed(description = f":musical_note: **Now playing: {info['title']}**", color = 0x126bf1)) + embed = discord.Embed(description = f":musical_note: **Now playing: {info['title']}**", color = 0x126bf1) + + embed.set_footer(text = " | Please note: music is experimental, freezing may occur.", icon_url = ctx.author.avatar_url) + + return await ctx.send(embed = embed) # Link to bot def setup(bot): diff --git a/commands/music/stop.py b/commands/music/stop.py new file mode 100644 index 0000000..1495f39 --- /dev/null +++ b/commands/music/stop.py @@ -0,0 +1,44 @@ +# Modules +import discord + +from assets.prism import Tools +from discord.ext import commands + +# Main Command Class +class Stop(commands.Cog): + + def __init__(self, bot): + self.bot = bot + self.desc = "Stops playing music in your voice channel." + self.usage = "stop" + + @commands.command() + async def stop(self, ctx): + + if not ctx.author.voice: + + return await ctx.send(embed = Tools.error("You aren't in a voice channel.")) + + voice = discord.utils.get(self.bot.voice_clients, guild = ctx.guild) + + if not voice: + + return await ctx.send(embed = Tools.error("Prism isn't in a voice channel.")) + + elif not voice.is_playing(): + + return await ctx.send(embed = Tools.error("No music is currently playing.")) + + try: + + voice.stop() + + except: + + return await ctx.send(embed = Tools.error("Something went wrong while stopping.")) + + return await ctx.send(embed = discord.Embed(description = f":x: **Playback stopped.**", color = 0x126bf1)) + +# Link to bot +def setup(bot): + bot.add_cog(Stop(bot))