Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD: .spod command #108

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions commands/spod.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ exports.command = {
var chalk = require('chalk');
var formatters = require('../utils/formatters.js');
var userlist;

// the usertime is found in a different way, depending on if they're online or not
// TODO: consider moving this into an helper function that can be used on .exa and elsewhere
var usertime = function(user) {
return user.loggedin ? (Date.now() - user.loginTime) : user.totalTime;
}

if(command === "") { // sort by total time
userList = command_access.getUsersList().sort(function(a,b){return b.totalTime - a.totalTime;});
var lengthMaxFriendlyTotalTime = formatters.friendly_time(userList[0].totalTime).length;
userList = command_access.getUsersList().sort(function(a,b){return usertime(b) - usertime(a);});
var lengthMaxFriendlyTotalTime = formatters.friendly_time(usertime(userList[0])).length;
command_access.sendData(socket, "\r\n" + chalk.cyan("+-- Top Users by login time -------------------------------------------------+\r\n\r\n"));
} else if(command === '-l') { // sort by login count
userList = command_access.getUsersList().sort(function(a,b){return b.loginCount - a.loginCount;});
Expand All @@ -36,7 +43,7 @@ exports.command = {
if(command === '-l') {
userRow = userRow + userObject.loginCount.toString().padStart(lengthMaxLoginCount) + " logins";
} else {
userRow = userRow + formatters.friendly_time(userObject.totalTime).padStart(lengthMaxFriendlyTotalTime);
userRow = userRow + formatters.friendly_time(usertime(userObject)).padStart(lengthMaxFriendlyTotalTime);
}
userRow = userRow + " : " + userObject.username + "\r\n";
if(userRow[0] === '>') {
Expand Down