Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow any word to be used for points #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ robot.emit "plus-one", {

## Installation

Run the following command
Run the following command

$ npm install hubot-plusplus

Expand All @@ -46,3 +46,16 @@ To enable the script, add a `hubot-plusplus` entry to the `external-scripts.json
file (you may need to create this file).

["hubot-plusplus"]

## Configuration

You can optionally set the term used to points to another word if desired.

HUBOT_PLUSPLUS_POINT: the singular term, default 'point'
HUBOT_PLUSPLUS_POINTS: the plural term, default is the singular term with an 's' appended

For example, setting `HUBOT_PLUSPLUS_POINT=onion` would result in hubot responding with:

bruce: thing++
hubot: thing has 1 onion

22 changes: 13 additions & 9 deletions src/plusplus.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# "clark": "0.0.6"
#
# Configuration:
# HUBOT_PLUSPLUS_POINT: optional, use your own word for points, default: point
# HUBOT_PLUSPLUS_POINTS: optional, plural term for points, default HUBOT_PLUSPLUS_POINT + 's'
#
# Commands:
# <name>++
Expand All @@ -28,6 +30,8 @@ querystring = require('querystring')
ScoreKeeper = require('./scorekeeper')

module.exports = (robot) ->
point = process.env.HUBOT_PLUSPLUS_POINT or 'point'
points = process.env.HUBOT_PLUSPLUS_POINTS or "#{point}s"
scoreKeeper = new ScoreKeeper(robot)

# sweet regex bro
Expand Down Expand Up @@ -73,14 +77,14 @@ module.exports = (robot) ->
if score?
message = if reason?
if reasonScore == 1 or reasonScore == -1
"#{name} has #{score} points, #{reasonScore} of which is for #{reason}."
"#{name} has #{score} #{points}, #{reasonScore} of which is for #{reason}."
else
"#{name} has #{score} points, #{reasonScore} of which are for #{reason}."
"#{name} has #{score} #{points}, #{reasonScore} of which are for #{reason}."
else
if score == 1
"#{name} has #{score} point"
"#{name} has #{score} #{point}"
else
"#{name} has #{score} points"
"#{name} has #{score} #{points}"


msg.send message
Expand Down Expand Up @@ -124,7 +128,7 @@ module.exports = (robot) ->
message = if reason?
"Erased the following reason from #{name}: #{reason}"
else
"Erased points for #{name}"
"Erased #{points} for #{name}"
msg.send message

robot.respond /score (for\s)?(.*)/i, (msg) ->
Expand All @@ -133,12 +137,12 @@ module.exports = (robot) ->
reasons = scoreKeeper.reasonsForUser(name)

reasonString = if typeof reasons == 'object' && Object.keys(reasons).length > 0
"#{name} has #{score} points. here are some raisins:" +
"#{name} has #{score} #{points}. here are some raisins:" +
_.reduce(reasons, (memo, val, key) ->
memo += "\n#{key}: #{val} points"
memo += "\n#{key}: #{val} #{points}"
, "")
else
"#{name} has #{score} points."
"#{name} has #{score} #{points}."

msg.send reasonString

Expand All @@ -160,7 +164,7 @@ module.exports = (robot) ->

msg.send message.join("\n")

robot.router.get "/#{robot.name}/normalize-points", (req, res) ->
robot.router.get "/#{robot.name}/normalize-#{points}", (req, res) ->
scoreKeeper.normalize((score) ->
if score > 0
score = score - Math.ceil(score / 10)
Expand Down