From a8d1fbd5484ce8acd616a9a278b1223f24a5abb0 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sun, 27 Jun 2021 18:53:07 -0600 Subject: [PATCH] Encode/decode support --- jarvis/cogs/dev.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/jarvis/cogs/dev.py b/jarvis/cogs/dev.py index 7c014f7..570c690 100644 --- a/jarvis/cogs/dev.py +++ b/jarvis/cogs/dev.py @@ -3,6 +3,7 @@ import hashlib import uuid import re import ulid +import base64 from discord.ext import commands from jarvis.utils import build_embed, convert_bytesize from jarvis.utils.field import Field @@ -149,6 +150,68 @@ class DevCog(commands.Cog): else: await ctx.send("Invalid ULID.") + @commands.group(name="encode") + async def _encode(self, ctx): + """Encodes text with specified encoding method""" + if ctx.invoked_subcommand is None: + await ctx.send("Usage: encode ") + + @_encode.command(name="b64e") + async def _b64e(self, ctx, *, data: str): + """Base64 encoding""" + await ctx.send(base64.b64encode(data.encode("UTF-8")).decode("UTF-8")) + + @_encode.command(name="b16e") + async def _b16e(self, ctx, *, data: str): + """Base16 encoding""" + await ctx.send(base64.b16encode(data.encode("UTF-8")).decode("UTF-8")) + + @_encode.command(name="b32e") + async def _b32e(self, ctx, *, data: str): + """Base32 encoding""" + await ctx.send(base64.b32encode(data.encode("UTF-8")).decode("UTF-8")) + + @_encode.command(name="a85e") + async def _a85e(self, ctx, *, data: str): + """ASCII85 encoding""" + await ctx.send(base64.a85encode(data.encode("UTF-8")).decode("UTF-8")) + + @_encode.command(name="b85e") + async def _b85e(self, ctx, *, data: str): + """Base85 encoding""" + await ctx.send(base64.b85encode(data.encode("UTF-8")).decode("UTF-8")) + + @commands.group() + async def _decode(self, ctx): + """Decodes text with specified encoding method""" + if ctx.invoked_subcommand is None: + await ctx.send("Usage: decode ") + + @_decode.command(name="b64d") + async def _b64d(self, ctx, *, data: str): + """Base64 decoding""" + await ctx.send(base64.b64decode(data.encode("UTF-8")).decode("UTF-8")) + + @_decode.command(name="b16d") + async def _b16d(self, ctx, *, data: str): + """Base16 decoding""" + await ctx.send(base64.b16decode(data.encode("UTF-8")).decode("UTF-8")) + + @_decode.command(name="b32d") + async def _b32d(self, ctx, *, data: str): + """Base32 decoding""" + await ctx.send(base64.b32decode(data.encode("UTF-8")).decode("UTF-8")) + + @_decode.command(name="a85d") + async def _a85d(self, ctx, *, data: str): + """ASCII85 decoding""" + await ctx.send(base64.a85decode(data.encode("UTF-8")).decode("UTF-8")) + + @_decode.command(name="b85d") + async def _b85d(self, ctx, *, data: str): + """Base85 decoding""" + await ctx.send(base64.b85decode(data.encode("UTF-8")).decode("UTF-8")) + def setup(bot): bot.add_cog(DevCog(bot))