Catch encoding errors
This commit is contained in:
parent
02d50180f1
commit
38b86d4694
1 changed files with 10 additions and 2 deletions
|
@ -207,7 +207,11 @@ class DevCog(Scale):
|
||||||
async def _encode(self, ctx: InteractionContext, method: str, data: str) -> None:
|
async def _encode(self, ctx: InteractionContext, method: str, data: str) -> None:
|
||||||
mstr = method
|
mstr = method
|
||||||
method = getattr(base64, method + "encode")
|
method = getattr(base64, method + "encode")
|
||||||
|
try:
|
||||||
encoded = method(data.encode("UTF-8")).decode("UTF-8")
|
encoded = method(data.encode("UTF-8")).decode("UTF-8")
|
||||||
|
except Exception as e:
|
||||||
|
await ctx.send(f"Failed to encode data: {e}")
|
||||||
|
return
|
||||||
fields = [
|
fields = [
|
||||||
EmbedField(name="Plaintext", value=f"`{data}`", inline=False),
|
EmbedField(name="Plaintext", value=f"`{data}`", inline=False),
|
||||||
EmbedField(name=mstr, value=f"`{encoded}`", 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:
|
async def _decode(self, ctx: InteractionContext, method: str, data: str) -> None:
|
||||||
mstr = method
|
mstr = method
|
||||||
method = getattr(base64, method + "decode")
|
method = getattr(base64, method + "decode")
|
||||||
|
try:
|
||||||
decoded = method(data.encode("UTF-8")).decode("UTF-8")
|
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):
|
if invites.search(decoded):
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
"Please don't use this to bypass invite restrictions",
|
"Please don't use this to bypass invite restrictions",
|
||||||
|
|
Loading…
Add table
Reference in a new issue