Bot bridge: keep a Russian realm in Russian with small models

With qwen2.5:3b on a 6 GB card (Geshka), a Russian player got an English line now and
then, General and Trade posts and street talk were all English, and the first answer
took 41 s while a bots' talk line ran next to it (that talk then timed out).

- A player's answer that should be Russian but is not gets one more ask; if that is
  English too, a short Russian line is said instead (or nothing, for a moment).
- Talk and post events carry the language most real players on that map play in
  ("locale", else the realm's); the program writes them in it and drops an English line
  on a Russian realm.
- Bots' talk waits while any player's answer is being written, and gives up after 20 s
  instead of 45 s.

(cherry picked from commit bc7829815c5bd7a2dc182d2ec576ab4f24603462)
This commit is contained in:
Karrz1
2026-11-11 23:37:46 +00:00
parent b812f5d171
commit 094f1cb8c2
3 changed files with 64 additions and 8 deletions
+25
View File
@@ -1985,6 +1985,29 @@ std::string ClientLocale(Player const* player)
return l < TOTAL_LOCALES ? localeNames[l] : "enUS";
}
// The language most real players on the bot's map play in, for lines no one player asked for (a street talk, a General or
// Trade post): a Russian realm got English posts (Geshka, 2026-11-09). No player there: the realm's own language.
std::string ListenersLocale(Player const* bot)
{
std::array<uint32, TOTAL_LOCALES> count{};
if (Map* map = bot ? bot->GetMap() : nullptr)
for (MapReference const& ref : map->GetPlayers())
{
Player const* p = ref.GetSource();
if (p && p->GetSession() && !Services::Registry().has(p->GetGUID().GetCounter()))
{
LocaleConstant const l = p->GetSession()->GetSessionDbcLocale();
if (l < TOTAL_LOCALES)
++count[l];
}
}
std::size_t best = std::size_t(sWorld->GetDefaultDbcLocale());
for (std::size_t l = 0; l < count.size(); ++l)
if (count[l] > count[best])
best = l;
return best < TOTAL_LOCALES ? localeNames[best] : "enUS";
}
void WriteMoment(ConfigReader::BridgeConfig const& cfg, Moment const& m, uint32 now_ms)
{
Player* bot = FindBot(m.bot);
@@ -2074,6 +2097,7 @@ uint64 WriteChannelTalk(ConfigReader::BridgeConfig const& cfg, Player* bot, uint
e.fields.emplace_back("channel", ChannelWord(channel_id));
e.fields.emplace_back("scene", scene);
e.fields.emplace_back("talk", "");
e.fields.emplace_back("locale", ListenersLocale(bot));
if (!keep.empty())
e.fields.emplace_back("keep", keep);
if (cfg.swearing)
@@ -2407,6 +2431,7 @@ bool BotBridge::AskTalk(Player* bot, std::string const& scene, std::string const
e.fields.emplace_back("channel", "say");
e.fields.emplace_back("scene", scene.size() > 1500 ? scene.substr(0, 1500) : scene);
e.fields.emplace_back("talk", chat.size() > 1500 ? chat.substr(chat.size() - 1500) : chat);
e.fields.emplace_back("locale", ListenersLocale(bot));
if (Services::Config().bridge().swearing)
e.numbers.emplace_back("swearing", 1);
e.fields.emplace_back("weather", WeatherWord(bot->GetMap() ? bot->GetMap()->GetZoneWeather(bot->GetZoneId()) : WEATHER_STATE_FINE));