Added uptime module.

This commit is contained in:
2022-10-23 05:03:18 +02:00
parent 93ee8f1c17
commit d36180c8b0
4 changed files with 52 additions and 1 deletions

32
src/games/uptime.js Normal file
View File

@@ -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 };