diff --git a/commands/serverinfo.js b/commands/serverinfo.js new file mode 100644 index 0000000..8990268 --- /dev/null +++ b/commands/serverinfo.js @@ -0,0 +1,50 @@ +const os = require('os') +const path = require('path') +const fs = require('fs/promises') + +// should i move this to util? +async function getCpuModelName () { + const cpuInfo = await fs.readFile('/proc/cpuinfo') + const lines = cpuInfo.toString().split('\n') + // among us way of doing it + const modelName = lines.find((line) => line.startsWith('model name')).split('\t: ') + return modelName[1] +} + +module.exports = { + name: 'serverinfo', + alias: [], + description: 'Shows the info about the server that is hosting the bot', + trusted: 0, + usage: '', + execute: async function (bot, username, sender, prefix, args, config, hash, ownerhash, selector) { + const component = [] + component.push({ text: 'Hostname: ', color: 'gold' }) + component.push({ text: os.hostname(), color: 'aqua' }) + component.push('\n') + component.push({ text: 'Working directory: ', color: 'gold' }) + component.push({ text: path.join(__dirname, '..') /* if without .. it will includes the commands directory */, color: 'aqua' }) + component.push('\n') + component.push({ text: 'OS architecture: ', color: 'gold' }) + component.push({ text: os.arch(), color: 'aqua' }) + component.push('\n') + component.push({ text: 'OS platform: ', color: 'gold' }) + component.push({ text: os.platform(), color: 'aqua' }) + component.push('\n') + component.push({ text: 'OS name: ', color: 'gold' }) + component.push({ text: os.version(), color: 'aqua' }) + component.push('\n') + component.push({ text: 'CPU cores: ', color: 'gold' }) + component.push({ text: os.cpus().length, color: 'aqua' }) + component.push('\n') + component.push({ text: 'CPU model: ', color: 'gold' }) + component.push({ text: await getCpuModelName(), color: 'aqua' }) + component.push('\n') + component.push({ text: 'Total memory usage: ', color: 'gold' }) + component.push({ text: `${Math.floor(os.totalmem() / 1024 / 1024)} MB`, color: 'aqua' }) + component.push('\n') + component.push({ text: 'Available memory usage: ', color: 'gold' }) + component.push({ text: `${Math.floor(os.freemem() / 1024 / 1024)} MB`, color: 'aqua' }) + bot.tellraw(selector, component) + } +}