-
-
Save tamoot/29009a89dbcf184b2e51a19c5b7f3ea5 to your computer and use it in GitHub Desktop.
Hubot script: Utility commands for voting someone.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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