From a28e803f43bbf0f263df6ec4100bf0b1f1deb4bf Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 21 Apr 2024 16:03:34 +0500 Subject: feat: instance bundle --- src/bundle.hpp | 11 +++++++++++ src/commands/command.cpp | 7 +++++-- src/commands/command.hpp | 9 ++++++--- src/modules/ping.hpp | 6 ++++-- 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 src/bundle.hpp diff --git a/src/bundle.hpp b/src/bundle.hpp new file mode 100644 index 0000000..fa8d80a --- /dev/null +++ b/src/bundle.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "irc/client.hpp" +#include "localization/localization.hpp" + +namespace bot { + struct InstanceBundle { + const irc::Client &irc_client; + const bot::loc::Localization &localization; + }; +} diff --git a/src/commands/command.cpp b/src/commands/command.cpp index b6852cc..9d6ec6a 100644 --- a/src/commands/command.cpp +++ b/src/commands/command.cpp @@ -4,6 +4,7 @@ #include #include +#include "../bundle.hpp" #include "../modules/ping.hpp" namespace bot { @@ -17,10 +18,12 @@ namespace bot { } std::optional, std::string>> - CommandLoader::run(const irc::Message &msg) { + CommandLoader::run( + const InstanceBundle &bundle, + const irc::Message &msg) const { for (const std::unique_ptr &command : this->commands) { if (command->get_name() == msg.message) { - return command->run(msg); + return command->run(bundle, msg); } } diff --git a/src/commands/command.hpp b/src/commands/command.hpp index 0266301..5f69788 100644 --- a/src/commands/command.hpp +++ b/src/commands/command.hpp @@ -6,15 +6,17 @@ #include #include +#include "../bundle.hpp" #include "../irc/message.hpp" namespace bot { namespace command { class Command { public: - virtual std::string get_name() = 0; + virtual std::string get_name() const = 0; virtual std::variant, std::string> run( - const irc::Message &msg) = 0; + const InstanceBundle &bundle, + const irc::Message &msg) const = 0; }; class CommandLoader { @@ -24,7 +26,8 @@ namespace bot { void add_command(std::unique_ptr cmd); std::optional, std::string>> run( - const irc::Message &msg); + const InstanceBundle &bundle, + const irc::Message &msg) const; const std::vector> &get_commands() const { return this->commands; diff --git a/src/modules/ping.hpp b/src/modules/ping.hpp index cf59d66..033f93a 100644 --- a/src/modules/ping.hpp +++ b/src/modules/ping.hpp @@ -4,15 +4,17 @@ #include #include +#include "../bundle.hpp" #include "../commands/command.hpp" namespace bot { namespace mod { class Ping : public command::Command { - std::string get_name() override { return "ping"; } + std::string get_name() const override { return "ping"; } std::variant, std::string> run( - const irc::Message &msg) override { + const InstanceBundle &bundle, + const irc::Message &msg) const override { return "pong"; } }; -- cgit v1.2.3