summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-04-30 22:27:49 +0500
committerilotterytea <iltsu@alright.party>2024-04-30 22:27:49 +0500
commita47294d563c940e1423791eaa5f4e0bfe6b9dae1 (patch)
treec184e3af9dd6a73bac92c390e70506b605ce69d6 /src
parenta47271126bac5c7637fc7763213659fb63e384bd (diff)
feat: added ChannelPreferences model into Request struct
Diffstat (limited to 'src')
-rw-r--r--src/commands/request.hpp1
-rw-r--r--src/commands/request_util.cpp32
2 files changed, 29 insertions, 4 deletions
diff --git a/src/commands/request.hpp b/src/commands/request.hpp
index 702fcb8..8538cdc 100644
--- a/src/commands/request.hpp
+++ b/src/commands/request.hpp
@@ -16,6 +16,7 @@ namespace bot::command {
const irc::Message<irc::MessageType::Privmsg> &irc_message;
schemas::Channel channel;
+ schemas::ChannelPreferences channel_preferences;
schemas::User user;
pqxx::connection &conn;
diff --git a/src/commands/request_util.cpp b/src/commands/request_util.cpp
index 94e563d..9424082 100644
--- a/src/commands/request_util.cpp
+++ b/src/commands/request_util.cpp
@@ -63,6 +63,30 @@ namespace bot::command {
schemas::Channel channel(channel_query[0]);
+ pqxx::result channel_pref_query =
+ work->exec("SELECT * FROM channel_preferences WHERE channel_id = " +
+ std::to_string(channel.get_id()));
+
+ // Create new channel preference data in the database if it didn't exist b4
+ if (channel_pref_query.empty()) {
+ work->exec(
+ "INSERT INTO channel_preferences (channel_id, prefix, locale) VALUES "
+ "(" +
+ std::to_string(channel.get_id()) + ", '" + DEFAULT_PREFIX + "', '" +
+ DEFAULT_LOCALE_ID + "')");
+
+ work->commit();
+
+ delete work;
+ work = new pqxx::work(conn);
+
+ channel_pref_query =
+ work->exec("SELECT * FROM channel_preferences WHERE channel_id = " +
+ std::to_string(channel.get_id()));
+ }
+
+ schemas::ChannelPreferences channel_preferences(channel_pref_query[0]);
+
pqxx::result user_query =
work->exec("SELECT * FROM users WHERE alias_id = " +
std::to_string(irc_message.sender.id));
@@ -87,8 +111,8 @@ namespace bot::command {
delete work;
if (parts.empty()) {
- Request req{command_id, std::nullopt, std::nullopt, irc_message,
- channel, user, conn};
+ Request req{command_id, std::nullopt, std::nullopt, irc_message,
+ channel, channel_preferences, user, conn};
return req;
}
@@ -105,8 +129,8 @@ namespace bot::command {
message = std::nullopt;
}
- Request req{command_id, subcommand_id, message, irc_message,
- channel, user, conn};
+ Request req{command_id, subcommand_id, message, irc_message,
+ channel, channel_preferences, user, conn};
return req;
}
}