Skip to content

Caesar cipher command#421

Merged
kosayoda merged 21 commits into
python-discord:masterfrom
purefunctor:caesar-command
Sep 18, 2020
Merged

Caesar cipher command#421
kosayoda merged 21 commits into
python-discord:masterfrom
purefunctor:caesar-command

Conversation

@purefunctor
Copy link
Copy Markdown
Contributor

Relevant Issues

Closes #420.

Description

This adds a .caesarcipher command group with decrypt, encrypt, and info subcommands in the Fun cog. The decrypt and encrypt subcommands also support message IDs and links similarly to other Fun cog commands such as .uwu and .randomcase.

Reasoning

The decrypt and encrypt subcommands should provide a concise way of using the ciphering a message, with info adding good educational value to the feature.

Screenshots

image

Additional Details

In order to support message IDs and links for the command, the _caesar_cipher method was patterned against the uwu and random case commands. Maybe this feature can be abstracted to a generalized function to avoid redundancy/for future text-related commands as well?

Did you:

  • Join the Python Discord Community?
  • If dependencies have been added or updated, run pipenv lock?
  • Lint your code (pipenv run lint)?
  • Set the PR to allow edits from contributors?

@purefunctor purefunctor added type: feature Relating to the functionality of the application. season: evergreen labels Jun 25, 2020
@purefunctor purefunctor requested review from kosayoda and kwzrd June 25, 2020 18:02
@purefunctor purefunctor requested a review from a team as a code owner June 25, 2020 18:02
@purefunctor purefunctor self-assigned this Jun 25, 2020
Copy link
Copy Markdown
Contributor

@ks129 ks129 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick review without actual testing.

Comment thread bot/exts/evergreen/fun.py
Comment thread bot/exts/evergreen/fun.py Outdated
Comment thread bot/exts/evergreen/fun.py Outdated
Comment thread bot/exts/evergreen/fun.py Outdated
Copy link
Copy Markdown
Contributor

@kwzrd kwzrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and works fine apart from the path problem. I haven't looked at the actual shift algorithm you have implemented in much detail yet, but it looks interesting. Defining the resource dict such that an embed can be built from it directly is a really cool idea.

Comment thread bot/exts/evergreen/fun.py Outdated
Comment thread bot/resources/evergreen/caesar_info.json Outdated
@ghost ghost added the status: waiting for author Waiting for author to address a review or respond to a comment label Jun 27, 2020
@ghost ghost added needs 2 approvals and removed status: waiting for author Waiting for author to address a review or respond to a comment labels Jun 27, 2020
Comment thread bot/exts/evergreen/fun.py Outdated
Comment thread bot/exts/evergreen/fun.py Outdated
Copy link
Copy Markdown
Member

@Den4200 Den4200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It all looks good overall, but I have not tested this yet.

Comment thread bot/exts/evergreen/fun.py Outdated
Comment thread bot/exts/evergreen/fun.py Outdated
@ghost ghost added status: waiting for author Waiting for author to address a review or respond to a comment and removed needs 2 approvals labels Jun 29, 2020
@ghost ghost added needs 2 approvals and removed status: waiting for author Waiting for author to address a review or respond to a comment labels Jul 2, 2020
Comment thread bot/exts/evergreen/fun.py Outdated
@kwzrd kwzrd self-requested a review July 23, 2020 13:28
Comment thread bot/exts/evergreen/fun.py Outdated
@purefunctor purefunctor requested a review from kwzrd July 29, 2020 04:46
Comment thread bot/exts/evergreen/fun.py Outdated
Comment on lines +129 to +143
def caesar_func(text: str) -> Iterable[str]:
"""Implements a lazy Caesar Cipher algorithm."""
for char in text:
if not char.isascii() or not char.isalpha() or char.isspace():
yield char
continue

case_start = 65 if char.isupper() else 97
true_offset = (ord(char) - case_start + offset) % 26

yield chr(case_start + true_offset)

def conversion_func(text: str) -> str:
"""Encrypts the given string using the Caesar Cipher."""
return "".join(caesar_func(text))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why these are defined inside the command? From the look of it, you can move it outside as well to prevent them being defined everytime the command is run, declaring them as @staticmethod

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've initially decided to define these inside of the function to be consistent with the form of the other commands inside of the Fun cog. I could change them into @staticmethods but I'm not sure whether making them standalone top-level functions would avoid polluting the cog.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest moving them outside, in case we want to write unittests for these. Naming these with a _ in front of the name to signify that these are to be used internally might be able to help, otherwise you can always move them outside in their own class and just call it inside the Cog.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll go ahead and do that 👍

purefunctor and others added 4 commits September 18, 2020 20:36
This makes caesar_func a top-level function and renames it to
caesar_cipher.
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.
@kosayoda kosayoda merged commit 2e63318 into python-discord:master Sep 18, 2020
@purefunctor purefunctor deleted the caesar-command branch September 18, 2020 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Relating to the functionality of the application.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caesar cipher command

7 participants