diff --git a/app.coffee b/app.coffee index e1a96ac..811f89a 100644 --- a/app.coffee +++ b/app.coffee @@ -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') diff --git a/package.json b/package.json index 89a41b1..55a0a2c 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/src/bot.coffee b/src/bot.coffee index 2e80e1c..805e6e1 100644 --- a/src/bot.coffee +++ b/src/bot.coffee @@ -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(',')} 这几个家伙还没签到,去哪儿啦?" @@ -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 @@ -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