2019-01-19 05:09:10 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const UserProps = require('./user_property.js');
|
|
|
|
const Events = require('./events.js');
|
|
|
|
const StatLog = require('./stat_log.js');
|
|
|
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
exports.trackDoorRunBegin = trackDoorRunBegin;
|
|
|
|
exports.trackDoorRunEnd = trackDoorRunEnd;
|
|
|
|
|
|
|
|
function trackDoorRunBegin(client, doorTag) {
|
|
|
|
const startTime = moment();
|
2019-01-19 06:12:01 +00:00
|
|
|
return { startTime, client, doorTag };
|
2019-01-19 05:09:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function trackDoorRunEnd(trackInfo) {
|
2020-05-22 03:22:49 +00:00
|
|
|
if (!trackInfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-19 06:12:01 +00:00
|
|
|
const { startTime, client, doorTag } = trackInfo;
|
2019-01-19 05:09:10 +00:00
|
|
|
|
2019-01-19 06:12:01 +00:00
|
|
|
const diff = moment.duration(moment().diff(startTime));
|
|
|
|
if(diff.asSeconds() >= 45) {
|
|
|
|
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalCount, 1);
|
|
|
|
}
|
2019-01-19 05:09:10 +00:00
|
|
|
|
2019-01-19 06:12:01 +00:00
|
|
|
const runTimeMinutes = Math.floor(diff.asMinutes());
|
2019-01-19 05:09:10 +00:00
|
|
|
if(runTimeMinutes > 0) {
|
|
|
|
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
|
2019-01-19 06:12:01 +00:00
|
|
|
|
|
|
|
const eventInfo = {
|
|
|
|
runTimeMinutes,
|
|
|
|
user : client.user,
|
|
|
|
doorTag : doorTag || 'unknown',
|
|
|
|
};
|
|
|
|
|
|
|
|
Events.emit(Events.getSystemEvents().UserRunDoor, eventInfo);
|
2019-01-19 05:09:10 +00:00
|
|
|
}
|
|
|
|
}
|