diff options
Diffstat (limited to 'bot/src/schemas/channel.cpp')
| -rw-r--r-- | bot/src/schemas/channel.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/bot/src/schemas/channel.cpp b/bot/src/schemas/channel.cpp index ae4ea53..540b7c0 100644 --- a/bot/src/schemas/channel.cpp +++ b/bot/src/schemas/channel.cpp @@ -1,5 +1,7 @@ #include "channel.hpp" +#include <optional> + namespace bot::schemas { std::optional<ChannelFeature> string_to_channel_feature( const std::string &value) { @@ -11,4 +13,62 @@ namespace bot::schemas { return std::nullopt; } } + + std::optional<std::string> channelfeature_to_string( + const ChannelFeature &value) { + switch (value) { + case MARKOV_RESPONSES: + return "markov_responses"; + case RANDOM_MARKOV_RESPONSES: + return "random_markov_responses"; + default: + std::nullopt; + } + } + + sol::table Channel::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 ChannelPreferences::as_lua_table( + std::shared_ptr<sol::state> luaState) const { + sol::table o = luaState->create_table(); + + o["id"] = this->channel_id; // TODO: remove it later too. + o["channel_id"] = this->channel_id; + o["prefix"] = this->prefix; + o["language"] = this->locale; + + sol::table f = luaState->create_table(); + + for (const ChannelFeature &feature : this->features) { + std::optional<std::string> ff = channelfeature_to_string(feature); + if (ff.has_value()) { + f.add(ff.value()); + } + } + + o["features"] = f; + + return o; + } }
\ No newline at end of file |
