From 17c96ce4e5de6e8811d8f5664c4ab8a6ac68e041 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 10 Apr 2025 23:34:41 +0500 Subject: feat: time_format lua function --- bot/src/commands/lua.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index 5a996ca..17c5ba3 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -5,10 +5,14 @@ #include #include +#include #include +#include +#include #include #include #include +#include #include #include #include @@ -82,6 +86,20 @@ namespace bot::command::lua { state->set_function("time_humanize", [](const int ×tamp) { return utils::chrono::format_timestamp(timestamp); }); + + state->set_function("time_format", + [](const long ×tamp, const std::string &format) { + std::time_t t = std::time(nullptr); + t = timestamp; + std::tm *now = std::localtime(&t); + + std::ostringstream oss; + oss << std::put_time(now, format.c_str()); + + std::string o = oss.str(); + + return o; + }); } sol::object parse_json_object(std::shared_ptr state, -- cgit v1.2.3