Add latency est., activity level indicators, etc.

This commit is contained in:
Bryan Ashby 2019-06-10 20:07:45 -06:00
parent da93fd53e9
commit 80eb8ad38d
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
1 changed files with 51 additions and 16 deletions

View File

@ -82,17 +82,19 @@ exports.getModule = class mrcModule extends MenuModule {
room: '', room: '',
room_topic: '', room_topic: '',
nicks: [], nicks: [],
last_ping: 0 lastSentMsg : {}, // used for latency est.
}; };
this.customFormatObj = { this.customFormatObj = {
roomName : '', roomName : '',
roomTopic : '', roomTopic : '',
roomUserCount : 0, roomUserCount : 0,
userCount : 0, userCount : 0,
boardCount : 0, boardCount : 0,
roomCount : 0, roomCount : 0,
//latencyMs : 0, //latencyMs : 0,
activityLevel : 0,
activityLevelIndicator : ' ',
}; };
this.menuMethods = { this.menuMethods = {
@ -298,16 +300,27 @@ exports.getModule = class mrcModule extends MenuModule {
break; break;
case 'STATS': { case 'STATS': {
const stats = params[1].split(' '); const [
this.setText(MciViewIds.mrcChat.mrcUsers, stats[2]); boardCount,
this.setText(MciViewIds.mrcChat.mrcBbses, stats[0]); roomCount,
userCount,
activityLevel
] = params[1].split(' ').map(v => parseInt(v));
const activityLevelIndicator = this.getActivityLevelIndicator(activityLevel);
Object.assign(
this.customFormatObj,
{
boardCount, roomCount, userCount,
activityLevel, activityLevelIndicator
}
);
this.setText(MciViewIds.mrcChat.mrcUsers, userCount);
this.setText(MciViewIds.mrcChat.mrcBbses, boardCount);
this.customFormatObj.boardCount = parseInt(stats[0]);
this.customFormatObj.roomCount = parseInt(stats[1]);
this.customFormatObj.userCount = parseInt(stats[2]);
this.updateCustomViews(); this.updateCustomViews();
this.state.last_ping = stats[1];
break; break;
} }
@ -317,6 +330,12 @@ exports.getModule = class mrcModule extends MenuModule {
} }
} else { } else {
if(message.body === this.state.lastSentMsg.msg) {
this.customFormatObj.latencyMs =
moment.duration(moment().diff(this.state.lastSentMsg.time)).asMilliseconds();
delete this.state.lastSentMsg.msg;
}
if (message.to_room == this.state.room) { if (message.to_room == this.state.room) {
// if we're here then we want to show it to the user // if we're here then we want to show it to the user
const currentTime = moment().format(this.client.currentTheme.helpers.getTimeFormat()); const currentTime = moment().format(this.client.currentTheme.helpers.getTimeFormat());
@ -328,6 +347,14 @@ exports.getModule = class mrcModule extends MenuModule {
}); });
} }
getActivityLevelIndicator(level) {
let indicators = this.config.activityLevelIndicators;
if(!Array.isArray(indicators) || indicators.length < level + 1) {
indicators = [ ' ', '░', '▒', '▓' ];
}
return indicators[level].charAt(0);
}
setText(mciId, text) { setText(mciId, text) {
return this.setViewText('mrcChat', mciId, text); return this.setViewText('mrcChat', mciId, text);
} }
@ -378,6 +405,10 @@ exports.getModule = class mrcModule extends MenuModule {
} }
try { try {
this.state.lastSentMsg = {
msg : formattedMessage,
time : moment(),
};
this.sendMessageToMultiplexer(to_user || '', '', this.state.room, formattedMessage); this.sendMessageToMultiplexer(to_user || '', '', this.state.room, formattedMessage);
} catch(e) { } catch(e) {
this.client.log.warn( { error : e.message }, 'MRC error'); this.client.log.warn( { error : e.message }, 'MRC error');
@ -397,6 +428,7 @@ exports.getModule = class mrcModule extends MenuModule {
case 'pm': case 'pm':
this.processOutgoingMessage(cmd[2], cmd[1]); this.processOutgoingMessage(cmd[2], cmd[1]);
break; break;
case 'rainbow': { case 'rainbow': {
// this is brutal, but i love it // this is brutal, but i love it
const line = message.replace(/^\/rainbow\s/, '').split(' ').reduce(function (a, c) { const line = message.replace(/^\/rainbow\s/, '').split(' ').reduce(function (a, c) {
@ -408,6 +440,7 @@ exports.getModule = class mrcModule extends MenuModule {
this.processOutgoingMessage(line); this.processOutgoingMessage(line);
break; break;
} }
case 'l33t': case 'l33t':
this.processOutgoingMessage(StringUtil.stylizeString(message.substr(6), 'l33t')); this.processOutgoingMessage(StringUtil.stylizeString(message.substr(6), 'l33t'));
break; break;
@ -418,6 +451,7 @@ exports.getModule = class mrcModule extends MenuModule {
this.processOutgoingMessage(StringUtil.stylizeString(message.substr(6), mode)); this.processOutgoingMessage(StringUtil.stylizeString(message.substr(6), mode));
break; break;
} }
case 'whoon': case 'whoon':
this.sendServerMessage('WHOON'); this.sendServerMessage('WHOON');
break; break;
@ -471,6 +505,7 @@ exports.getModule = class mrcModule extends MenuModule {
} }
// just do something to get the cursor back to the right place ¯\_(ツ)_/¯ // just do something to get the cursor back to the right place ¯\_(ツ)_/¯
// :TODO: fix me!
this.sendServerMessage('STATS'); this.sendServerMessage('STATS');
} }