From dd188b36802ffcb6547c048b5e2eabfcf918a554 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 10 Mar 2025 22:45:50 +0100 Subject: [PATCH] port to contact4 --- plugins/plugin_sdbot-webui.cpp | 6 ++++-- src/sd_bot.cpp | 23 +++++++++++++---------- src/sd_bot.hpp | 10 +++++----- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/plugins/plugin_sdbot-webui.cpp b/plugins/plugin_sdbot-webui.cpp index 6e60707..3d0bcce 100644 --- a/plugins/plugin_sdbot-webui.cpp +++ b/plugins/plugin_sdbot-webui.cpp @@ -1,5 +1,7 @@ #include +#include + #include "../src/sd_bot.hpp" #include @@ -32,13 +34,13 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) } try { - auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1"); + auto* cs = PLUG_RESOLVE_INSTANCE(ContactStore4I); auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI); auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI); // static store, could be anywhere tho // construct with fetched dependencies - g_sdbot = std::make_unique(*cr, *rmm, *conf); + g_sdbot = std::make_unique(*cs, *rmm, *conf); // register types PLUG_PROVIDE_INSTANCE(SDBot, plugin_name, g_sdbot.get()); diff --git a/src/sd_bot.cpp b/src/sd_bot.cpp index 410e9b9..128de20 100644 --- a/src/sd_bot.cpp +++ b/src/sd_bot.cpp @@ -1,6 +1,7 @@ #include "./sd_bot.hpp" #include +#include #include #include @@ -17,7 +18,7 @@ struct Automatic1111_v1_Endpoint : public SDBot::EndpointI { Automatic1111_v1_Endpoint(RegistryMessageModelI& rmm, std::default_random_engine& rng) : SDBot::EndpointI(rmm, rng) {} - bool handleResponse(Contact3 contact, ByteSpan data) override { + bool handleResponse(Contact4 contact, ByteSpan data) override { //std::cout << std::string_view{reinterpret_cast(data.ptr), data.size} << "\n"; // extract json result @@ -63,7 +64,7 @@ struct Automatic1111_v1_Endpoint : public SDBot::EndpointI { struct SDcpp_wip1_Endpoint : public SDBot::EndpointI { SDcpp_wip1_Endpoint(RegistryMessageModelI& rmm, std::default_random_engine& rng) : SDBot::EndpointI(rmm, rng) {} - bool handleResponse(Contact3 contact, ByteSpan data) override { + bool handleResponse(Contact4 contact, ByteSpan data) override { //std::cout << std::string_view{reinterpret_cast(data.ptr), data.size} << "\n"; std::string_view data_str {reinterpret_cast(data.ptr), data.size}; @@ -132,7 +133,7 @@ struct SDcpp_wip1_Endpoint : public SDBot::EndpointI { struct SDcpp_stduhpf_wip1_Endpoint : public SDBot::EndpointI { SDcpp_stduhpf_wip1_Endpoint(RegistryMessageModelI& rmm, std::default_random_engine& rng) : SDBot::EndpointI(rmm, rng) {} - bool handleResponse(Contact3 contact, ByteSpan data) override { + bool handleResponse(Contact4 contact, ByteSpan data) override { bool succ = true; try { @@ -201,10 +202,10 @@ struct SDcpp_stduhpf_wip1_Endpoint : public SDBot::EndpointI { }; SDBot::SDBot( - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm, ConfigModelI& conf -) : _cr(cr), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _conf(conf) { +) : _cs(cs), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _conf(conf) { _rng.seed(std::random_device{}()); _rng.discard(3137); @@ -415,7 +416,9 @@ bool SDBot::onEvent(const Message::Events::MessageConstruct& e) { const auto contact_to = e.e.get().c; const auto contact_from = e.e.get().c; - const bool is_private = _cr.any_of(contact_to); + const auto& cr = _cs.registry(); + + const bool is_private = cr.any_of(contact_to); if (is_private) { std::cout << "SDB private message " << message_text << " (l:" << message_text.size() << ")\n"; @@ -425,13 +428,13 @@ bool SDBot::onEvent(const Message::Events::MessageConstruct& e) { _prompt_queue.push(std::make_pair(uint64_t{id}, std::string{message_text})); } } else { - assert(_cr.all_of(contact_to)); - const auto contact_self = _cr.get(contact_to).self; - if (!_cr.all_of(contact_self)) { + assert(cr.all_of(contact_to)); + const auto contact_self = cr.get(contact_to).self; + if (!cr.all_of(contact_self)) { std::cerr << "SDB error: dont have self name\n"; return false; } - const auto& self_name = _cr.get(contact_self).name; + const auto& self_name = cr.get(contact_self).name; const auto self_prefix = self_name + ": "; diff --git a/src/sd_bot.hpp b/src/sd_bot.hpp index d01d390..7abc9ff 100644 --- a/src/sd_bot.hpp +++ b/src/sd_bot.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include @@ -19,7 +19,7 @@ struct ConfigModelI; class SDBot : public RegistryMessageModelEventI { - Contact3Registry& _cr; + ContactStore4I& _cs; RegistryMessageModelI& _rmm; RegistryMessageModelI::SubscriptionReference _rmm_sr; ConfigModelI& _conf; @@ -27,7 +27,7 @@ class SDBot : public RegistryMessageModelEventI { //TransferManager& _tm; //std::map> _task_map; - std::map _task_map; + std::map _task_map; std::queue> _prompt_queue; uint64_t _last_task_counter = 0; @@ -44,7 +44,7 @@ class SDBot : public RegistryMessageModelEventI { EndpointI(RegistryMessageModelI& rmm, std::default_random_engine& rng) : _rmm(rmm), _rng(rng) {} virtual ~EndpointI(void) {} - virtual bool handleResponse(Contact3 contact, ByteSpan data) = 0; + virtual bool handleResponse(Contact4 contact, ByteSpan data) = 0; }; private: @@ -52,7 +52,7 @@ class SDBot : public RegistryMessageModelEventI { public: SDBot( - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm, ConfigModelI& conf );