diff --git a/README.md b/README.md index 358323a..e9722ed 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,17 @@ If you would like business jargon triggers that are not in the plugin, [pull req HUBOT_BUSINESS_CAT_JARGON='more,jargon,ideat(e|ion)' HUBOT_BUSINESS_CAT_OMITTED_JARGON='in the loop,takeaway' ``` + +If you think business cat triggers too often, you can also reduce the probability of a response by setting the variable HUBOT_BUSINESS_CAT_FREQUENCY to a positive integer value, giving a one-in-HUBOT_BUSINESS_CAT_FREQUENCY chance of replying. if not set, this defaults to the existing 100% chance of a response. +``` +# a 50% chance of responding: (one of two) +HUBOT_BUSINESS_CAT_FREQUENCY=2 +``` +``` +# a 25% chance of responding: (one in four) +HUBOT_BUSINESS_CAT_FREQUENCY=4 +``` +``` +# a 1% chance of responding: (one in one-hundred) +HUBOT_BUSINESS_CAT_FREQUENCY=100 +``` \ No newline at end of file diff --git a/src/businesscat.coffee b/src/businesscat.coffee index e3f1931..4b2b6f1 100644 --- a/src/businesscat.coffee +++ b/src/businesscat.coffee @@ -34,10 +34,17 @@ if process.env.HUBOT_BUSINESS_CAT_OMITTED_JARGON? omittedJargon = (process.env.HUBOT_BUSINESS_CAT_OMITTED_JARGON).split(',') jargon = removeTerm(term, jargon) for term in omittedJargon +if process.env.HUBOT_BUSINESS_CAT_FREQUENCY? > 0 + frequency = Math.floor(process.env.HUBOT_BUSINESS_CAT_OMITTED_JARGON) +else + frequency = 1 + regex = new RegExp jargon.join('|'), 'gi' exports = module.exports = (robot) -> robot.hear regex, (msg) -> - msg.send msg.random images + if !(Math.floor(Math.random() * frequency))) + msg.send msg.random images exports.removeTerm = removeTerm + diff --git a/test/businesscat_test.coffee b/test/businesscat_test.coffee index bbf6098..2429881 100644 --- a/test/businesscat_test.coffee +++ b/test/businesscat_test.coffee @@ -17,6 +17,7 @@ describe 'hubot-business-cat', -> afterEach -> delete process.env.HUBOT_BUSINESS_CAT_JARGON delete process.env.HUBOT_BUSINESS_CAT_OMITTED_JARGON + delete process.env.HUBOT_BUSINESS_CAT_FREQUENCY it 'does register a hear listener', -> expect(@robot.hear).to.have.been.calledWithMatch sinon.match( (val) ->