Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add game channel regex function #135

Closed
wants to merge 39 commits into from
Closed

add game channel regex function #135

wants to merge 39 commits into from

Conversation

maishams
Copy link
Contributor

@maishams maishams commented Feb 7, 2019

instead of having to run the :level command, it will look for 'lvl' or 'level' in a message, and then show the level thing instead. it also checks it against what channel it was sent in, so person wont have to specify what base. i tried it on a private server, and it assigned the variables well.

instead of having to run the :level command, it will look for 'lvl' or 'level' in a message, and then show the level thing instead. it also checks it against what channel it was sent in, so person wont have to specify what base. i tried it on a private server, and it assigned the variables well.
@jerbob
Copy link
Member

jerbob commented Feb 7, 2019

Take a look at the Travis build errors and fix the flake8 issues

jerbob and others added 3 commits February 7, 2019 23:06
i removed a few whitespaces, added some and added
async def on_message(self, message: Message):
@maishams maishams closed this Feb 7, 2019
@thebeanogamer thebeanogamer reopened this Feb 7, 2019
@maishams maishams closed this Feb 7, 2019
@maishams maishams reopened this Feb 7, 2019
@maishams maishams closed this Feb 7, 2019
@maishams maishams reopened this Feb 7, 2019
removed/added whitespace and 
took ':Message' out of 'async def on_message(self, message: Message): '
plswork
took 'self' out of 'async def on_message(self, message):'
plswork
bot/cogs/cyber.py Outdated Show resolved Hide resolved
bot/cogs/cyber.py Outdated Show resolved Hide resolved
Copy link
Contributor

@joker314 joker314 left a comment

Choose a reason for hiding this comment

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

Thank you very much for the contribution. I love the idea, and thank you for going ahead and implementing it!

There are a few little problems with this pull request, though, and I'll just list them here to be helpful.

You've created an on_message function, but there's already a function with that name on line 341 (323 before your changes). Python will only remember one of them, so the other one's functionality will be removed. Instead of defining the function again, try adding your changes to the existing function.

In addition to that, here are some other issues (again, quite minor and shouldn't take too long to remedy -- but if you need help, please ask!):


EDIT: You added a commit before I had a chance to finish writing my review; so everything's going to look a little out of order on GitHub -- and some things will be marked as "outdated" and collapsed when they're still relevant, but all my comments are still there and if you need help or don't understand what I'm saying do ask!

plswork
moved my actual function down to the bottom with all the other regex functions
fixed the match error
bot/cogs/cyber.py Outdated Show resolved Hide resolved
added a space after #
added 2 blank lines after my code
bot/cogs/cyber.py Outdated Show resolved Hide resolved
bot/cogs/cyber.py Outdated Show resolved Hide resolved
bot/cogs/cyber.py Outdated Show resolved Hide resolved
Copy link
Contributor

@joker314 joker314 left a comment

Choose a reason for hiding this comment

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

Thank you for making the changes. I'm really glad it's passing now and it's awesome that it is! I just wanted to note down some minor improvements that aren't required but just some notes for discussion. This pull request can be merged even without these changes, of course.

as suggested by joker314
i think this is it
will shortly modify my actual code
@CyberDiscovery CyberDiscovery deleted a comment Feb 9, 2019
bot/constants.py Show resolved Hide resolved
Co-Authored-By: maishams <43148755+maishams@users.noreply.github.com>
@CyberDiscovery CyberDiscovery deleted a comment Feb 9, 2019
@CyberDiscovery CyberDiscovery deleted a comment Feb 9, 2019
@CyberDiscovery CyberDiscovery deleted a comment Feb 10, 2019
Copy link
Member

@teamshortcut teamshortcut left a comment

Choose a reason for hiding this comment

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

I will check with other staff before approving this, as it could be somewhat intrusive to people trying to discuss the challenges. However, slight changes notwithstanding, good work.

bot/cogs/cyber.py Outdated Show resolved Hide resolved
bot/cogs/cyber.py Show resolved Hide resolved
@teamshortcut
Copy link
Member

Oh, and the regex should probably catch alternate notation; so 13 1 (covered), 13.1, L13C1, l13c1, so on.

@CyberDiscovery CyberDiscovery deleted a comment Feb 10, 2019
@teamshortcut
Copy link
Member

It may be helpful if the regex only fired if the message were along the lines of "can I have a hint on..." or "I need some help on..." to avoid it popping up too much and obstructing discussion.

@skiros-habib
Copy link
Contributor

skiros-habib commented Feb 11, 2019

Change the regex to
^(le?ve?l)?\b.*?(\d{1,2}).*?(\d{1,2})\b.*$
image
image
image

Copy link
Contributor

@skiros-habib skiros-habib left a comment

Choose a reason for hiding this comment

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

updated regex

bot/cogs/cyber.py Outdated Show resolved Hide resolved
Co-Authored-By: maishams <43148755+maishams@users.noreply.github.com>
@CyberDiscovery CyberDiscovery deleted a comment Feb 12, 2019
@jerbob jerbob dismissed teamshortcut’s stale review February 12, 2019 18:59

Changes have been addressed.

Copy link
Contributor

@joker314 joker314 left a comment

Choose a reason for hiding this comment

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

I think we should discuss the regular expression in a little more detail. A brief overview of my issues are:

  • Matches words beginning with "L" even if they aren't related to levels
  • Does not match unless at the beginning of line
  • Matches "Lev X Y" and "LL X Y" even though these aren't typical abbreviations (although this is difficult... because I can't really imagine a context where this would be used and not refer to a level. Let me know what you think)
  • Matches "Level XY" despite this notation being ambiguous and prone to false-positives

I really like everything in general, these are just tiny nit-picks!

@@ -63,6 +63,10 @@ def __init__(self, bot: Bot):
r"^.*\bwhat\b.*\belite\b.*\bemail\b.*$",
re.IGNORECASE
)
self.game_level_regex = re.compile(
r"^(le?v?e?l?).*?(\d{1,2}).*?(\d{1,2})\b.*$",
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, so this regular expression has changed a lot. It matches this, which I think it shouldn't:

Lol, remember the 2018 intake?

:level 20 18

This would maybe be acceptable, but in addition, the command will report out-of-range errors back to the user, in the form of a spammy message. We need to suppress these error messages if the command was invoked via this pattern match rather than a direct invocation of the command.

iThe bot replies with "Invalid challenge number!" if asked for level 20 19


I think, also, in 5451798 we accidentally removed the .* prefixing the pattern for "level". This is bad because you can no longer use inline phrases like

I'm struggling with level 4.3

Maybe we ought to remove the ^ anchor at the beginning of the match, as that seems more readable than adding a .*.

Also, notice that "Lol" matches. This probably isn't a good idea. Maybe we should only match "L" on its own. "Lev" probably shouldn't be matched either, but "lvl" and "level" should be.

This change will resolve some of the above:


Also, "2019" shouldn't match. There should be a digit-boundary between each number, so that "20 19" is okay, but three-digit numbers should not work.

Here is a regular expression to consolidate the above requests:

Suggested change
r"^(le?v?e?l?).*?(\d{1,2}).*?(\d{1,2})\b.*$",
r"(le?v?e?l|l(?=\b|\d))\D*(\d{1,2})\D+(\d{1,2})\b.*$",

Matches

  • LxCy
  • lvl x y
  • lvl x.y
  • levl x y
  • lvel x y
  • level x y
  • lvl x challenge y

Does not match:

  • lev x y
  • love x y
  • level xy
  • level 01 04 (note leading zeros)

We should maybe consider allowing the last one.


Additionally, you use a capturing group to match for "level". I haven't changed it here because it would require changing some of your other code, but you never use this result so maybe we should use a non-capturing group (?:...) so as to only match what we need.


I really like how this has all turned out and am open to thoughts on the above!

Copy link
Contributor

@joker314 joker314 left a comment

Choose a reason for hiding this comment

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

EDIT: Accidental double-review

Copy link
Contributor

@skiros-habib skiros-habib left a comment

Choose a reason for hiding this comment

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

A slightly less hacky way of invoking the command, still kind of bad that the command has to be invoked, ideally wanting the code to just be ran.

bot/cogs/cyber.py Outdated Show resolved Hide resolved
bot/cogs/cyber.py Outdated Show resolved Hide resolved
bot/cogs/cyber.py Outdated Show resolved Hide resolved
skiros-habib and others added 3 commits February 15, 2019 20:26
Co-Authored-By: maishams <43148755+maishams@users.noreply.github.com>
Co-Authored-By: maishams <43148755+maishams@users.noreply.github.com>
Co-Authored-By: maishams <43148755+maishams@users.noreply.github.com>
@jerbob
Copy link
Member

jerbob commented Mar 15, 2019

As a heads up @maishams @justanotherfailure, I'm going to be closing this soon if merge conflicts aren't resolved. The PR has been open for over a month.

@maishams maishams closed this Mar 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants