FridayNightFunkinBoyfriendBot/modules/memusage.js

53 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2024-01-12 12:24:01 -05:00
function memusage(bot, options) {
const clamp = require("../util/clamp");
const bossbarName = "memusage";
2023-12-17 14:55:27 -05:00
2024-01-12 12:24:01 -05:00
const os = require("os");
let enabled = false;
let tag = "FNFBoyfriendBotMemusage";
bot.memusage = {
on() {
enabled = true;
2023-12-17 14:55:27 -05:00
},
2024-01-12 12:24:01 -05:00
off() {
enabled = false;
bot.core.run(`minecraft:bossbar remove ${bossbarName}`);
},
};//
2023-12-17 14:55:27 -05:00
const interval = setInterval(() => {
2024-01-12 12:24:01 -05:00
if (!enabled) return;
2023-12-17 14:55:27 -05:00
2024-01-12 12:24:01 -05:00
/* const component = {
text: `Mem used ${Math.floor(
process.memoryUsage().heapUsed / 1000 / 1000,
)} MiB / ${Math.floor(
process.memoryUsage().heapTotal / 1000 / 1000,
)} MiB. `,
color: "dark_gray",
};*/
const component = {
translate: `memusage %s`,
color: "gray",
bold: false,
with: [{ text: `Memory used ${Math.floor(
process.memoryUsage().heapUsed / 1000 / 1000,
)} Mebibytes / ${Math.floor(
process.memoryUsage().heapTotal / 1000 / 1000,
)} Mebibytes.`, color: "green" }],
};
//process.cpuUsage
bot.core.run(`minecraft:bossbar add ${bossbarName} ""`);
bot.core.run(`minecraft:bossbar set ${bossbarName} players @a`);
bot.core.run(`minecraft:bossbar set ${bossbarName} color yellow`);
bot.core.run(`minecraft:bossbar set ${bossbarName} visible true`);
bot.core.run(`minecraft:bossbar set ${bossbarName} style progress`);
bot.core.run(
`minecraft:bossbar set ${bossbarName} name ${JSON.stringify(component)}`,
);
bot.core.run(`minecraft:bossbar set ${bossbarName} max 20`);
}, 100); //process.memoryUsage().heapUsed /1024 / 1024
}
module.exports = memusage;