From a7a92f5b51be22e7c0ff06cb0d466b2d0ba9ddb7 Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 22 Jan 2020 21:22:20 +0100 Subject: [PATCH] Added encryption --- cogs/fun/encryption.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 cogs/fun/encryption.py diff --git a/cogs/fun/encryption.py b/cogs/fun/encryption.py new file mode 100644 index 0000000..fa91450 --- /dev/null +++ b/cogs/fun/encryption.py @@ -0,0 +1,34 @@ +import discord +from discord.ext import commands +from util import embed + +class Encryption(commands.Cog): + def __init__(self, client: discord.Client): + self.client = client + + @commands.command(name="rot", description="Applies the ROT encryption", usage="rot [number] [message]") + @commands.cooldown(1, 2) + async def rot(self, ctx: commands.Context, shift: str, *message: str): + if not shift.isnumeric(): + await ctx.send(embed=embed.make_error_embed(f"{shift} is not a number.")) + return + + shift = int(shift) + if (shift < 1) or (shift > 25): + await ctx.send(embed=embed.make_error_embed("That's too much rotation. Stop it.")) + return + + old_message = list(' '.join(message)) + for i in range(0, len(old_message)): + if not old_message[i].isalpha(): + continue + + if old_message[i].isupper(): + old_message[i] = chr(ord('A') + ((ord(old_message[i]) + shift - ord('A')) % 26)) + else: + old_message[i] = chr(ord('a') + ((ord(old_message[i]) + shift - ord('a')) % 26)) + + await ctx.send(''.join(old_message)) + +def setup(client: discord.Client): + client.add_cog(Encryption(client)) \ No newline at end of file