diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-10 23:34:41 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-10 23:34:41 +0500 |
| commit | 17c96ce4e5de6e8811d8f5664c4ab8a6ac68e041 (patch) | |
| tree | ac2c054e1a8c488a2e439e84e5f06ecd1d9a69f2 /bot/src/commands/lua.cpp | |
| parent | f46c0e11fc38669d752d981867ddd5e6b1713dd0 (diff) | |
feat: time_format lua function
Diffstat (limited to 'bot/src/commands/lua.cpp')
| -rw-r--r-- | bot/src/commands/lua.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
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 <unistd.h> #include <algorithm> +#include <chrono> #include <cmath> +#include <ctime> +#include <iomanip> #include <memory> #include <nlohmann/json.hpp> #include <sol/sol.hpp> +#include <sstream> #include <stdexcept> #include <string> #include <vector> @@ -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<sol::state_view> state, |
