Encode/decode support
This commit is contained in:
parent
5bd1e35e64
commit
a8d1fbd548
1 changed files with 63 additions and 0 deletions
|
@ -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 <method> <data>")
|
||||
|
||||
@_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 <method> <data>")
|
||||
|
||||
@_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))
|
||||
|
|
Loading…
Add table
Reference in a new issue