diff options
author | 2020-06-25 23:29:06 +0800 | |
---|---|---|
committer | 2020-06-26 01:50:18 +0800 | |
commit | 3260a16d78351fec2bab9ba6124e4a655fbd2e26 (patch) | |
tree | 3b9a82fb8c76f29c3a506d2e601ec2ddfadb1a0a /bot/exts/evergreen/fun.py | |
parent | Add basic caesar cipher information embed (diff) |
Refactor translate subcommand to encrypt and decrypt
Diffstat (limited to 'bot/exts/evergreen/fun.py')
-rw-r--r-- | bot/exts/evergreen/fun.py | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index f3e3bfcc..75b0e2b0 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -93,7 +93,7 @@ class Fun(Cog): """ Translates a message using the Caesar Cipher. - See `info` and `translate` subcommands. + See `decrpyt`, `encrypt`, and `info` subcommands. """ if ctx.invoked_subcommand is None: await self.bot.get_cog("Help").new_help(ctx, "caesarcipher") @@ -112,17 +112,17 @@ class Fun(Cog): await ctx.send(embed=embed) - @caesarcipher_group.command(name="translate") - async def caesarcipher_translate(self, ctx: Context, offset: int, *, text: str) -> None: + @staticmethod + async def _caesar_cipher(ctx: Context, offset: int, text: str) -> None: """ - Given an integer `offset`, translate the given `text`. + Given an integer `offset`, translates and sends the given `text`. - A positive `offset` will cause the letters to shift right, - while a negative `offset` will cause the letters to shift left. + A positive `offset` will cause the letters to shift right, while + a negative `offset` will cause the letters to shift left. - Also accepts a valid discord Message ID or link. + Also accepts a valid Discord Message ID or link. """ - def cipher_func(text: str) -> str: + def caesar_func(text: str) -> str: """Implements a lazy Caesar Cipher algorithm.""" for char in text: if not char.isascii() or not char.isalpha() or char.isspace(): @@ -133,7 +133,7 @@ class Fun(Cog): def conversion_func(text: str) -> str: """Encrypts the given string using the Caesar Cipher.""" - return "".join(cipher_func(text)) + return "".join(caesar_func(text)) text, embed = await Fun._get_text_and_embed(ctx, text) # Convert embed if it exists @@ -145,6 +145,28 @@ class Fun(Cog): converted_text = f">>> {converted_text.lstrip('> ')}" await ctx.send(content=converted_text, embed=embed) + @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift")) + async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, text: str) -> None: + """ + Given a positive integer `offset`, encrypt the given `text`. + + Performs a right shift of the letters in the message. + + Also accepts a valid Discord Message ID or link. + """ + await self._caesar_cipher(ctx, offset, text) + + @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) + async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, text: str) -> None: + """ + Given a positive integer `offset`, decrypt the given `text`. + + Performs a left shift of the letters in the message. + + Also accepts a valid Discord Message ID or link. + """ + await self._caesar_cipher(ctx, -offset, text) + @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: """ |