port to contact4
This commit is contained in:
parent
3dd500e202
commit
dd188b3680
@ -1,5 +1,7 @@
|
||||
#include <solanaceae/plugin/solana_plugin_v1.h>
|
||||
|
||||
#include <solanaceae/contact/contact_store_i.hpp>
|
||||
|
||||
#include "../src/sd_bot.hpp"
|
||||
|
||||
#include <solanaceae/util/config_model.hpp>
|
||||
@ -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<SDBot>(*cr, *rmm, *conf);
|
||||
g_sdbot = std::make_unique<SDBot>(*cs, *rmm, *conf);
|
||||
|
||||
// register types
|
||||
PLUG_PROVIDE_INSTANCE(SDBot, plugin_name, g_sdbot.get());
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "./sd_bot.hpp"
|
||||
|
||||
#include <solanaceae/util/config_model.hpp>
|
||||
#include <solanaceae/contact/contact_store_i.hpp>
|
||||
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
#include <solanaceae/message3/components.hpp>
|
||||
@ -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<const char*>(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<const char*>(data.ptr), data.size} << "\n";
|
||||
|
||||
std::string_view data_str {reinterpret_cast<const char*>(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<Message::Components::ContactTo>().c;
|
||||
const auto contact_from = e.e.get<Message::Components::ContactFrom>().c;
|
||||
|
||||
const bool is_private = _cr.any_of<Contact::Components::TagSelfWeak, Contact::Components::TagSelfStrong>(contact_to);
|
||||
const auto& cr = _cs.registry();
|
||||
|
||||
const bool is_private = cr.any_of<Contact::Components::TagSelfWeak, Contact::Components::TagSelfStrong>(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::Components::Self>(contact_to));
|
||||
const auto contact_self = _cr.get<Contact::Components::Self>(contact_to).self;
|
||||
if (!_cr.all_of<Contact::Components::Name>(contact_self)) {
|
||||
assert(cr.all_of<Contact::Components::Self>(contact_to));
|
||||
const auto contact_self = cr.get<Contact::Components::Self>(contact_to).self;
|
||||
if (!cr.all_of<Contact::Components::Name>(contact_self)) {
|
||||
std::cerr << "SDB error: dont have self name\n";
|
||||
return false;
|
||||
}
|
||||
const auto& self_name = _cr.get<Contact::Components::Name>(contact_self).name;
|
||||
const auto& self_name = cr.get<Contact::Components::Name>(contact_self).name;
|
||||
|
||||
const auto self_prefix = self_name + ": ";
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <solanaceae/util/span.hpp>
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
#include <solanaceae/contact/contact_model3.hpp>
|
||||
#include <solanaceae/contact/fwd.hpp>
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
@ -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<uint64_t, std::variant<ContactFriend, ContactConference, ContactGroupPeer>> _task_map;
|
||||
std::map<uint64_t, Contact3> _task_map;
|
||||
std::map<uint64_t, Contact4> _task_map;
|
||||
std::queue<std::pair<uint64_t, std::string>> _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
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user