limit spam

This commit is contained in:
Green Sky 2024-02-06 23:03:57 +01:00
parent 8dbbe7a76d
commit d0dfe6b121
No known key found for this signature in database
2 changed files with 53 additions and 18 deletions

View File

@ -16,7 +16,7 @@ TODO: move rpbot to own repo
- `RPBot`, `system_prompt`(, opt contact ID) - `RPBot`, `system_prompt`(, opt contact ID)
- type: `string` - type: `string`
- System prompt that is prefixed - System prompt that is prefixed
- can contain spcific formatters - can contain specific formatters:
- `{self_name}` username for specified chat - `{self_name}` username for specified chat
- default: `Transcript of a group chat, where {self_name} talks to online strangers.\n{self_name} is creative and curious. {self_name} is writing with precision, but also with occasional typos.\n` - default: `Transcript of a group chat, where {self_name} talks to online strangers.\n{self_name} is creative and curious. {self_name} is writing with precision, but also with occasional typos.\n`
@ -25,6 +25,11 @@ TODO: move rpbot to own repo
- TODO: implement per ID - TODO: implement per ID
- default: `4` - default: `4`
- `RPBot`, `max_cont_messages`(, opt contact ID)
- type: `int`
- TODO: implement per ID
- default: '4'
- `RPBot`, `max_interactive_delay`(, opt contact ID) - `RPBot`, `max_interactive_delay`(, opt contact ID)
- type: `float` - type: `float`
- TODO: implement per ID - TODO: implement per ID

View File

@ -48,6 +48,12 @@ void RPBot::stateTransition(const Contact3 c, const StateIdle& from, StateNextAc
return; return;
} }
if (mpb.names.size() < 2) {
// early exit for too small groups
to.future = std::async(std::launch::async, [self]() -> int64_t { return -10; });
return;
}
{ // - system promp (needs self name etc) { // - system promp (needs self name etc)
if (const auto* id_comp = _cr.try_get<Contact::Components::ID>(c); id_comp != nullptr) { if (const auto* id_comp = _cr.try_get<Contact::Components::ID>(c); id_comp != nullptr) {
const auto id_hex = bin2hex(id_comp->data); const auto id_hex = bin2hex(id_comp->data);
@ -171,17 +177,43 @@ float RPBot::doAllIdle(float time_delta) {
} }
state.timeout -= time_delta; state.timeout -= time_delta;
if (state.timeout <= 0.f) { if (state.timeout > 0.f) {
return;
}
std::cout << "RPBot: idle timed out\n"; std::cout << "RPBot: idle timed out\n";
// TODO: use multiprompt and better system promp to start immediatly
// TODO: use multi-shot-prompt and better system promp to start immediatly
auto* mreg = _rmm.get(c);
if (mreg != nullptr) {
// TODO: per id min_messages // TODO: per id min_messages
if (auto* mreg = _rmm.get(c); mreg != nullptr && mreg->view<Message::Components::MessageText>().size() >= _conf.get_int("RPBot", "min_messages").value_or(4)) { if (mreg->view<Message::Components::MessageText>().size() >= _conf.get_int("RPBot", "min_messages").value_or(4)) {
// maximum amount of messages the bot can send, before someone else needs to send a message
// TODO: per id max_cont_messages
const size_t max_cont_messages = _conf.get_int("RPBot", "max_cont_messages").value_or(4);
auto tmp_view = mreg->view<Message::Components::Timestamp, Message::Components::MessageText, Message::Components::ContactFrom>();
tmp_view.use<Message::Components::Timestamp>();
bool other_sender {false};
auto view_it = tmp_view.begin(), view_last = tmp_view.end();
for (size_t i = 0; i < max_cont_messages && view_it != view_last; view_it++, i++) {
// TODO: also test for weak self?
if (!_cr.any_of<Contact::Components::TagSelfStrong>(tmp_view.get<Message::Components::ContactFrom>(*view_it).c)) {
other_sender = true;
break;
}
}
if (other_sender) {
to_remove_stateidle.push_back(c); to_remove_stateidle.push_back(c);
min_tick_interval = 0.1f; min_tick_interval = 0.1f;
// transition to Next // transition to Next
emplaceStateTransition<StateNextActor>(_cr, c, state); emplaceStateTransition<StateNextActor>(_cr, c, state);
} else { return;
}
}
}
// if not handled yet
// check-in in another 15-45s // check-in in another 15-45s
state.timeout = std::uniform_real_distribution<>{15.f, 45.f}(_rng); state.timeout = std::uniform_real_distribution<>{15.f, 45.f}(_rng);
std::cout << "RPBot: not ready yet, back to ideling\n"; std::cout << "RPBot: not ready yet, back to ideling\n";
@ -190,8 +222,6 @@ float RPBot::doAllIdle(float time_delta) {
} else { } else {
std::cout << "size(): " << mreg->view<Message::Components::MessageText>().size() << "\n"; std::cout << "size(): " << mreg->view<Message::Components::MessageText>().size() << "\n";
} }
}
}
}); });
_cr.remove<StateIdle>(to_remove_stateidle.cbegin(), to_remove_stateidle.cend()); _cr.remove<StateIdle>(to_remove_stateidle.cbegin(), to_remove_stateidle.cend());