Skip to content

Commit

Permalink
feat(hubot-shinchoku): Add REACTION_MODE
Browse files Browse the repository at this point in the history
  • Loading branch information
moqada committed Jun 7, 2018
1 parent d376d86 commit 38c26d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
2. "hubot-shinchoku" を external-scripts.json に追加
4. Reboot Hubot

## Configuration:

**HUBOT_SHINCHOKU_REACTION_MODE**

メッセージへの反応形式を設定する。

- `respond`: mentionのキーワードにのみ反応する
- `hear`: 会話中全てのキーワードに反応する (default)

## Commands

```
Expand Down
11 changes: 10 additions & 1 deletion src/scripts/shinchoku.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@
request = require 'request'
cheerio = require 'cheerio'

pattern = /(shinchoku|進捗)/i
reactionMode = process.env.HUBOT_SHINCHOKU_REACTION_MODE or 'hear'
url = 'http://shinchokudodesuka.tumblr.com/random'
retries = 3

module.exports = (robot) ->
robot.hear /(shinchoku|進捗)/i, (msg) ->
if reactionMode is 'respond'
robot.respond pattern, (msg) ->
sendImage msg
else
robot.hear pattern, (msg) ->
sendImage msg

sendImage = (msg) ->
post_shinchoku = (retry_left) ->
request url: url, (err, res, body) ->
$ = cheerio.load body
Expand Down

0 comments on commit 38c26d7

Please sign in to comment.