hubot-scorekeeper
hubot-scorekeeper copied to clipboard
Improvement: Multiple detection and Remove an user
Multiple detection
Now we can increment multiple users at one line!
For example, this command will increment taro and hanako:
taro++, hanako++
,
This will add 3 points to taro:
taro++ taro++ taro++
And, this is just a joke:
taro-- taro++
Remove an user
When you mistyped name, now you can remove it.
tarp++
hubot scorekeeper remove tarp
Add remove function is ok.
Multiple increment/decrement in one line is cool! but IMO it lost readability.
Please change like this
robot.hear /(\w+)\+\+$/g, (msg) ->
for str in msg.match
user = userName(str)
scorekeeper.increment user, (error, result) ->
msg.send "incremented #{user} (#{result} pt)"
robot.hear /(\w+)\-\-$/g, (msg) ->
for str in msg.match
user = userName(str)
scorekeeper.decrement user, (error, result) ->
msg.send "decremented #{user} (#{result} pt)"
but IMO it lost readability.
Indeed.
But I can't work your example code correctly in my local environment.
Using global match, msg.match
returns entire matching string instead of captured string.
e.g. )When foo++
is coming, msg.match
doesn't return foo
, but foo++
.
And, when foo++ bar--
is passed, foo++
is ignored.
Anyway, I'm working to refactor my PR code better :dancer:
thanks.