diff options
| author | ilotterytea <iltsu@alright.party> | 2025-07-02 03:31:54 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-07-02 03:31:54 +0500 |
| commit | 79be89ad0491bfdd110b2c612e21a0f28c29fa87 (patch) | |
| tree | 589daab514de11cc87e424b62d87f8cac12494ab /bot/src/schemas | |
| parent | fea3c12d6b621796bb239cebb57a5a5014dfe350 (diff) | |
feat: MARIADB SUPPORT!!!!
Diffstat (limited to 'bot/src/schemas')
| -rw-r--r-- | bot/src/schemas/channel.hpp | 62 | ||||
| -rw-r--r-- | bot/src/schemas/user.hpp | 26 |
2 files changed, 40 insertions, 48 deletions
diff --git a/bot/src/schemas/channel.hpp b/bot/src/schemas/channel.hpp index d2f13eb..a8979ec 100644 --- a/bot/src/schemas/channel.hpp +++ b/bot/src/schemas/channel.hpp @@ -1,30 +1,30 @@ #pragma once +#include <algorithm> #include <chrono> #include <optional> -#include <pqxx/pqxx> #include <sol/sol.hpp> #include <string> #include <vector> #include "../constants.hpp" #include "../utils/chrono.hpp" -#include "../utils/string.hpp" +#include "database.hpp" namespace bot::schemas { class Channel { public: - Channel(const pqxx::row &row) { - this->id = row[0].as<int>(); - this->alias_id = row[1].as<int>(); - this->alias_name = row[2].as<std::string>(); + Channel(const db::DatabaseRow &row) { + this->id = std::stoi(row.at("id")); + this->alias_id = std::stoi(row.at("alias_id")); + this->alias_name = row.at("alias_name"); this->joined_at = - utils::chrono::string_to_time_point(row[3].as<std::string>()); + utils::chrono::string_to_time_point(row.at("joined_at")); - if (!row[4].is_null()) { + if (!row.at("opted_out_at").empty()) { this->opted_out_at = - utils::chrono::string_to_time_point(row[4].as<std::string>()); + utils::chrono::string_to_time_point(row.at("opted_out_at")); } } @@ -51,6 +51,8 @@ namespace bot::schemas { }; enum ChannelFeature { MARKOV_RESPONSES, RANDOM_MARKOV_RESPONSES }; + const std::vector<ChannelFeature> FEATURES = {MARKOV_RESPONSES, + RANDOM_MARKOV_RESPONSES}; std::optional<ChannelFeature> string_to_channel_feature( const std::string &value); std::optional<std::string> channelfeature_to_string( @@ -58,32 +60,22 @@ namespace bot::schemas { class ChannelPreferences { public: - ChannelPreferences(const pqxx::row &row) { - this->channel_id = row[0].as<int>(); - - if (!row[1].is_null()) { - this->prefix = row[1].as<std::string>(); - } else { - this->prefix = DEFAULT_PREFIX; - } - - if (!row[2].is_null()) { - this->locale = row[2].as<std::string>(); - } else { - this->locale = DEFAULT_LOCALE_ID; - } - - if (!row[3].is_null()) { - std::string x = row[3].as<std::string>(); - x = x.substr(1, x.length() - 2); - std::vector<std::string> 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(const db::DatabaseRow &row) { + this->channel_id = std::stoi(row.at("id")); + this->prefix = + row.at("prefix").empty() ? DEFAULT_PREFIX : row.at("prefix"); + this->locale = + row.at("locale").empty() ? DEFAULT_LOCALE_ID : row.at("locale"); + + std::for_each( + FEATURES.begin(), FEATURES.end(), + [this, &row](const ChannelFeature &f) { + std::optional<std::string> feature = channelfeature_to_string(f); + if (feature.has_value() && row.find(*feature) != row.end() && + row.at(*feature) == "1") { + this->features.push_back(f); + } + }); } ~ChannelPreferences() = default; diff --git a/bot/src/schemas/user.hpp b/bot/src/schemas/user.hpp index e9d7e0f..ee9bd10 100644 --- a/bot/src/schemas/user.hpp +++ b/bot/src/schemas/user.hpp @@ -2,26 +2,26 @@ #include <chrono> #include <optional> -#include <pqxx/pqxx> #include <sol/sol.hpp> #include <string> #include "../utils/chrono.hpp" +#include "database.hpp" namespace bot::schemas { class User { public: - User(const pqxx::row &row) { - this->id = row[0].as<int>(); - this->alias_id = row[1].as<int>(); - this->alias_name = row[2].as<std::string>(); + User(const db::DatabaseRow &row) { + this->id = std::stoi(row.at("id")); + this->alias_id = std::stoi(row.at("alias_id")); + this->alias_name = row.at("alias_name"); this->joined_at = - utils::chrono::string_to_time_point(row[3].as<std::string>()); + utils::chrono::string_to_time_point(row.at("joined_at")); - if (!row[4].is_null()) { + if (!row.at("opted_out_at").empty()) { this->opted_out_at = - utils::chrono::string_to_time_point(row[4].as<std::string>()); + utils::chrono::string_to_time_point(row.at("opted_out_at")); } } @@ -54,11 +54,11 @@ namespace bot::schemas { class UserRights { public: - UserRights(const pqxx::row &row) { - this->id = row[0].as<int>(); - this->user_id = row[1].as<int>(); - this->channel_id = row[2].as<int>(); - this->level = static_cast<PermissionLevel>(row[3].as<int>()); + UserRights(const db::DatabaseRow &row) { + this->id = std::stoi(row.at("id")); + this->user_id = std::stoi(row.at("user_id")); + this->channel_id = std::stoi(row.at("channel_id")); + this->level = static_cast<PermissionLevel>(std::stoi(row.at("level"))); } ~UserRights() = default; |
