From 11ca4bf50b7b14b8be54756cb2a7f37ef31890a8 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 5 Jul 2025 12:34:11 +0500 Subject: feat: get bot temperature --- bot/src/commands/lua.cpp | 25 +++++++++++++++++++++++++ luamods/ping.lua | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index a35e605..0c02bf5 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -64,6 +66,29 @@ namespace bot::command::lua { return usage.ru_maxrss; }); + state->set_function("bot_get_temperature", []() { + float temp = 0.0; + + std::string path = "/sys/class/thermal/thermal_zone0/temp"; + + if (!std::filesystem::exists(path)) { + return temp; + } + + std::ifstream ifs; + ifs.open(path); + + std::stringstream buffer; + buffer << ifs.rdbuf(); + ifs.close(); + + temp = std::stof(buffer.str()); + temp /= 1000; + temp = std::roundf(temp * 100) / 100; + + return temp; + }); + state->set_function("bot_get_compile_time", []() { return BOT_COMPILED_TIMESTAMP; }); diff --git a/luamods/ping.lua b/luamods/ping.lua index d314cb2..a8b9fd4 100644 --- a/luamods/ping.lua +++ b/luamods/ping.lua @@ -12,7 +12,7 @@ return { bot_get_compiler_version() .. " · Uptime: " .. time_humanize(bot_get_uptime()) .. " · Used memory: " .. math.ceil(bot_get_memory_usage() / 1024 / 1024) .. - "MB · Bot running on v" .. bot_get_version() .. + "MB · Temperature: " .. tostring(bot_get_temperature()) .. "°C · Bot running on v" .. bot_get_version() .. " (Last updated " .. time_humanize(time_current() - bot_get_compile_time()) .. " ago)" end } -- cgit v1.2.3