2015-11-26 01:00:13 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-08-27 02:53:27 +00:00
|
|
|
// ENiGMA½
|
|
|
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
const ViewController = require('../core/view_controller.js').ViewController;
|
|
|
|
const getActiveNodeList = require('../core/client_connections.js').getActiveNodeList;
|
2016-09-05 03:36:26 +00:00
|
|
|
const stringFormat = require('../core/string_format.js');
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2016-08-27 02:53:27 +00:00
|
|
|
// deps
|
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2015-11-26 01:00:13 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Who\'s Online',
|
|
|
|
desc : 'Who is currently online',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
packageName : 'codes.l33t.enigma.whosonline'
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.getModule = WhosOnlineModule;
|
|
|
|
|
2016-08-27 02:53:27 +00:00
|
|
|
const MciCodeIds = {
|
2015-11-26 01:00:13 +00:00
|
|
|
OnlineList : 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
function WhosOnlineModule(options) {
|
|
|
|
MenuModule.call(this, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(WhosOnlineModule, MenuModule);
|
|
|
|
|
|
|
|
WhosOnlineModule.prototype.mciReady = function(mciData, cb) {
|
2016-08-27 02:53:27 +00:00
|
|
|
const self = this;
|
|
|
|
const vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
|
2015-11-26 01:00:13 +00:00
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function callParentMciReady(callback) {
|
2016-08-27 02:53:27 +00:00
|
|
|
return WhosOnlineModule.super_.prototype.mciReady.call(self, mciData, callback);
|
2015-11-26 01:00:13 +00:00
|
|
|
},
|
|
|
|
function loadFromConfig(callback) {
|
2016-08-27 02:53:27 +00:00
|
|
|
const loadOpts = {
|
2015-11-26 01:00:13 +00:00
|
|
|
callingMenu : self,
|
|
|
|
mciMap : mciData.menu,
|
|
|
|
noInput : true,
|
|
|
|
};
|
|
|
|
|
2016-08-27 02:53:27 +00:00
|
|
|
return vc.loadFromMenuConfig(loadOpts, callback);
|
2015-11-26 01:00:13 +00:00
|
|
|
},
|
|
|
|
function populateList(callback) {
|
2016-08-27 02:53:27 +00:00
|
|
|
const onlineListView = vc.getView(MciCodeIds.OnlineList);
|
|
|
|
const listFormat = self.menuConfig.config.listFormat || '{node} - {userName} - {action} - {timeOn}';
|
|
|
|
const nonAuthUser = self.menuConfig.config.nonAuthUser || 'Logging In';
|
|
|
|
const otherUnknown = self.menuConfig.config.otherUnknown || 'N/A';
|
|
|
|
const onlineList = getActiveNodeList(self.menuConfig.config.authUsersOnly).slice(0, onlineListView.height);
|
2016-01-30 22:18:55 +00:00
|
|
|
|
|
|
|
onlineListView.setItems(_.map(onlineList, oe => {
|
|
|
|
if(oe.authenticated) {
|
|
|
|
oe.timeOn = _.capitalize(oe.timeOn.humanize());
|
|
|
|
} else {
|
|
|
|
[ 'realName', 'location', 'affils', 'timeOn' ].forEach(m => {
|
|
|
|
oe[m] = otherUnknown;
|
|
|
|
});
|
|
|
|
oe.userName = nonAuthUser;
|
2016-01-02 20:20:52 +00:00
|
|
|
}
|
2016-09-05 03:36:26 +00:00
|
|
|
return stringFormat(listFormat, oe);
|
2015-11-26 01:00:13 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
onlineListView.focusItems = onlineListView.items;
|
|
|
|
onlineListView.redraw();
|
2016-08-27 02:53:27 +00:00
|
|
|
|
|
|
|
return callback(null);
|
2015-11-26 01:00:13 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
if(err) {
|
2016-08-27 02:53:27 +00:00
|
|
|
self.client.log.error( { error : err.message }, 'Error loading who\'s online');
|
2015-11-26 01:00:13 +00:00
|
|
|
}
|
2016-08-27 02:53:27 +00:00
|
|
|
return cb(err);
|
2015-11-26 01:00:13 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|