Skip to content

Commit

Permalink
Fix checkin members check
Browse files Browse the repository at this point in the history
  • Loading branch information
sailxjx committed Jan 29, 2016
1 parent 975c5cf commit 51fcdb4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions app.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
express = require 'express'
logger = require 'graceful-logger'
config = require 'config'
morgan = require 'morgan'
bodyParser = require 'body-parser'
app = express()

bot = require './src/bot'

app.use morgan()
app.use bodyParser.json(limit: '10mb')
app.use bodyParser.urlencoded(extended: true, limit: '10mb')

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"graceful-logger": "^0.4.3",
"lodash": "^4.0.1",
"moment": "^2.11.1",
"morgan": "^1.6.1",
"nedb": "^1.7.2",
"request": "^2.69.0"
}
Expand Down
16 changes: 6 additions & 10 deletions src/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ _sendCheckinSummary = ->
return unless bot.isActive()
return unless rules.members and config._targetId and config.webhookUrl
model.getCheckins().then (checkins) ->
_checkinIds = checkins.map (checkin) -> "#{checkin._creatorId}"
checkinNames = checkins.map (checkin) -> "#{checkin.name}"
nonCheckMembers = rules.members.filter (memberName) ->
return false if checkins._creatorId is memberName
return false if checkins.name.indexOf(memberName) > -1
return false if memberName in _checkinIds
return false if checkinNames.some (name) -> name?.indexOf(memberName) > -1
return true
if nonCheckMembers.length
msg = "#{nonCheckMembers.join('')} 这几个家伙还没签到,去哪儿啦?"
Expand Down Expand Up @@ -118,12 +120,6 @@ _sendCronData = (cronData) ->
when 'room' then message._roomId = config._targetId
else return false

console.log "Send message",
method: 'POST'
url: config.webhookUrl
json: true
body: message

requestAsync
method: 'POST'
url: config.webhookUrl
Expand All @@ -139,10 +135,10 @@ module.exports = (app) ->
app.use (err, req, res, next) ->
res.status(500).send error: err.message

new CronJob '0 0 10 * * 1-5', _sendCheckinSummary
new CronJob('0 0 10 * * 1-5', _sendCheckinSummary).start()

if rules.crons
for cronRule, cronData of rules.crons
new CronJob cronRule, _sendCronData(cronData)
new CronJob(cronRule, _sendCronData(cronData)).start()

bot

0 comments on commit 51fcdb4

Please sign in to comment.