Catch encoding errors

This commit is contained in:
Zeva Rose 2022-03-25 12:48:44 -06:00
parent 02d50180f1
commit 38b86d4694

View file

@ -207,7 +207,11 @@ class DevCog(Scale):
async def _encode(self, ctx: InteractionContext, method: str, data: str) -> None:
mstr = method
method = getattr(base64, method + "encode")
encoded = method(data.encode("UTF-8")).decode("UTF-8")
try:
encoded = method(data.encode("UTF-8")).decode("UTF-8")
except Exception as e:
await ctx.send(f"Failed to encode data: {e}")
return
fields = [
EmbedField(name="Plaintext", value=f"`{data}`", inline=False),
EmbedField(name=mstr, value=f"`{encoded}`", inline=False),
@ -232,7 +236,11 @@ class DevCog(Scale):
async def _decode(self, ctx: InteractionContext, method: str, data: str) -> None:
mstr = method
method = getattr(base64, method + "decode")
decoded = method(data.encode("UTF-8")).decode("UTF-8")
try:
decoded = method(data.encode("UTF-8")).decode("UTF-8")
except Exception as e:
await ctx.send(f"Failed to decode data: {e}")
return
if invites.search(decoded):
await ctx.send(
"Please don't use this to bypass invite restrictions",