From 2a49844a95593ac98e919c18651320e62f276fa7 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 6 Apr 2025 17:28:47 +0400 Subject: feat: implementing lua coding --- bot/src/schemas/user.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bot/src/schemas/user.cpp (limited to 'bot/src/schemas/user.cpp') diff --git a/bot/src/schemas/user.cpp b/bot/src/schemas/user.cpp new file mode 100644 index 0000000..bbf5711 --- /dev/null +++ b/bot/src/schemas/user.cpp @@ -0,0 +1,42 @@ +#include "schemas/user.hpp" + +#include +#include + +namespace bot::schemas { + sol::table User::as_lua_table(std::shared_ptr luaState) const { + sol::table o = luaState->create_table(); + + o["id"] = this->id; + o["alias_id"] = this->alias_id; + o["alias_name"] = this->alias_name; + + o["joined_at"] = + static_cast(std::chrono::duration_cast( + this->joined_at.time_since_epoch()) + .count()); + if (this->opted_out_at.has_value()) { + o["opted_out_at"] = + static_cast(std::chrono::duration_cast( + this->opted_out_at->time_since_epoch()) + .count()); + } else { + o["opted_out_at"] = sol::lua_nil; + } + + return o; + } + + sol::table UserRights::as_lua_table( + std::shared_ptr luaState) const { + sol::table o = luaState->create_table(); + + o["id"] = this->id; + o["user_id"] = this->user_id; + o["channel_id"] = this->channel_id; + o["level"] = this->level; + o["is_fixed"] = false; // TODO: remove it later + + return o; + } +} \ No newline at end of file -- cgit v1.2.3