vnstat/index.js

36 lines
915 B
JavaScript
Raw Permalink Normal View History

2023-01-07 22:09:09 +08:00
const { KiviPlugin, segment } = require("@kivibot/core");
const { execSync } = require("child_process");
2023-01-06 17:14:30 +08:00
const plugin = new KiviPlugin("demo", "0.1.0");
2023-01-07 22:09:09 +08:00
function vnstati() {
execSync("vnstati -L -i eth0 -s -o s.png");
execSync("vnstati -L -i eth0 -h -o h.png");
execSync("vnstati -L -i eth0 -hg -o hg.png");
}
2023-01-06 17:14:30 +08:00
plugin.onMounted(() => {
plugin.cron("0 8 * * *", (bot, admins) => {
2023-01-07 22:09:09 +08:00
vnstati();
2023-01-06 17:14:30 +08:00
admins.forEach((admin) => {
2023-01-07 22:09:09 +08:00
bot.sendPrivateMsg(admin, [
"昨日流量使用数据:\n",
segment.image("s.png"),
segment.image("h.png"),
segment.image("hg.png"),
]);
2023-01-06 17:14:30 +08:00
});
});
2023-01-07 22:09:09 +08:00
plugin.onAdminCmd("vnstat", (event, params, options) => {
vnstati();
event.reply([
"过去24小时内流量使用数据\n",
segment.image("s.png"),
segment.image("h.png"),
segment.image("hg.png"),
]);
});
2023-01-06 17:14:30 +08:00
});
module.exports = { plugin };