Added uptime module.
This commit is contained in:
parent
93ee8f1c17
commit
d36180c8b0
|
@ -22,7 +22,7 @@ module.exports = {
|
|||
greeting: 'Hi, I am aisha, your game host!',
|
||||
usernamePrefix: '@',
|
||||
channels: ['GamesNight'],
|
||||
games: ['mash', 'trivia', 'letters', 'duck', 'ping', 'say', 'kill', 'help'],
|
||||
games: ['mash', 'trivia', 'letters', 'duck', 'ping', 'say', 'kill', 'uptime', 'help'],
|
||||
schatColors: {
|
||||
red: 'red',
|
||||
orange: 'orange',
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
"bhttp": "^1.2.8",
|
||||
"bottleneck": "^2.19.5",
|
||||
"config": "^3.3.6",
|
||||
"date-fns": "^2.29.3",
|
||||
"html-entities": "^2.3.2",
|
||||
"inflect": "^0.5.0",
|
||||
"irc": "^0.5.2",
|
||||
|
@ -1078,6 +1079,18 @@
|
|||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/date-fns": {
|
||||
"version": "2.29.3",
|
||||
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.29.3.tgz",
|
||||
"integrity": "sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==",
|
||||
"engines": {
|
||||
"node": ">=0.11"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/date-fns"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
|
@ -4673,6 +4686,11 @@
|
|||
"whatwg-url": "^10.0.0"
|
||||
}
|
||||
},
|
||||
"date-fns": {
|
||||
"version": "2.29.3",
|
||||
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.29.3.tgz",
|
||||
"integrity": "sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA=="
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
"bhttp": "^1.2.8",
|
||||
"bottleneck": "^2.19.5",
|
||||
"config": "^3.3.6",
|
||||
"date-fns": "^2.29.3",
|
||||
"html-entities": "^2.3.2",
|
||||
"inflect": "^0.5.0",
|
||||
"irc": "^0.5.2",
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
const config = require('config');
|
||||
const os = require('os');
|
||||
const { intervalToDuration } = require('date-fns');
|
||||
|
||||
const start = Date.now();
|
||||
|
||||
function getDurationString(duration) {
|
||||
return Object.entries(duration)
|
||||
.filter(([, value]) => !!value)
|
||||
.map(([key, value]) => `${value} ${key}`)
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
function onCommand(args, context) {
|
||||
const duration = intervalToDuration({ start, end: Date.now() });
|
||||
const durationString = getDurationString(duration);
|
||||
|
||||
if (['sys', 'system'].includes(context.subcommand || args[0]) && config.operators.includes(context.user.username)) {
|
||||
const osDuration = intervalToDuration({ start: 0, end: os.uptime() * 1000 });
|
||||
const osDurationString = getDurationString(osDuration);
|
||||
|
||||
context.sendMessage(`I've been awake for ${durationString}. My host has been running for ${osDurationString}.`, context.room.id, null, context.message.user?.recipient);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
context.sendMessage(`I've been awake for ${durationString}.`, context.room.id, null, context.message.user?.recipient);
|
||||
}
|
||||
|
||||
module.exports = { onCommand };
|
Loading…
Reference in New Issue