2015-11-26 01:00:13 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
2022-06-05 20:04:25 +00:00
|
|
|
const { MenuModule } = require('./menu_module.js');
|
2018-11-14 03:03:54 +00:00
|
|
|
const { getActiveConnectionList } = require('./client_connections.js');
|
2022-06-05 20:04:25 +00:00
|
|
|
const { Errors } = require('./enig_error.js');
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2015-11-26 01:00:13 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2022-06-05 20:04:25 +00:00
|
|
|
name: "Who's Online",
|
|
|
|
desc: 'Who is currently online',
|
|
|
|
author: 'NuSkooler',
|
|
|
|
packageName: 'codes.l33t.enigma.whosonline',
|
2015-11-26 01:00:13 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const MciViewIds = {
|
2022-06-05 20:04:25 +00:00
|
|
|
onlineList: 1,
|
2015-11-26 01:00:13 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class WhosOnlineModule extends MenuModule {
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
}
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return cb(err);
|
|
|
|
}
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
async.series(
|
|
|
|
[
|
2022-06-05 20:04:25 +00:00
|
|
|
next => {
|
2018-07-22 05:57:59 +00:00
|
|
|
return this.prepViewController('online', 0, mciData.menu, next);
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
next => {
|
|
|
|
const onlineListView = this.viewControllers.online.getView(
|
|
|
|
MciViewIds.onlineList
|
|
|
|
);
|
|
|
|
if (!onlineListView) {
|
|
|
|
return cb(
|
|
|
|
Errors.MissingMci(
|
|
|
|
`Missing online list MCI ${MciViewIds.onlineList}`
|
|
|
|
)
|
|
|
|
);
|
2018-07-22 05:57:59 +00:00
|
|
|
}
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const onlineList = getActiveConnectionList(true)
|
|
|
|
.slice(0, onlineListView.height)
|
|
|
|
.map(oe =>
|
|
|
|
Object.assign(oe, {
|
|
|
|
text: oe.userName,
|
|
|
|
timeOn: _.upperFirst(oe.timeOn.humanize()),
|
|
|
|
})
|
|
|
|
);
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2018-07-22 05:57:59 +00:00
|
|
|
onlineListView.setItems(onlineList);
|
2018-06-22 05:15:04 +00:00
|
|
|
onlineListView.redraw();
|
2018-07-22 05:57:59 +00:00
|
|
|
return next(null);
|
2022-06-05 20:04:25 +00:00
|
|
|
},
|
2018-06-22 05:15:04 +00:00
|
|
|
],
|
2018-07-22 05:57:59 +00:00
|
|
|
err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
|
|
|
this.client.log.error(
|
|
|
|
{ error: err.message },
|
|
|
|
"Error loading who's online"
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2015-11-26 01:00:13 +00:00
|
|
|
};
|