Compare commits

...

2 Commits

Author SHA1 Message Date
ThePendulum 11dd4f2c53 1.14.0 2022-10-23 05:03:20 +02:00
ThePendulum d36180c8b0 Added uptime module. 2022-10-23 05:03:18 +02:00
4 changed files with 55 additions and 4 deletions

View File

@ -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',

22
package-lock.json generated
View File

@ -1,17 +1,18 @@
{
"name": "schat2-clive",
"version": "1.13.0",
"version": "1.14.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "schat2-clive",
"version": "1.13.0",
"version": "1.14.0",
"license": "ISC",
"dependencies": {
"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",

View File

@ -1,6 +1,6 @@
{
"name": "schat2-clive",
"version": "1.13.0",
"version": "1.14.0",
"description": "Game host for SChat 2-powered chat sites",
"main": "src/app.js",
"scripts": {
@ -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",

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