limit spam
This commit is contained in:
		| @@ -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 | ||||||
|   | |||||||
| @@ -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,27 +177,51 @@ float RPBot::doAllIdle(float time_delta) { | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		state.timeout -= time_delta; | 		state.timeout -= time_delta; | ||||||
| 		if (state.timeout <= 0.f) { | 		if (state.timeout > 0.f) { | ||||||
| 			std::cout << "RPBot: idle timed out\n"; | 			return; | ||||||
| 			// TODO: use multiprompt and better system promp to start immediatly | 		} | ||||||
| 			// TODO: per id min_messages | 		std::cout << "RPBot: idle timed out\n"; | ||||||
| 			if (auto* mreg = _rmm.get(c); mreg != nullptr && mreg->view<Message::Components::MessageText>().size() >= _conf.get_int("RPBot", "min_messages").value_or(4)) { |  | ||||||
| 				to_remove_stateidle.push_back(c); |  | ||||||
| 				min_tick_interval = 0.1f; |  | ||||||
|  |  | ||||||
| 				// transition to Next | 		// TODO: use multi-shot-prompt and better system promp to start immediatly | ||||||
| 				emplaceStateTransition<StateNextActor>(_cr, c, state); | 		auto* mreg = _rmm.get(c); | ||||||
| 			} else { | 		if (mreg != nullptr) { | ||||||
| 				// check-in in another 15-45s | 			// TODO: per id min_messages | ||||||
| 				state.timeout = std::uniform_real_distribution<>{15.f, 45.f}(_rng); | 			if (mreg->view<Message::Components::MessageText>().size() >= _conf.get_int("RPBot", "min_messages").value_or(4)) { | ||||||
| 				std::cout << "RPBot: not ready yet, back to ideling\n"; | 				// maximum amount of messages the bot can send, before someone else needs to send a message | ||||||
| 				if (mreg == nullptr) { | 				// TODO: per id max_cont_messages | ||||||
| 					std::cout << "mreg is null\n"; | 				const size_t max_cont_messages = _conf.get_int("RPBot", "max_cont_messages").value_or(4); | ||||||
| 				} else { | 				auto tmp_view = mreg->view<Message::Components::Timestamp, Message::Components::MessageText, Message::Components::ContactFrom>(); | ||||||
| 					std::cout << "size(): " << mreg->view<Message::Components::MessageText>().size() << "\n"; | 				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); | ||||||
|  | 					min_tick_interval = 0.1f; | ||||||
|  |  | ||||||
|  | 					// transition to Next | ||||||
|  | 					emplaceStateTransition<StateNextActor>(_cr, c, state); | ||||||
|  | 					return; | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		// if not handled yet | ||||||
|  | 		// check-in in another 15-45s | ||||||
|  | 		state.timeout = std::uniform_real_distribution<>{15.f, 45.f}(_rng); | ||||||
|  | 		std::cout << "RPBot: not ready yet, back to ideling\n"; | ||||||
|  | 		if (mreg == nullptr) { | ||||||
|  | 			std::cout << "mreg is null\n"; | ||||||
|  | 		} else { | ||||||
|  | 			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()); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user