mirror of
https://gitlab.com/niansa/reaktor.git
synced 2025-03-06 20:53:30 +01:00
Use a much better pseudo random generator
This commit is contained in:
parent
96408d7820
commit
204a742c73
2 changed files with 8 additions and 3 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 41f58e36cf77139398f2a37213b13f38f4593722
|
||||
Subproject commit d0a9401a54212533be1ee752d87f5ee023c2dbb6
|
9
main.cpp
9
main.cpp
|
@ -12,6 +12,7 @@
|
|||
#include <colorama.hpp>
|
||||
#include <commoncpp/utils.hpp>
|
||||
#include <commoncpp/timer.hpp>
|
||||
#include <commoncpp/random.hpp>
|
||||
#include <commoncpp/pooled_thread.hpp>
|
||||
|
||||
|
||||
|
@ -228,6 +229,10 @@ void run(const std::string& token, const std::string& model_path, const std::str
|
|||
bot.on_log(dpp::utility::cout_logger());
|
||||
bot.intents |= dpp::i_guild_messages | dpp::i_message_content | dpp::i_guild_voice_states;
|
||||
|
||||
// Create random generator
|
||||
common::RandomGenerator rng;
|
||||
rng.seed();
|
||||
|
||||
#ifdef REAKTOR_WITH_CHAT
|
||||
// Message generator
|
||||
ChatMessageGenerateContext genCtx;
|
||||
|
@ -255,7 +260,7 @@ void run(const std::string& token, const std::string& model_path, const std::str
|
|||
ok = chat_message_add(chatModel.get(), msg.author.username, msg.content);
|
||||
if (!ok) return;
|
||||
// Skip if not mentioned and random chance
|
||||
if (!mentioned && time_t(event.msg.id.get_creation_time()) % 18) return;
|
||||
if (!mentioned && rng.getBool(0.125f)) return;
|
||||
// Create initial message
|
||||
auto new_msg = bot.message_create_sync(dpp::message(msg.channel_id, "⠀"));
|
||||
bot.channel_typing(new_msg.channel_id);
|
||||
|
@ -280,7 +285,7 @@ void run(const std::string& token, const std::string& model_path, const std::str
|
|||
// Only react to messages that are sufficiently long
|
||||
if (event.msg.content.size() < 34) return;
|
||||
// Only react to approx. every 10th message
|
||||
if (time_t(event.msg.id.get_creation_time()) % 20 && last_reaction_timer.get<std::chrono::hours>() < 2) return;
|
||||
if (rng.getBool(0.1f) && last_reaction_timer.get<std::chrono::hours>() < 2) return;
|
||||
// Get shortened message content
|
||||
std::string content{event.msg.content.data(), std::min<size_t>(event.msg.content.size(), 160)};
|
||||
// Move to another thread
|
||||
|
|
Loading…
Add table
Reference in a new issue