GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add Chat Filter · Ridemofi/CleanBot@dbc59be

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .luarc.json
  • Bridge.lua
  • ChatFilter.lua
  • CleanBot.lua
  • CleanBot.toc
  • SettingsTab.lua
  • docs
    • bridge-protocol.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.luarc.json‎

Copy file name to clipboardExpand all lines: .luarc.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"ElvUI",
2828
"Talented",
2929
"ChatEdit_InsertLink",
30+
"ChatFrame_AddMessageEventFilter",
3031
"CloseDropDownMenus",
3132
"ColorPickerFrame",
3233
"FauxScrollFrame_GetOffset",
Collapse file

‎Bridge.lua‎

Copy file name to clipboardExpand all lines: Bridge.lua
+82-49Lines changed: 82 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,17 @@ NS.debugSimulate = false ---@type boolean
9999
NS.debugVerify = false ---@type boolean
100100

101101
-- 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).
105105
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
107113

108114
-- ============================================================
109115
-- Linked accounts (populated by .playerbots account linkedAccounts)
@@ -127,9 +133,11 @@ NS.syncPending = false
127133
-- No-bridge discovery: whisper "co ?" to each group member (party or raid)
128134
-- exactly once. Only members that reply with a "Strategies: " line are treated
129135
-- 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.
131139
-- 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.
133141
local function CB_ProbePartyForBots()
134142
if NS.loginPhaseActive then return end
135143

@@ -139,15 +147,18 @@ local function CB_ProbePartyForBots()
139147
if nm then present[strlower(nm)] = true end
140148
end)
141149
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
143153
end
144154

145155
NS.CB_ForEachGroupMember(function(unit, nm)
146156
if nm and UnitIsPlayer(unit) then
147157
local key = strlower(nm)
148158
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
151162
NS.CB_SendBotCommand(nm, "co ?")
152163
end
153164
end
@@ -329,6 +340,40 @@ local function CB_SendBridge(msg)
329340
end
330341
end
331342

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+
332377
-- Sends a command to a bot. Routes through the bridge (silent, no whisper
333378
-- spam) when the bridge is present and the command is allowlisted; falls back
334379
-- 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)
352397
return
353398
end
354399
end
400+
CB_MarkExpectReply(botName)
401+
CB_TagSelfWhisper(botName, command)
355402
SendChatMessage(command, "WHISPER", nil, botName)
356403
end
357404

@@ -633,6 +680,8 @@ NS.CB_FetchStats = function(entry, force)
633680
end
634681
entry.awaitingMoney = true
635682
entry.moneyTimeout = 0
683+
CB_MarkExpectReply(entry.name)
684+
CB_TagSelfWhisper(entry.name, "stats")
636685
SendChatMessage("stats", "WHISPER", nil, entry.name)
637686
end
638687

@@ -709,17 +758,10 @@ local function CB_StartBridgeDetection()
709758
-- Keep the Debug tab's "Auto (<state>)" label current.
710759
if NS.CB_RefreshDebugTab then NS.CB_RefreshDebugTab() end
711760

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.
723765
NS.CB_RequestSync()
724766
end
725767
end)
@@ -749,31 +791,21 @@ bridgeFrame:SetScript("OnEvent", function(self, event, ...)
749791
local key = strlower(sender)
750792
local entry = CleanBot_PartyBots[key]
751793

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 ?")
777809
return
778810
end
779811

@@ -913,7 +945,8 @@ bridgeFrame:SetScript("OnEvent", function(self, event, ...)
913945

914946
elseif NS.awaitingProbe[key] then
915947
-- 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
917950
local class = NS.CB_ResolveClass(sender, "WARRIOR")
918951
entry = {
919952
name = sender,
@@ -943,8 +976,8 @@ bridgeFrame:SetScript("OnEvent", function(self, event, ...)
943976
NS.bridgeReady = true
944977
NS.bridgeState = "present"
945978
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 = {}
948981
-- Keep the Debug tab's "Auto (<state>)" label current.
949982
if NS.CB_RefreshDebugTab then NS.CB_RefreshDebugTab() end
950983
CB_BridgeRequest()
@@ -1229,7 +1262,7 @@ bridgeFrame:SetScript("OnEvent", function(self, event, ...)
12291262
CleanBot_SavedVars.sessionActive = true
12301263

12311264
NS.loginPhaseActive = not isReload -- gate bot probing on fresh login only
1232-
NS.pendingHello = {}
1265+
NS.joinCandidates = {}
12331266
NS.bridgeReady = false
12341267
NS.bridgeState = "unknown"
12351268
NS.bridgeDetecting = false
Collapse file

‎ChatFilter.lua‎

Copy file name to clipboard
+110Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
-- ============================================================
2+
-- ChatFilter.lua — hides CleanBot's own whisper/command chatter from the chat
3+
-- window to cut spam. Display-only: ChatFrame message filters intercept the chat-
4+
-- frame display pipeline, NOT addon RegisterEvent handlers, so Bridge.lua keeps
5+
-- parsing every line — we only stop the user-facing echo of the commands we send
6+
-- and the replies we consume.
7+
--
8+
-- Gated on NS.hideBotChatter (Settings → "Hide Bot Chatter", default on; toggle off
9+
-- to see raw traffic for testing). Read live on each call, so no /reload is needed.
10+
-- ============================================================
11+
local NS = CleanBotNS
12+
13+
local function enabled()
14+
return NS.hideBotChatter ~= false
15+
end
16+
17+
-- A whisper is suppressible when the other party is a bot we manage OR a current
18+
-- group member. The group-member case covers the no-bridge discovery handshake, where
19+
-- a member isn't in CleanBot_PartyBots yet but is being probed (the "co ?" we send and
20+
-- the "Strategies:" reply). CB_FindPartyUnit walks party AND raid.
21+
---@param name string|nil Whisper sender (incoming) or recipient (outgoing).
22+
---@return boolean
23+
local function suppressibleParty(name)
24+
if not name or name == "" then return false end
25+
if CleanBot_PartyBots[strlower(name)] then return true end
26+
return (NS.CB_FindPartyUnit and NS.CB_FindPartyUnit(name) ~= nil) or false
27+
end
28+
29+
-- Outgoing: hide only the command whispers CleanBot itself sent, so a command you type by hand
30+
-- to a bot stays visible. Bridge.lua tags each addon-sent whisper in NS.selfWhispers (keyed by
31+
-- recipient+text); we consume one matching tag per INFORM. No tag → it's a manual whisper, show
32+
-- it. Tags older than SELF_WHISPER_TTL are purged: a failed send fires no INFORM, so its tag
33+
-- must not linger and wrongly hide a later identical manual command.
34+
local SELF_WHISPER_TTL = 3
35+
local function filterWhisperInform(_, _, msg, recipient)
36+
if not enabled() or not suppressibleParty(recipient) then return false end
37+
local store = NS.selfWhispers
38+
local list = store and store[strlower(recipient or "") .. "\0" .. (msg or "")]
39+
if not list then return false end
40+
local now = GetTime()
41+
while list[1] and (now - list[1]) > SELF_WHISPER_TTL do
42+
table.remove(list, 1) -- drop stale tags (sends that never produced an INFORM)
43+
end
44+
if list[1] then
45+
table.remove(list, 1) -- consume this addon-sent whisper
46+
return true
47+
end
48+
return false
49+
end
50+
51+
-- Incoming: hide a bot's reply while its command-reply window is open (see CB_MarkExpectReply
52+
-- in Bridge.lua). The window opens when we whisper a command and is slid forward by one
53+
-- WHISPER_SILENCE on each reply line, so it brackets the whole burst — one ack or a long
54+
-- streamed dump — and closes once the bot goes quiet. Unsolicited bot greetings (a bot's
55+
-- readiness whisper, with no command before it) are intentionally NOT hidden: their text
56+
-- varies and isn't distinguishable from a human's, so they show once on join.
57+
local function filterWhisper(_, _, _, sender)
58+
if not enabled() or not suppressibleParty(sender) then return false end
59+
local key = strlower(sender)
60+
local deadline = NS.botReplyWindow and NS.botReplyWindow[key]
61+
if deadline and GetTime() < deadline then
62+
NS.botReplyWindow[key] = GetTime() + NS.WHISPER_SILENCE -- slide to keep bracketing the burst
63+
return true
64+
end
65+
return false
66+
end
67+
68+
-- System: hide the server output CleanBot triggers and already parses — the self-bot
69+
-- "player botAI" toggle line, the "Linked accounts:" dump, and the per-name bot-add
70+
-- results. collectingLinked is tracked locally (not off Bridge's flag) so it stays
71+
-- consistent regardless of filter-vs-handler ordering for the same line.
72+
local collectingLinked = false
73+
74+
-- Result words that mark a line as ".playerbots bot add/addaccount/login/remove" output.
75+
local BOT_CMD_RESULTS = {
76+
"player already logged in",
77+
"player is offline",
78+
"not your bot",
79+
" - ok",
80+
"logged in",
81+
}
82+
83+
local function filterSystem(_, _, msg)
84+
if not enabled() or not msg then return false end
85+
local lower = strlower(msg)
86+
87+
if lower:find("player botai", 1, true) then return true end
88+
89+
if lower:find("linked accounts", 1, true) then
90+
collectingLinked = true
91+
return true
92+
end
93+
if collectingLinked then
94+
if msg:match("^%s*%-%s*%S+%s*$") then return true end -- "- NAME" row
95+
collectingLinked = false -- non-row line ends the list
96+
end
97+
98+
-- Per-name bot command results: "<cmd>: <Name> - <result>".
99+
if msg:match("^%a+:%s+%S+%s+%-%s+") then
100+
for _, word in ipairs(BOT_CMD_RESULTS) do
101+
if lower:find(word, 1, true) then return true end
102+
end
103+
end
104+
105+
return false
106+
end
107+
108+
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", filterWhisperInform)
109+
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", filterWhisper)
110+
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", filterSystem)
Collapse file

‎CleanBot.lua‎

Copy file name to clipboardExpand all lines: CleanBot.lua
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ NS.THEME_DEFAULTS = {
204204
-- Feature flags and theme values — mutated at login from SavedVars, and by the Settings Apply button.
205205
NS.botEmotes = true
206206
NS.itemGlow = true -- Blizz-path rarity overlay on items/equipment (uncommon+); see ItemVisuals
207+
NS.hideBotChatter = true -- hide CleanBot's own whisper/command spam from chat; see ChatFilter.lua
207208
NS.manageSelf = false -- preference: auto-enable self-bot on fresh login; see Bridge self-bot section
208209
NS.selfBotActive = false -- live state: is the player currently a self-bot (driven by server botAI messages)
209210
NS.scale = NS.THEME_DEFAULTS.scale
@@ -433,6 +434,9 @@ initFrame:SetScript("OnEvent", function(self, event)
433434
if type(CleanBot_SavedVars.itemGlow) == "boolean" then
434435
NS.itemGlow = CleanBot_SavedVars.itemGlow
435436
end
437+
if type(CleanBot_SavedVars.hideBotChatter) == "boolean" then
438+
NS.hideBotChatter = CleanBot_SavedVars.hideBotChatter
439+
end
436440
if type(CleanBot_SavedVars.manageSelf) == "boolean" then
437441
NS.manageSelf = CleanBot_SavedVars.manageSelf
438442
end
Collapse file

‎CleanBot.toc‎

Copy file name to clipboardExpand all lines: CleanBot.toc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Skinning\Widgets.lua
1313
Skinning\QuestWidgets.lua
1414
Skinning\ItemVisuals.lua
1515
Bridge.lua
16+
ChatFilter.lua
1617
Individual\Strategies.lua
1718
Individual\ClassData.lua
1819
Individual\EquipData.lua

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.