From d1793df1eda463b10107d41785ad1d7f055ed476 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 18 May 2024 14:48:12 +0500 Subject: upd: moved the bot part to a relative subfolder --- bot/src/modules/ping.hpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 bot/src/modules/ping.hpp (limited to 'bot/src/modules/ping.hpp') diff --git a/bot/src/modules/ping.hpp b/bot/src/modules/ping.hpp new file mode 100644 index 0000000..836917d --- /dev/null +++ b/bot/src/modules/ping.hpp @@ -0,0 +1,59 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include +#include + +#include "../bundle.hpp" +#include "../commands/command.hpp" +#include "../utils/chrono.hpp" + +namespace bot { + namespace mod { + class Ping : public command::Command { + std::string get_name() const override { return "ping"; } + + std::variant, std::string> run( + const InstanceBundle &bundle, + const command::Request &request) const override { + auto now = std::chrono::steady_clock::now(); + auto duration = now - START_TIME; + auto seconds = + std::chrono::duration_cast(duration); + std::string uptime = utils::chrono::format_timestamp(seconds.count()); + + struct rusage usage; + getrusage(RUSAGE_SELF, &usage); + + int used_memory = usage.ru_maxrss / 1024; + + std::string cpp_info; + +#ifdef __cplusplus + cpp_info.append("C++" + std::to_string(__cplusplus).substr(2, 2)); +#endif + +#ifdef __VERSION__ + cpp_info.append(" (gcc " + + bot::utils::string::split_text(__VERSION__, ' ')[0] + + ")"); +#endif + + if (!cpp_info.empty()) { + cpp_info.append(" ยท "); + } + + return bundle.localization + .get_formatted_line( + request, loc::LineId::PingResponse, + {cpp_info, uptime, std::to_string(used_memory)}) + .value(); + } + }; + } +} -- cgit v1.2.3