Skip to content

Commit

Permalink
.spod: show current login time, for online users
Browse files Browse the repository at this point in the history
  • Loading branch information
marado committed Apr 22, 2021
1 parent 44ab522 commit 698b7ca
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit 698b7ca

Please sign in to comment.