diff --git a/flake.nix b/flake.nix index 325960d..9f09c20 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55ef988..f43e4b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 ) diff --git a/src/config_commands.cpp b/src/config_commands.cpp new file mode 100644 index 0000000..2e8dc48 --- /dev/null +++ b/src/config_commands.cpp @@ -0,0 +1,66 @@ +#include "./managment_commands.hpp" + +#include +#include + +#include "./message_command_dispatcher.hpp" + +#include +#include + +#include + +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().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 + ); +} + diff --git a/src/config_commands.hpp b/src/config_commands.hpp new file mode 100644 index 0000000..578f4d4 --- /dev/null +++ b/src/config_commands.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +// fwd +class MessageCommandDispatcher; +struct ConfigModelI; + +void registerConfigCommands( + MessageCommandDispatcher& mcd, + ConfigModelI& conf, + Contact3Registry& cr, + RegistryMessageModel& rmm +); + diff --git a/src/main.cpp b/src/main.cpp index 0c0d129..1616012 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ #include "./message_command_dispatcher.hpp" #include "./managment_commands.hpp" +#include "./config_commands.hpp" #include "./tox_commands.hpp" //#include @@ -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(); diff --git a/src/message_command_dispatcher.cpp b/src/message_command_dispatcher.cpp index 338e43a..c992e85 100644 --- a/src/message_command_dispatcher.cpp +++ b/src/message_command_dispatcher.cpp @@ -246,6 +246,7 @@ bool MessageCommandDispatcher::onEvent(const Message::Events::MessageConstruct& std::string_view message_text = e.e.get().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);