fix group messages and start config commands (disabled for now)

This commit is contained in:
Green Sky 2023-12-14 17:56:52 +01:00
parent 1c10d4da4c
commit 910029bf4f
No known key found for this signature in database
6 changed files with 94 additions and 5 deletions

View File

@ -27,8 +27,8 @@
};
solanaceae_util-src = pkgs.fetchFromGitHub {
owner = "Green-Sky"; repo = "solanaceae_util";
rev = "57d7178e76b41c5d0f8117fc8fb5791b4108cdc0";
hash = "sha256-CjBj1iYlJsLMsZvp857FrsmStV4AJ7SD7L+hzOgZMpg=";
rev = "2b20c2d2a45ad1005e794c704b3fc831ca1d3830";
hash = "sha256-eLDIFQOA3NjdjK1MPpdNJl9mYQgtJK9IV4CaOyenae8=";
};
solanaceae_contact-src = pkgs.fetchFromGitHub {
owner = "Green-Sky"; repo = "solanaceae_contact";
@ -37,8 +37,8 @@
};
solanaceae_message3-src = pkgs.fetchFromGitHub {
owner = "Green-Sky"; repo = "solanaceae_message3";
rev = "48fb5f0889404370006ae12b3637a77d7d4ba485";
hash = "sha256-kFA90EpAH/BciHDD7NwZs7KL1cDcGVQZCRjOazxMbvM=";
rev = "1a036c2321e06d4c36f3e2148e67dfe6aa379296";
hash = "sha256-vcUN7tsy6E1P5juhW7pj9OUtZLytZcpPijlIj/iTBgk=";
};
solanaceae_plugin-src = pkgs.fetchFromGitHub {
owner = "Green-Sky"; repo = "solanaceae_plugin";

View File

@ -18,6 +18,9 @@ add_executable(totato
./managment_commands.hpp
./managment_commands.cpp
./config_commands.hpp
./config_commands.cpp
./tox_commands.hpp
./tox_commands.cpp
)

66
src/config_commands.cpp Normal file
View File

@ -0,0 +1,66 @@
#include "./managment_commands.hpp"
#include <solanaceae/contact/contact_model3.hpp>
#include <solanaceae/util/config_model.hpp>
#include "./message_command_dispatcher.hpp"
#include <solanaceae/message3/components.hpp>
#include <solanaceae/contact/components.hpp>
#include <iostream>
void registerConfigCommands(
MessageCommandDispatcher& mcd,
ConfigModelI& conf,
Contact3Registry& cr,
RegistryMessageModel& rmm
) {
mcd.registerCommand(
"Config", "conf",
"set-string",
[&](std::string_view params, Message3Handle m) -> bool {
// x x x
// 01234
if (params.size() < 5) {
return false;
}
const auto contact_from = m.get<Message::Components::ContactFrom>().c;
// split params into:
// - module
// - category
const auto first_space_pos = params.find_first_of(' ');
// x x x
// 01234
if (first_space_pos >= int64_t(params.size())-2) {
// TODO: error?
return false;
}
const auto second_space_pos = params.find_first_of(' ', first_space_pos+1);
if (second_space_pos >= params.size()-2) {
// TODO: error?
return false;
}
const auto fist_word = params.substr(0, first_space_pos);
const auto second_word = params.substr(first_space_pos+1, second_space_pos);
const auto rest_word = params.substr(second_space_pos+1);
//conf.set("MessageCommandDispatcher", group, params, true);
rmm.sendText(
contact_from,
"he"
);
return true;
},
"Set the config value for a category.",
MessageCommandDispatcher::Perms::ADMIN // yes, always
);
}

16
src/config_commands.hpp Normal file
View File

@ -0,0 +1,16 @@
#pragma once
#include <solanaceae/contact/contact_model3.hpp>
#include <solanaceae/message3/registry_message_model.hpp>
// fwd
class MessageCommandDispatcher;
struct ConfigModelI;
void registerConfigCommands(
MessageCommandDispatcher& mcd,
ConfigModelI& conf,
Contact3Registry& cr,
RegistryMessageModel& rmm
);

View File

@ -16,6 +16,7 @@
#include "./message_command_dispatcher.hpp"
#include "./managment_commands.hpp"
#include "./config_commands.hpp"
#include "./tox_commands.hpp"
//#include <solanaceae/message3/components.hpp>
@ -243,6 +244,8 @@ int main(int argc, char** argv) {
}
registerManagementCommands(mcd, conf, cr, rmm);
// TODO: finish impl
//registerConfigCommands(mcd, conf, cr, rmm);
registerToxCommands(mcd, conf, cr, rmm, tc, tpi);
conf.dump();

View File

@ -246,6 +246,7 @@ bool MessageCommandDispatcher::onEvent(const Message::Events::MessageConstruct&
std::string_view message_text = e.e.get<Message::Components::MessageText>().text;
if (message_text.empty()) {
std::cout << "MCD warning: empty message\n";
// empty message?
return false;
}
@ -258,7 +259,7 @@ bool MessageCommandDispatcher::onEvent(const Message::Events::MessageConstruct&
list.cbegin(), list.cend(),
[this](const auto& it) {
// TODO: add weak self
return _cr.all_of<
return _cr.any_of<
Contact::Components::TagSelfStrong,
Contact::Components::TagSelfWeak // trust weak self
>(it);