diff options
| author | ilotterytea <iltsu@alright.party> | 2024-04-21 02:09:16 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-04-21 02:09:16 +0500 |
| commit | aa21312f18ef86a335dd28272e317da959ceb9b7 (patch) | |
| tree | 038a13e38e06a4199c6af9a86bff39963be5c449 | |
| parent | f2c9182dba4cbd95d7f865efddd45c592f8623bf (diff) | |
upd: renamed namespaces + added utils namespace
| -rw-r--r-- | src/irc/client.cpp | 5 | ||||
| -rw-r--r-- | src/irc/client.hpp | 4 | ||||
| -rw-r--r-- | src/irc/message.cpp | 6 | ||||
| -rw-r--r-- | src/irc/message.hpp | 14 | ||||
| -rw-r--r-- | src/main.cpp | 2 | ||||
| -rw-r--r-- | src/utils/string.cpp | 54 | ||||
| -rw-r--r-- | src/utils/string.hpp | 15 |
7 files changed, 59 insertions, 41 deletions
diff --git a/src/irc/client.cpp b/src/irc/client.cpp index 2d07070..e08d243 100644 --- a/src/irc/client.cpp +++ b/src/irc/client.cpp @@ -11,7 +11,7 @@ #include "message.hpp" -using namespace RedpilledBot::IRC; +using namespace bot::irc; Client::Client(std::string username, std::string password) { this->username = username; @@ -30,7 +30,8 @@ void Client::run() { case ix::WebSocketMessageType::Message: { std::cout << "Got a message: " << msg->str << std::endl; - std::vector<std::string> lines = split_text(msg->str, '\n'); + std::vector<std::string> lines = + utils::string::split_text(msg->str, '\n'); for (std::string &line : lines) { line.erase(std::remove_if(line.begin(), line.end(), diff --git a/src/irc/client.hpp b/src/irc/client.hpp index 6f0791f..eec233c 100644 --- a/src/irc/client.hpp +++ b/src/irc/client.hpp @@ -6,8 +6,8 @@ #include "message.hpp" -namespace RedpilledBot { - namespace IRC { +namespace bot { + namespace irc { class Client { public: Client(std::string username, std::string password); diff --git a/src/irc/message.cpp b/src/irc/message.cpp index 123a0da..569e691 100644 --- a/src/irc/message.cpp +++ b/src/irc/message.cpp @@ -4,10 +4,10 @@ #include <string> #include <vector> -namespace RedpilledBot { - namespace IRC { +namespace bot { + namespace irc { std::optional<MessageType> define_message_type(const std::string &msg) { - std::vector<std::string> parts = split_text(msg, ' '); + std::vector<std::string> parts = utils::string::split_text(msg, ' '); int i; if (msg[0] == '@') { diff --git a/src/irc/message.hpp b/src/irc/message.hpp index 23bbe29..94541a6 100644 --- a/src/irc/message.hpp +++ b/src/irc/message.hpp @@ -8,8 +8,8 @@ #include "../utils/string.hpp" -namespace RedpilledBot { - namespace IRC { +namespace bot { + namespace irc { enum MessageType { Privmsg, Notice }; std::optional<MessageType> define_message_type(const std::string &msg); @@ -38,7 +38,7 @@ namespace RedpilledBot { template <MessageType T> std::optional<Message<T>> parse_message(const std::string &msg) { - std::vector<std::string> parts = split_text(msg, ' '); + std::vector<std::string> parts = utils::string::split_text(msg, ' '); if (T == MessageType::Privmsg) { MessageSender sender; @@ -53,7 +53,8 @@ namespace RedpilledBot { std::string user = parts[0]; user = user.substr(1, user.length()); - std::vector<std::string> user_parts = split_text(user, '!'); + std::vector<std::string> user_parts = + utils::string::split_text(user, '!'); sender.login = user_parts[0]; @@ -64,10 +65,11 @@ namespace RedpilledBot { parts.erase(parts.begin()); - std::string chat_message = join_vector(parts, ' '); + std::string chat_message = utils::string::join_vector(parts, ' '); message.message = chat_message.substr(1, chat_message.length()); - std::vector<std::string> tags_parts = split_text(tags, ';'); + std::vector<std::string> tags_parts = + utils::string::split_text(tags, ';'); for (const std::string &tag : tags_parts) { std::istringstream iss(tag); diff --git a/src/main.cpp b/src/main.cpp index 3e13f5c..b940d1d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,7 @@ int main(int argc, char *argv[]) { std::cout << "hi world\n"; - RedpilledBot::IRC::Client client("", ""); + bot::irc::Client client("", ""); client.run(); diff --git a/src/utils/string.cpp b/src/utils/string.cpp index 41e4224..8a4c1cc 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -4,37 +4,45 @@ #include <string> #include <vector> -std::vector<std::string> split_text(const std::string &text, char delimiter) { - std::vector<std::string> parts; +namespace bot { + namespace utils { + namespace string { + std::vector<std::string> split_text(const std::string &text, + char delimiter) { + std::vector<std::string> parts; - std::istringstream iss(text); - std::string part; + std::istringstream iss(text); + std::string part; - while (std::getline(iss, part, delimiter)) { - parts.push_back(part); - } + while (std::getline(iss, part, delimiter)) { + parts.push_back(part); + } - return parts; -} + return parts; + } -std::string join_vector(const std::vector<std::string> &vec, char delimiter) { - std::string str; + std::string join_vector(const std::vector<std::string> &vec, + char delimiter) { + std::string str; - for (auto i = vec.begin(); i != vec.end() - 1; i++) { - str += *i + delimiter; - } + for (auto i = vec.begin(); i != vec.end() - 1; i++) { + str += *i + delimiter; + } - str += vec[vec.size() - 1]; + str += vec[vec.size() - 1]; - return str; -} + return str; + } -std::string join_vector(const std::vector<std::string> &vec) { - std::string str; + std::string join_vector(const std::vector<std::string> &vec) { + std::string str; - for (const auto &e : vec) { - str += e; - } + for (const auto &e : vec) { + str += e; + } - return str; + return str; + } + } + } } diff --git a/src/utils/string.hpp b/src/utils/string.hpp index 16888d0..fe0610b 100644 --- a/src/utils/string.hpp +++ b/src/utils/string.hpp @@ -3,7 +3,14 @@ #include <string> #include <vector> -std::vector<std::string> split_text(const std::string &text, char delimiter); - -std::string join_vector(const std::vector<std::string> &vec, char delimiter); -std::string join_vector(const std::vector<std::string> &vec); +namespace bot { + namespace utils { + namespace string { + std::vector<std::string> split_text(const std::string &text, + char delimiter); + std::string join_vector(const std::vector<std::string> &vec, + char delimiter); + std::string join_vector(const std::vector<std::string> &vec); + } + } +} |
