dgw/sopel-duel

Trim nick passed to .duel

Closed this issue · 3 comments

dgw commented

The following example shows the issue with failing to sanitize the nickname passed to .duel:

<dgw> ;duel DHMO++
<Kaede> dgw has increased DHMO's reputation score to 94
<Kaede> You can't duel people who don't exist!

+, for example, is not a valid character in nicknames, and should be ignored.

The other issue is that this means users can duel using actions (see #35) while simultaneously increasing their target's reputation via the rep module, but cannot use the .duel command to achieve the same goal.

A stretch objective for resolving this is to also handle -- suffixes in addition to ++. That's trickier because - is a valid character in nicknames, so there's probably some presence-checking logic required to handle that. (If it turns out to be more work than I'm willing to do before fixing the ++ issue, it'll get punted to a separate ticket.)

dgw commented

This is actually easier than I thought it would be, based on tests. I can just import sopel-rep's validation function and use it as a filter if available. Whether I should rewrite the rep module to be properly encapsulated before implementing that method is another matter…

dgw commented

Glad I left the implementation of this in testing for long enough to catch an issue: The external validation function returns None if it can't extract a valid nick from the passed-in string, which causes issues with the if target == bot.nick check (AttributeError: 'NoneType' object has no attribute 'lower') due to the way Sopel overrides comparisons with Identifier objects.

Solution is probably modifying sopel-rep to return '' instead of None, because returning a string (even if it's empty) makes more sense and is still False-y.

dgw commented

So, importing verified_nick from sopel-rep wasn't really a good solution. It doesn't work properly in all cases, depending on import order and placement of files.

Long-term solution would be to convert my plugins into PyPI packages, but the kludge will be to copy-paste the function into sopel-duel so it works.