From 48bfed5c68220e19bb4a2dd0e70cd227c25062e8 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 1 May 2024 01:19:37 +0500 Subject: feat: update user alias name if it has been changed --- src/commands/request_util.cpp | 11 +++++++++++ src/schemas/user.hpp | 3 +++ 2 files changed, 14 insertions(+) (limited to 'src') diff --git a/src/commands/request_util.cpp b/src/commands/request_util.cpp index 77d94bc..8ac2471 100644 --- a/src/commands/request_util.cpp +++ b/src/commands/request_util.cpp @@ -106,6 +106,17 @@ namespace bot::command { schemas::User user(query[0]); + if (user.get_alias_name() != irc_message.sender.login) { + work->exec("UPDATE users SET alias_name = '" + irc_message.sender.login + + "' WHERE id = " + std::to_string(user.get_id())); + work->commit(); + + delete work; + work = new pqxx::work(conn); + + user.set_alias_name(irc_message.sender.login); + } + schemas::PermissionLevel level = schemas::PermissionLevel::USER; const auto &badges = irc_message.sender.badges; diff --git a/src/schemas/user.hpp b/src/schemas/user.hpp index a5f3238..443dde9 100644 --- a/src/schemas/user.hpp +++ b/src/schemas/user.hpp @@ -49,6 +49,9 @@ namespace bot::schemas { const int &get_id() const { return this->id; } const int &get_alias_id() const { return this->alias_id; } const std::string &get_alias_name() const { return this->alias_name; } + void set_alias_name(const std::string &alias_name) { + this->alias_name = alias_name; + } const std::chrono::system_clock::time_point &get_joined_at() const { return this->joined_at; } -- cgit v1.2.3