hubot-scorekeeper icon indicating copy to clipboard operation
hubot-scorekeeper copied to clipboard

Improvement: Multiple detection and Remove an user

Open pachirel opened this issue 9 years ago • 2 comments

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

pachirel avatar Aug 28 '15 09:08 pachirel

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)"

yoshiori avatar Aug 31 '15 06:08 yoshiori

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.

pachirel avatar Sep 01 '15 04:09 pachirel