summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-04-21 01:43:16 +0500
committerilotterytea <iltsu@alright.party>2024-04-21 01:43:16 +0500
commitd75a5081c57c06e261b040a39078257a141864dd (patch)
tree7481cde4cfc3c8dd695d9728b2f3b983871a974d /src/irc
parentedcf0fd1b942531ac0c6a6442fa5ad21096fe218 (diff)
feat: message handlers
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/client.hpp16
-rw-r--r--src/irc/message.hpp9
2 files changed, 25 insertions, 0 deletions
diff --git a/src/irc/client.hpp b/src/irc/client.hpp
index e6846d2..6f0791f 100644
--- a/src/irc/client.hpp
+++ b/src/irc/client.hpp
@@ -4,6 +4,8 @@
#include <string>
+#include "message.hpp"
+
namespace RedpilledBot {
namespace IRC {
class Client {
@@ -13,6 +15,17 @@ namespace RedpilledBot {
void run();
+ template <MessageType T>
+ void on(typename MessageHandler<T>::fn function) {
+ switch (T) {
+ case Privmsg:
+ this->onPrivmsg = function;
+ break;
+ default:
+ break;
+ }
+ }
+
private:
void authorize();
@@ -23,6 +36,9 @@ namespace RedpilledBot {
std::string port;
ix::WebSocket websocket;
+
+ // Message handlers
+ typename MessageHandler<MessageType::Privmsg>::fn onPrivmsg;
};
}
}
diff --git a/src/irc/message.hpp b/src/irc/message.hpp
index b0ae353..23bbe29 100644
--- a/src/irc/message.hpp
+++ b/src/irc/message.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <functional>
#include <optional>
#include <sstream>
#include <string>
@@ -94,5 +95,13 @@ namespace RedpilledBot {
return std::nullopt;
}
+ template <MessageType T>
+ struct MessageHandler;
+
+ template <>
+ struct MessageHandler<MessageType::Privmsg> {
+ using fn = std::function<void(Message<Privmsg> message)>;
+ };
+
}
}