Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Join, Leave, Stop & De/Encrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin O'Brien committed Oct 4, 2020
1 parent 0f22814 commit 7ccf2be
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 5 deletions.
47 changes: 47 additions & 0 deletions commands/entertainment/decrypt.py
Original file line number Diff line number Diff line change
@@ -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))
51 changes: 51 additions & 0 deletions commands/entertainment/encrypt.py
Original file line number Diff line number Diff line change
@@ -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))
4 changes: 2 additions & 2 deletions commands/misc/bio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
6 changes: 4 additions & 2 deletions commands/misc/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
38 changes: 38 additions & 0 deletions commands/music/join.py
Original file line number Diff line number Diff line change
@@ -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))
44 changes: 44 additions & 0 deletions commands/music/leave.py
Original file line number Diff line number Diff line change
@@ -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))
10 changes: 9 additions & 1 deletion commands/music/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
44 changes: 44 additions & 0 deletions commands/music/stop.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 7ccf2be

Please sign in to comment.