TheOdinProject / odin-bot-v2

The bot that breathes life into our Discord community
ISC License
46 stars 76 forks source link

Points: Also support prefix increments #441

Open Asartea opened 11 months ago

Asartea commented 11 months ago

Complete the following REQUIRED checkboxes:

The following checkbox is OPTIONAL:


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:

3. Additional Information:

01zulfi commented 6 months ago

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?

thatblindgeye commented 6 months ago

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)`
MaoShizhong commented 1 month ago

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