From c75e057e7ff05d698e1afaa5fb4e7268f72fe29b Mon Sep 17 00:00:00 2001 From: Jak Spalding Date: Tue, 19 Jan 2016 14:51:24 +0000 Subject: [PATCH] allow any word to be used for points --- README.md | 15 ++++++++++++++- src/plusplus.coffee | 22 +++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1e4a6659..ed5b35fe 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ robot.emit "plus-one", { ## Installation -Run the following command +Run the following command $ npm install hubot-plusplus @@ -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 + diff --git a/src/plusplus.coffee b/src/plusplus.coffee index fb92fb44..fa4d50e1 100644 --- a/src/plusplus.coffee +++ b/src/plusplus.coffee @@ -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: # ++ @@ -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 @@ -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 @@ -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) -> @@ -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 @@ -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)