@@ -99,11 +99,17 @@ NS.debugSimulate = false ---@type boolean |
99 | 99 | NS.debugVerify = false ---@type boolean |
100 | 100 |
|
101 | 101 | -- No-bridge login gating: on a fresh login (not a /reload) bots may not be |
102 | | --- online yet, so we block CB_ProbePartyForBots until bridge detection |
103 | | --- resolves. "Hello!" whispers from bots are buffered here and flushed once |
104 | | --- the bridge is declared absent. |
| 102 | +-- online yet, so we block CB_ProbePartyForBots until bridge detection resolves. |
| 103 | +-- Once it does, the probe sweep runs and a not-yet-ready bot is caught later via |
| 104 | +-- its readiness whisper (see NS.joinCandidates). |
105 | 105 | NS.loginPhaseActive = false -- true only on fresh login, cleared when detection resolves |
106 | | -NS.pendingHello = {} -- name-key -> display-name: buffered "Hello!" senders |
| 106 | + |
| 107 | +-- Discovery candidates: members CB_ProbePartyForBots has probed but not yet confirmed as bots. |
| 108 | +-- A bot that wasn't in-world during the probe sends an (any-text) greeting once it loads; that |
| 109 | +-- unsolicited whisper is the readiness signal that re-probes it. Bounded to one entry per member |
| 110 | +-- per join (set when first probed, cleared on the re-probe / on confirmation / on leaving), so an |
| 111 | +-- established member who later whispers isn't re-probed. Replaces the old exact-"Hello!" match. |
| 112 | +NS.joinCandidates = {} -- name-key -> display-name: probed, awaiting a readiness whisper |
107 | 113 |
|
108 | 114 | -- ============================================================ |
109 | 115 | -- Linked accounts (populated by .playerbots account linkedAccounts) |
@@ -127,9 +133,11 @@ NS.syncPending = false |
127 | 133 | -- No-bridge discovery: whisper "co ?" to each group member (party or raid) |
128 | 134 | -- exactly once. Only members that reply with a "Strategies: " line are treated |
129 | 135 | -- as bots (handled in the CHAT_MSG_WHISPER branch). Humans never respond, so |
130 | | --- they are probed a single time and then ignored. |
| 136 | +-- they are probed a single time and then ignored. Each newly-probed member is also |
| 137 | +-- recorded in NS.joinCandidates so a bot that wasn't ready for this probe is re-probed |
| 138 | +-- when it later sends a readiness whisper. |
131 | 139 | -- Skipped during loginPhaseActive — bots may not be online yet on fresh |
132 | | --- login; the "Hello!" path gates probing until each bot announces itself. |
| 140 | +-- login; probing waits until detection resolves, then this sweep runs. |
133 | 141 | local function CB_ProbePartyForBots() |
134 | 142 | if NS.loginPhaseActive then return end |
135 | 143 |
|
@@ -139,15 +147,18 @@ local function CB_ProbePartyForBots() |
139 | 147 | if nm then present[strlower(nm)] = true end |
140 | 148 | end) |
141 | 149 | for k in pairs(NS.probed) do |
142 | | - if not present[k] then NS.probed[k] = nil; NS.awaitingProbe[k] = nil end |
| 150 | + if not present[k] then |
| 151 | + NS.probed[k] = nil; NS.awaitingProbe[k] = nil; NS.joinCandidates[k] = nil |
| 152 | + end |
143 | 153 | end |
144 | 154 |
|
145 | 155 | NS.CB_ForEachGroupMember(function(unit, nm) |
146 | 156 | if nm and UnitIsPlayer(unit) then |
147 | 157 | local key = strlower(nm) |
148 | 158 | if not CleanBot_PartyBots[key] and not NS.probed[key] then |
149 | | - NS.probed[key] = true |
150 | | - NS.awaitingProbe[key] = true |
| 159 | + NS.probed[key] = true |
| 160 | + NS.awaitingProbe[key] = true |
| 161 | + NS.joinCandidates[key] = nm -- await a readiness whisper if this probe goes unanswered |
151 | 162 | NS.CB_SendBotCommand(nm, "co ?") |
152 | 163 | end |
153 | 164 | end |
@@ -329,6 +340,40 @@ local function CB_SendBridge(msg) |
329 | 340 | end |
330 | 341 | end |
331 | 342 |
|
| 343 | +-- Command-reply window: bots confirm nearly every command with a whisper — a one-line ack |
| 344 | +-- ("Picking ...", "Wait for attack time set to ...") or a multi-line dump (items/quests/spec). |
| 345 | +-- Rather than enumerate every reply string, we open a per-bot window the instant we whisper a |
| 346 | +-- command; ChatFilter.lua suppresses that bot's whispers while the window is open and slides it |
| 347 | +-- forward as each reply line arrives, so the window brackets the whole burst and closes after |
| 348 | +-- WHISPER_SILENCE of quiet (the same silence basis the collection flags use). Keyed by |
| 349 | +-- lowercased name so it also covers discovery probes to not-yet-cached members. |
| 350 | +NS.botReplyWindow = NS.botReplyWindow or {} -- [lowername] = GetTime() deadline |
| 351 | + |
| 352 | +---@param botName string The bot we just whispered a command/query to. |
| 353 | +local function CB_MarkExpectReply(botName) |
| 354 | + if botName and botName ~= "" then |
| 355 | + NS.botReplyWindow[strlower(botName)] = GetTime() + NS.WHISPER_SILENCE |
| 356 | + end |
| 357 | +end |
| 358 | + |
| 359 | +-- Outgoing whisper provenance: CHAT_MSG_WHISPER_INFORM can't tell an addon-sent command from |
| 360 | +-- one the user typed by hand, so we tag each command whisper we send. ChatFilter.lua hides only |
| 361 | +-- the tagged ones, leaving manually typed whispers to a bot visible. Keyed by recipient+text, |
| 362 | +-- holding a short list of send timestamps (a list, not a flag, so two identical commands in a |
| 363 | +-- row each get their own tag); ChatFilter consumes one per matching INFORM and expires stale |
| 364 | +-- tags (a failed send fires no INFORM, so its tag must not linger and hide a later manual one). |
| 365 | +NS.selfWhispers = NS.selfWhispers or {} -- ["lowerRecipient\0text"] = { GetTime(), ... } |
| 366 | + |
| 367 | +---@param recipient string Whisper target (bot name). |
| 368 | +---@param text string Exact whisper text the addon is sending. |
| 369 | +local function CB_TagSelfWhisper(recipient, text) |
| 370 | + if not recipient or recipient == "" then return end |
| 371 | + local k = strlower(recipient) .. "\0" .. (text or "") |
| 372 | + local list = NS.selfWhispers[k] |
| 373 | + if not list then list = {}; NS.selfWhispers[k] = list end |
| 374 | + list[#list + 1] = GetTime() |
| 375 | +end |
| 376 | + |
332 | 377 | -- Sends a command to a bot. Routes through the bridge (silent, no whisper |
333 | 378 | -- spam) when the bridge is present and the command is allowlisted; falls back |
334 | 379 | -- to a whisper for everything else or when bridge is absent. Safe to use for |
@@ -352,6 +397,8 @@ NS.CB_SendBotCommand = function(botName, command) |
352 | 397 | return |
353 | 398 | end |
354 | 399 | end |
| 400 | + CB_MarkExpectReply(botName) |
| 401 | + CB_TagSelfWhisper(botName, command) |
355 | 402 | SendChatMessage(command, "WHISPER", nil, botName) |
356 | 403 | end |
357 | 404 |
|
@@ -633,6 +680,8 @@ NS.CB_FetchStats = function(entry, force) |
633 | 680 | end |
634 | 681 | entry.awaitingMoney = true |
635 | 682 | entry.moneyTimeout = 0 |
| 683 | + CB_MarkExpectReply(entry.name) |
| 684 | + CB_TagSelfWhisper(entry.name, "stats") |
636 | 685 | SendChatMessage("stats", "WHISPER", nil, entry.name) |
637 | 686 | end |
638 | 687 |
|
@@ -709,17 +758,10 @@ local function CB_StartBridgeDetection() |
709 | 758 | -- Keep the Debug tab's "Auto (<state>)" label current. |
710 | 759 | if NS.CB_RefreshDebugTab then NS.CB_RefreshDebugTab() end |
711 | 760 |
|
712 | | - -- Flush bots that said "Hello!" during detection (fresh login path). |
713 | | - -- CB_ProbePartyForBots is now unblocked for mid-session joins. |
714 | | - for key, displayName in pairs(NS.pendingHello) do |
715 | | - if not CleanBot_PartyBots[key] and not NS.probed[key] then |
716 | | - NS.probed[key] = true |
717 | | - NS.awaitingProbe[key] = true |
718 | | - NS.CB_SendBotCommand(displayName, "co ?") |
719 | | - end |
720 | | - end |
721 | | - NS.pendingHello = {} |
722 | | - |
| 761 | + -- Detection done with no bridge: run the probe sweep now that login gating is |
| 762 | + -- lifted. It probes every current member (and records joinCandidates), so a bot |
| 763 | + -- that greeted during detection is caught here, and a not-yet-ready one is caught |
| 764 | + -- later by its readiness whisper. |
723 | 765 | NS.CB_RequestSync() |
724 | 766 | end |
725 | 767 | end) |
@@ -749,31 +791,21 @@ bridgeFrame:SetScript("OnEvent", function(self, event, ...) |
749 | 791 | local key = strlower(sender) |
750 | 792 | local entry = CleanBot_PartyBots[key] |
751 | 793 |
|
752 | | - -- "Hello!" detection: a bot has just come online (no-bridge, fresh-login path). |
753 | | - -- We verify the sender is actually in our group to avoid acting on a real player. |
754 | | - -- "Hello!" is not a Strategies reply, so we return early after handling it. |
755 | | - if msg == "Hello!" and CB_EffectiveBridgeState() ~= "present" then |
756 | | - local inParty = false |
757 | | - NS.CB_ForEachGroupMember(function(unit, nm) |
758 | | - if nm == sender then inParty = true end |
759 | | - end) |
760 | | - if inParty then |
761 | | - if NS.loginPhaseActive then |
762 | | - -- Detection still running: buffer for processing when it resolves. |
763 | | - NS.pendingHello[key] = sender |
764 | | - elseif not CleanBot_PartyBots[key] then |
765 | | - -- A bot whispers "Hello!" once it has finished loading into the |
766 | | - -- world. Re-probe even if we already probed it: the initial |
767 | | - -- discovery probe is often whispered before the bot has spawned, |
768 | | - -- so it never replies (leaving probed=true, awaiting=true, but no |
769 | | - -- cache entry — exactly what /cbdebug showed). "Hello!" is the |
770 | | - -- bot's readiness signal and only bots send it, so re-probing |
771 | | - -- here never spams real players. |
772 | | - NS.probed[key] = true |
773 | | - NS.awaitingProbe[key] = true |
774 | | - NS.CB_SendBotCommand(sender, "co ?") |
775 | | - end |
776 | | - end |
| 794 | + -- Readiness detection (no-bridge): a bot that wasn't in-world for its initial probe |
| 795 | + -- announces itself once loaded by whispering the player. The greeting text varies |
| 796 | + -- across playerbots versions ("Hi", "Hi!", "Hello", "Hello!", …), so we trigger on the |
| 797 | + -- whisper itself, not its content: an unsolicited whisper from a joinCandidate (a member |
| 798 | + -- we probed but haven't confirmed) re-sends "co ?", and the "Strategies:" reply confirms |
| 799 | + -- bot-hood below. A human just won't reply. Bounded to one re-probe per join by clearing |
| 800 | + -- the candidate here. Excludes a "Strategies:" line (that's the reply, handled below) and |
| 801 | + -- known bots (entry ~= nil). |
| 802 | + if not entry and NS.joinCandidates[key] |
| 803 | + and strsub(msg, 1, 12) ~= "Strategies: " |
| 804 | + and CB_EffectiveBridgeState() ~= "present" then |
| 805 | + NS.probed[key] = true |
| 806 | + NS.awaitingProbe[key] = true |
| 807 | + NS.joinCandidates[key] = nil |
| 808 | + NS.CB_SendBotCommand(sender, "co ?") |
777 | 809 | return |
778 | 810 | end |
779 | 811 |
|
@@ -913,7 +945,8 @@ bridgeFrame:SetScript("OnEvent", function(self, event, ...) |
913 | 945 |
|
914 | 946 | elseif NS.awaitingProbe[key] then |
915 | 947 | -- No-bridge discovery: a probed party member replied, so it IS a bot. |
916 | | - NS.awaitingProbe[key] = nil |
| 948 | + NS.awaitingProbe[key] = nil |
| 949 | + NS.joinCandidates[key] = nil -- confirmed; no longer awaiting a readiness whisper |
917 | 950 | local class = NS.CB_ResolveClass(sender, "WARRIOR") |
918 | 951 | entry = { |
919 | 952 | name = sender, |
@@ -943,8 +976,8 @@ bridgeFrame:SetScript("OnEvent", function(self, event, ...) |
943 | 976 | NS.bridgeReady = true |
944 | 977 | NS.bridgeState = "present" |
945 | 978 | NS.bridgeDetecting = false |
946 | | - NS.loginPhaseActive = false -- bridge handles discovery; no Hello! gating needed |
947 | | - NS.pendingHello = {} |
| 979 | + NS.loginPhaseActive = false -- bridge handles discovery; no whisper-probe gating needed |
| 980 | + NS.joinCandidates = {} |
948 | 981 | -- Keep the Debug tab's "Auto (<state>)" label current. |
949 | 982 | if NS.CB_RefreshDebugTab then NS.CB_RefreshDebugTab() end |
950 | 983 | CB_BridgeRequest() |
@@ -1229,7 +1262,7 @@ bridgeFrame:SetScript("OnEvent", function(self, event, ...) |
1229 | 1262 | CleanBot_SavedVars.sessionActive = true |
1230 | 1263 |
|
1231 | 1264 | NS.loginPhaseActive = not isReload -- gate bot probing on fresh login only |
1232 | | - NS.pendingHello = {} |
| 1265 | + NS.joinCandidates = {} |
1233 | 1266 | NS.bridgeReady = false |
1234 | 1267 | NS.bridgeState = "unknown" |
1235 | 1268 | NS.bridgeDetecting = false |
|