summaryrefslogtreecommitdiff
path: root/bot/src/schemas/channel.cpp
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-06 17:28:47 +0400
committerilotterytea <iltsu@alright.party>2025-04-06 17:28:47 +0400
commit2a49844a95593ac98e919c18651320e62f276fa7 (patch)
tree01b7e2ebb1dc7a9ac92e7c3105edfd098271f29a /bot/src/schemas/channel.cpp
parenta1a36cf4d4999b5ce89dce95364c9fd839b54b5d (diff)
feat: implementing lua coding
Diffstat (limited to 'bot/src/schemas/channel.cpp')
-rw-r--r--bot/src/schemas/channel.cpp60
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