From 42cbe6ab4f4e7018786bfab59f54fb8422bcaa87 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Mon, 9 Dec 2024 07:36:27 +0500 Subject: feat: channel feature --- bot/src/schemas/channel.hpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'bot/src/schemas/channel.hpp') diff --git a/bot/src/schemas/channel.hpp b/bot/src/schemas/channel.hpp index 2560331..e346b9f 100644 --- a/bot/src/schemas/channel.hpp +++ b/bot/src/schemas/channel.hpp @@ -4,9 +4,11 @@ #include #include #include +#include #include "../constants.hpp" #include "../utils/chrono.hpp" +#include "../utils/string.hpp" namespace bot::schemas { class Channel { @@ -45,22 +47,36 @@ namespace bot::schemas { std::optional opted_out_at; }; + enum ChannelFeature { MARKOV_RESPONSES }; + class ChannelPreferences { public: ChannelPreferences(const pqxx::row &row) { this->channel_id = row[0].as(); - if (!row[2].is_null()) { + if (!row[1].is_null()) { this->prefix = row[1].as(); } else { this->prefix = DEFAULT_PREFIX; } - if (!row[3].is_null()) { + if (!row[2].is_null()) { this->locale = row[2].as(); } else { this->locale = DEFAULT_LOCALE_ID; } + + if (!row[3].is_null()) { + std::string x = row[3].as(); + x = x.substr(1, x.length() - 2); + std::vector split_text = + utils::string::split_text(x, ','); + + for (const std::string &part : split_text) { + ChannelFeature feature = (ChannelFeature)std::stoi(part); + this->features.push_back(feature); + } + } } ~ChannelPreferences() = default; @@ -68,9 +84,13 @@ namespace bot::schemas { const int &get_channel_id() const { return this->channel_id; } const std::string &get_prefix() const { return this->prefix; } const std::string &get_locale() const { return this->locale; } + const std::vector &get_features() const { + return this->features; + } private: int channel_id; std::string prefix, locale; + std::vector features; }; } -- cgit v1.2.3