fix group messages and start config commands (disabled for now)
This commit is contained in:
@ -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
66
src/config_commands.cpp
Normal 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
16
src/config_commands.hpp
Normal 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
|
||||
);
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user