47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
var express = require('express');
|
|
var api = express.Router();
|
|
var config = require('../../config');
|
|
var utils = require('../../utils');
|
|
const os = require('os');
|
|
|
|
api.get('/', (req, res) => {
|
|
res.status(200).jsonp({
|
|
name: config.name,
|
|
version: config.version
|
|
});
|
|
});
|
|
|
|
api.get('/ints/:kind/:user1?/:user2?', (req, res) => {
|
|
if (utils.int[req.params.kind] === undefined) return res.status(404).jsonp({ error: `This does not exist` });
|
|
if (!req.params.user1 || !req.params.user2) return res.status(400).jsonp({ error: `I need two users to work` });
|
|
let LineFromUtils = utils.int[req.params.kind][parseInt(Math.random() * utils.int[req.params.kind].length)];
|
|
let Line = LineFromUtils.replace(/0/g, utils.format.bold(req.params.user1)).replace(
|
|
/1/g,
|
|
utils.format.bold(req.params.user2)
|
|
);
|
|
let respo = LineFromUtils.replace(/0/g, req.params.user1).replace(/1/g, req.params.user2);
|
|
res.status(200).jsonp({
|
|
Line: respo,
|
|
MarkdownLine: Line
|
|
});
|
|
});
|
|
|
|
function format(seconds) {
|
|
function pad(s) {
|
|
return (s < 10 ? '0' : '') + s;
|
|
}
|
|
var hours = Math.floor(seconds / (60 * 60));
|
|
var minutes = Math.floor((seconds % (60 * 60)) / 60);
|
|
var seconds = Math.floor(seconds % 60);
|
|
|
|
return pad(hours) + 'h ' + pad(minutes) + 'm ' + pad(seconds) + 's';
|
|
}
|
|
|
|
api.get('/system', (req, res) => {
|
|
res.jsonp({
|
|
hostname: os.hostname(),
|
|
uptime: `${format(process.uptime())}`
|
|
});
|
|
});
|
|
|
|
module.exports = api;
|