summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-04-30 21:44:46 +0500
committerilotterytea <iltsu@alright.party>2024-04-30 21:44:46 +0500
commita1136494fbee133af36f6580125c9c7af9e1be45 (patch)
tree8dbd691190d057713d15a01a221c0c66dee7c8b8 /src
parentc7d93fd7c54145fa248e87930124fbc10367845d (diff)
feat: added User model into Request struct
Diffstat (limited to 'src')
-rw-r--r--src/commands/request.hpp2
-rw-r--r--src/commands/request_util.cpp28
2 files changed, 27 insertions, 3 deletions
diff --git a/src/commands/request.hpp b/src/commands/request.hpp
index 6149dee..702fcb8 100644
--- a/src/commands/request.hpp
+++ b/src/commands/request.hpp
@@ -6,6 +6,7 @@
#include "../irc/message.hpp"
#include "../schemas/channel.hpp"
+#include "../schemas/user.hpp"
namespace bot::command {
struct Request {
@@ -15,6 +16,7 @@ namespace bot::command {
const irc::Message<irc::MessageType::Privmsg> &irc_message;
schemas::Channel channel;
+ schemas::User user;
pqxx::connection &conn;
};
diff --git a/src/commands/request_util.cpp b/src/commands/request_util.cpp
index a0965c3..94e563d 100644
--- a/src/commands/request_util.cpp
+++ b/src/commands/request_util.cpp
@@ -63,11 +63,32 @@ namespace bot::command {
schemas::Channel channel(channel_query[0]);
+ pqxx::result user_query =
+ work->exec("SELECT * FROM users WHERE alias_id = " +
+ std::to_string(irc_message.sender.id));
+
+ // Create new user data in the database if it didn't exist before
+ if (user_query.empty()) {
+ work->exec("INSERT INTO users (alias_id, alias_name) VALUES (" +
+ std::to_string(irc_message.sender.id) + ", '" +
+ irc_message.sender.login + "')");
+
+ work->commit();
+
+ delete work;
+ work = new pqxx::work(conn);
+
+ user_query = work->exec("SELECT * FROM users WHERE alias_id = " +
+ std::to_string(irc_message.sender.id));
+ }
+
+ schemas::User user(user_query[0]);
+
delete work;
if (parts.empty()) {
- Request req{command_id, std::nullopt, std::nullopt,
- irc_message, channel, conn};
+ Request req{command_id, std::nullopt, std::nullopt, irc_message,
+ channel, user, conn};
return req;
}
@@ -84,7 +105,8 @@ namespace bot::command {
message = std::nullopt;
}
- Request req{command_id, subcommand_id, message, irc_message, channel, conn};
+ Request req{command_id, subcommand_id, message, irc_message,
+ channel, user, conn};
return req;
}
}