Skip to content

Instantly share code, notes, and snippets.

@tamoot
Forked from moomindani/vote.coffee
Last active Jun 14, 2017
Embed
What would you like to do?
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