Skip to content

Instantly share code, notes, and snippets.

@tamoot
Forked from moomindani/vote.coffee
Last active June 14, 2017 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamoot/29009a89dbcf184b2e51a19c5b7f3ea5 to your computer and use it in GitHub Desktop.
Save tamoot/29009a89dbcf184b2e51a19c5b7f3ea5 to your computer and use it in GitHub Desktop.
Hubot script: Utility commands for voting someone.
# Description:
# Utility commands for voting someone.
#
# Commands:
# <name>++, <name>--, !vote-list, !vote-clear
module.exports = (robot) ->
KEY_SCORE = 'key_score'
getScores = () ->
return robot.brain.get(KEY_SCORE) or {}
changeScore = (name, diff) ->
source = getScores()
score = source[name] or 0
new_score = score + diff
source[name] = new_score
robot.brain.set KEY_SCORE, source
return new_score
robot.hear /!vote-list/i, (msg) ->
source = getScores()
console.log source
msg.send """
### vote result :bar_chart:
"""
for name, score of source
msg.send """
#{name}:\t#{score}
"""
robot.hear /!vote-clear/i, (msg) ->
robot.brain.set KEY_SCORE, null
robot.hear /(.+)\+\+$/i, (msg) ->
name = msg.match[1]
new_score = changeScore(name, 1)
msg.send "Accepted -> #{name}: #{new_score} :chart_with_upwards_trend:"
robot.hear /(.+)--$/i, (msg) ->
name = msg.match[1]
new_score = changeScore(name, -1)
msg.send "Accepted -> #{name}: #{new_score} :chart_with_downwards_trend:"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment