odin-bot-v2 icon indicating copy to clipboard operation
odin-bot-v2 copied to clipboard

Points: Also support prefix increments

Open Asartea opened this issue 1 year ago • 3 comments

Complete the following REQUIRED checkboxes:

  • [x] I have thoroughly read and understand The Odin Project Contributing Guide

  • [x] The title of this issue follows the command name: brief description of request format, e.g. /help: add optional @user parameter

The following checkbox is OPTIONAL:

  • [ ] I would like to be assigned this issue to work on it

1. Description of the Feature Request:

Sometimes people use the wrong form of increment (++prefix rather than postfix++), when trying to give someone points, which doesn't work. It would be neat if this also worked

2. Acceptance Criteria:

  • [ ] ++@example works the same as @example++

3. Additional Information:

Asartea avatar Oct 01 '23 18:10 Asartea

That sounds cool, I'm not sure how much more complicated it will make the points regex

https://github.com/TheOdinProject/odin-bot-v2/blob/38609779485aa540ffba0eb23be7233128020379/botCommands/points.js#L111

@TheOdinProject/maintainers what do we think?

01zulfi avatar Feb 24 '24 13:02 01zulfi

Instead of using each of the different points regex individually in the awardPoints.regex, we could create a new variable so that the "main" regex isn't as long:

const starRegex...
const plusRegex...
const doublePointsPlusRegex...

const givePointsRegex = `(${doublePointsPlusRegex}|${plusRegex}|${starRegex})`

Then just check whether for "userRegex followed by givePointsRegex | givePointsRegex followed by userRegex". Doesn't really make it less complicated, but maybe a little easier to read?

`(?<!\\S)(${userRegex}\\s?${givePointsRegex}|${givePointsRegex}\\s?${userRegex})(?!\\S)`

thatblindgeye avatar Feb 24 '24 13:02 thatblindgeye

The above sounds very reasonable. I like the idea of supporting pre-increment.

MaoShizhong avatar Aug 08 '24 14:08 MaoShizhong

I'm no longer sure on whether it's worth implementing this, as the following situation could occur:

@name ++ @name ++

We would need to make sure that only 2 point events are triggered from postfix and for the first ++ to not trigger an extra point for the second mention.

Similarly with @name ++ @name we would need to decide whether post or prefix is used but not both.

While we can implement that (with added complexity), I'd rather not have a situation where a discord user gives someone a point then mentions another person (or vice versa) and accidentally gives the wrong person a point. While prefix increment is neat, I think it can be a little less practical. I think it creates enough opportunities for user error. Thoughts?

MaoShizhong avatar Sep 27 '24 14:09 MaoShizhong