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

Random delay #44

Open
wants to merge 4 commits into
base: main
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
9 changes: 8 additions & 1 deletion src/businesscat.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really cool @Gavitron but I think there's a typo here (extra ))... could you please update and I'll get this merged & shipped.

thanks!

msg.send msg.random images

exports.removeTerm = removeTerm

1 change: 1 addition & 0 deletions test/businesscat_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down