diff options
Diffstat (limited to 'bot/src/schemas/user.cpp')
| -rw-r--r-- | bot/src/schemas/user.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
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 <chrono> +#include <sol/types.hpp> + +namespace bot::schemas { + sol::table User::as_lua_table(std::shared_ptr<sol::state> 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<long>(std::chrono::duration_cast<std::chrono::seconds>( + this->joined_at.time_since_epoch()) + .count()); + if (this->opted_out_at.has_value()) { + o["opted_out_at"] = + static_cast<long>(std::chrono::duration_cast<std::chrono::seconds>( + 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<sol::state> 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 |
