diff options
author | 2020-09-18 20:39:38 +0800 | |
---|---|---|
committer | 2020-09-18 20:47:58 +0800 | |
commit | d6b331080d57fb122eb63644382717f2fc4860c7 (patch) | |
tree | 65a9a7921add490e8fbc02fac9af44599a552a37 | |
parent | Make the encryption function top-level (diff) |
Refactor methods to use _get_text_and_embed
This changes the converters used by caesarcipher_encrypt and
caesarcipher_decrypt in order to accomodate for the manual conversion
that _get_text_and_embed does, which allows for this feature to be
easily disabled.
-rw-r--r-- | bot/exts/evergreen/fun.py | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 3fd0f275..8235d072 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -131,7 +131,7 @@ class Fun(Cog): await ctx.send(embed=embed) @staticmethod - async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str], left_shift: bool = False) -> None: + async def _caesar_cipher(ctx: Context, offset: int, msg: str, left_shift: bool = False) -> None: """ Given a positive integer `offset`, translates and sends the given `msg`. @@ -150,10 +150,7 @@ class Fun(Cog): """Encrypts the given string using the Caesar Cipher.""" return "".join(caesar_cipher(text, offset)) - is_message = isinstance(msg, Message) - - text = msg.content if is_message else msg - embed = msg.embeds[0] if is_message and msg.embeds else None + text, embed = await Fun._get_text_and_embed(ctx, msg) if embed is not None: embed = Fun._convert_embed(conversion_func, embed) @@ -166,7 +163,7 @@ class Fun(Cog): await ctx.send(content=converted_text, embed=embed) @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift", "enc",)) - async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: + async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: str) -> None: """ Given a positive integer `offset`, encrypt the given `msg`. @@ -177,7 +174,7 @@ class Fun(Cog): await self._caesar_cipher(ctx, offset, msg, left_shift=False) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift", "dec",)) - async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: + async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: str) -> None: """ Given a positive integer `offset`, decrypt the given `msg`. |