Repository navigation
Expand file tree
/
Copy pathProfessionLink.lua
More file actions
671 lines (597 loc) · 20.9 KB
/
Copy pathProfessionLink.lua
File metadata and controls
671 lines (597 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
local ADDON_NAME = ...
local ADDON_PREFIX = "Profession Link: "
local MAX_CHAT_LENGTH = 255
local SPAM_TABLE_MAX_ENTRIES = 200
local WHISPER_MISSING_PREFIX = "I don't have "
local DEFAULTS = {
customText = "no fee, tips are welcome",
whisperDelay = 3,
guildDelay = 3,
}
-- Detect client flavor via TOC interface build number (Retail >= 10.0, Forever 1.60.x).
local interfaceVersion = GetBuildInfo and select(4, GetBuildInfo()) or nil
local IS_FOREVER = interfaceVersion ~= nil and interfaceVersion >= 16000 and interfaceVersion < 20000
local IS_RETAIL = interfaceVersion ~= nil and interfaceVersion >= 100000
-- Resolve WoW 12.0+ (Retail Midnight & Forever) namespaced APIs with fallbacks for older builds.
local SendChatMessage = (C_ChatInfo and C_ChatInfo.SendChatMessage) or _G.SendChatMessage
local InChatMessagingLockdown = C_ChatInfo and C_ChatInfo.InChatMessagingLockdown
local GetSpellTradeSkillLink = C_Spell and C_Spell.GetSpellTradeSkillLink
local GetSpellName = C_Spell and C_Spell.GetSpellName
local GetSpellInfo = C_Spell and C_Spell.GetSpellInfo
local GetSpellBookItemTradeSkillLink = C_SpellBook and C_SpellBook.GetSpellBookItemTradeSkillLink
local GetTradeSkillListLink = C_TradeSkillUI and C_TradeSkillUI.GetTradeSkillListLink
local GetBaseProfessionInfo = C_TradeSkillUI and C_TradeSkillUI.GetBaseProfessionInfo
local LegacyGetTradeSkillListLink = _G.GetTradeSkillListLink
local LegacyGetTradeSkillLine = _G.GetTradeSkillLine
local LegacyGetSpellLink = _G.GetSpellLink
local IsSecretValue = _G.issecretvalue
-- Craftable professions with clickable trade skill links across Retail and WoW Forever (Apprentice spell IDs).
local ALL_PROFESSIONS = {
{ name = "Alchemy", spellID = 2259, alias = "alch" },
{ name = "Blacksmithing", spellID = 2018, alias = "bs" },
{ name = "Enchanting", spellID = 7411, alias = "ench" },
{ name = "Engineering", spellID = 4036, alias = "eng" },
{ name = "Inscription", spellID = 45357, alias = "insc", retailOnly = true },
{ name = "Jewelcrafting", spellID = 25229, alias = "jc", retailOnly = true },
{ name = "Leatherworking", spellID = 2108, alias = "lw" },
{ name = "Tailoring", spellID = 3908, alias = "tail" },
{ name = "Cooking", spellID = 2550, alias = "cook" },
{ name = "First Aid", spellID = 3273, alias = "fa", excludeRetail = true },
}
local PROFESSIONS = {}
local PROFESSION_BY_NAME = {}
for _, entry in ipairs(ALL_PROFESSIONS) do
local excluded = (entry.retailOnly and IS_FOREVER) or (entry.excludeRetail and IS_RETAIL)
if not excluded then
table.insert(PROFESSIONS, entry)
PROFESSION_BY_NAME[entry.name] = entry
end
end
local TRIGGER_TO_PROFESSION = {
alch = "Alchemy",
alchemy = "Alchemy",
bs = "Blacksmithing",
blacksmith = "Blacksmithing",
blacksmithing = "Blacksmithing",
ench = "Enchanting",
enchant = "Enchanting",
enchanting = "Enchanting",
eng = "Engineering",
engi = "Engineering",
engineer = "Engineering",
engineering = "Engineering",
insc = "Inscription",
inscr = "Inscription",
scribe = "Inscription",
inscription = "Inscription",
jc = "Jewelcrafting",
jewel = "Jewelcrafting",
jewelcraft = "Jewelcrafting",
jewelcrafting = "Jewelcrafting",
lw = "Leatherworking",
leather = "Leatherworking",
leatherworking = "Leatherworking",
tail = "Tailoring",
tailor = "Tailoring",
tailoring = "Tailoring",
cook = "Cooking",
cooking = "Cooking",
fa = "First Aid",
firstaid = "First Aid",
["first aid"] = "First Aid",
}
local spamTable = {}
local spamCount = 0
--- Trims leading and trailing whitespace from a string.
-- @param str string|nil Input text
-- @return string Trimmed text (empty string if nil)
local function Trim(str)
if type(str) ~= "string" then
return ""
end
if _G.strtrim then
return _G.strtrim(str)
end
return str:match("^%s*(.-)%s*$") or ""
end
--- Prints a message prefixed with the addon title.
-- @param msg string Message to display in the local chat frame
local function Print(msg)
print(ADDON_PREFIX .. tostring(msg))
end
--- Returns the initialized SavedVariables table, populating missing defaults.
-- Checks `== nil` explicitly so intentionally cleared strings (e.g. `""`) persist.
-- @return table ProfessionLinkDB table
local function GetDB()
if type(ProfessionLinkDB) ~= "table" then
ProfessionLinkDB = {}
end
for key, defaultValue in pairs(DEFAULTS) do
if ProfessionLinkDB[key] == nil then
ProfessionLinkDB[key] = defaultValue
end
end
return ProfessionLinkDB
end
--- Resolves a localized spell name by its spell ID.
-- @param spellID number Spell ID
-- @return string|nil Localized spell name, or nil if unavailable
local function GetSpellNameByID(spellID)
if GetSpellName then
local name = GetSpellName(spellID)
if type(name) == "string" and name ~= "" then
return name
end
end
if GetSpellInfo then
local info = GetSpellInfo(spellID)
if type(info) == "table" and type(info.name) == "string" and info.name ~= "" then
return info.name
end
end
return nil
end
--- Resolves the client-localized name of a profession via its Apprentice spell ID.
-- @param profEntry table Entry from PROFESSIONS
-- @return string Localized profession name (falls back to English name)
local function GetLocalizedProfessionName(profEntry)
return GetSpellNameByID(profEntry.spellID) or profEntry.name
end
--- Resolves a user trigger or slash argument to a supported profession entry.
-- @param rawInput string Trigger text without leading "!" or slash command argument
-- @return table|nil Entry from PROFESSIONS, or nil if unrecognized
local function ResolveProfession(rawInput)
if type(rawInput) ~= "string" then
return nil
end
local cleaned = Trim(rawInput):lower():gsub("[?!.,:;]+$", "")
cleaned = Trim(cleaned)
if cleaned == "" then
return nil
end
local matchedName = TRIGGER_TO_PROFESSION[cleaned]
if matchedName then
return PROFESSION_BY_NAME[matchedName]
end
local firstWord = cleaned:match("^(%S+)")
if firstWord then
matchedName = TRIGGER_TO_PROFESSION[firstWord]
if matchedName then
return PROFESSION_BY_NAME[matchedName]
end
-- Match prefixes of 4+ characters to preserve legacy "!blac" / "!tail" behavior.
if #firstWord >= 4 then
for _, entry in ipairs(PROFESSIONS) do
local englishLower = entry.name:lower()
if englishLower:sub(1, #firstWord) == firstWord then
return entry
end
local localizedLower = GetLocalizedProfessionName(entry):lower()
if localizedLower:sub(1, #firstWord) == firstWord then
return entry
end
end
end
end
return nil
end
--- Retrieves the player's clickable trade skill hyperlink for a profession.
-- @param profEntry table Entry from PROFESSIONS
-- @return string|nil Trade skill hyperlink if learned, otherwise nil
local function GetProfessionTradeLink(profEntry)
local candidateNames = {}
local candidateSet = {}
local function AddCandidateName(name)
if type(name) == "string" and name ~= "" then
local lower = name:lower()
if not candidateSet[lower] then
candidateSet[lower] = true
table.insert(candidateNames, name)
end
end
end
AddCandidateName(GetLocalizedProfessionName(profEntry))
AddCandidateName(profEntry.name)
-- Tier 1: Direct C_Spell trade skill link lookup (11.0+ / Forever engine).
if GetSpellTradeSkillLink then
for _, name in ipairs(candidateNames) do
local link = GetSpellTradeSkillLink(name)
if type(link) == "string" and link ~= "" then
return link
end
end
local link = GetSpellTradeSkillLink(profEntry.spellID)
if type(link) == "string" and link ~= "" then
return link
end
end
-- Tier 2: Spellbook scan via GetProfessions() + C_SpellBook.
-- Iterate indices 1..6 explicitly instead of ipairs because unlearned slots are nil holes.
if GetProfessions and GetProfessionInfo and GetSpellBookItemTradeSkillLink then
local slots = { GetProfessions() }
local spellBank = (Enum and Enum.SpellBookSpellBank and Enum.SpellBookSpellBank.Player) or "spell"
for i = 1, 6 do
local profIndex = slots[i]
if profIndex then
local profName, _, _, _, numAbilities, spellOffset = GetProfessionInfo(profIndex)
if type(profName) == "string" and candidateSet[profName:lower()] and spellOffset then
for offset = 1, (numAbilities or 1) do
local link = GetSpellBookItemTradeSkillLink(spellOffset + offset, spellBank)
if type(link) == "string" and link ~= "" then
return link
end
end
end
end
end
end
-- Tier 3: Open profession window fallback via C_TradeSkillUI (Retail) or legacy globals.
-- Verify the open window actually matches the requested profession before returning its link.
if GetTradeSkillListLink and GetBaseProfessionInfo then
local baseInfo = GetBaseProfessionInfo()
if baseInfo then
local profLower = type(baseInfo.professionName) == "string" and baseInfo.professionName:lower() or nil
local parentLower = type(baseInfo.parentProfessionName) == "string" and baseInfo.parentProfessionName:lower() or nil
if (profLower and candidateSet[profLower]) or (parentLower and candidateSet[parentLower]) then
local link = GetTradeSkillListLink()
if type(link) == "string" and link ~= "" then
return link
end
end
end
end
if LegacyGetTradeSkillListLink and LegacyGetTradeSkillLine then
local openName = LegacyGetTradeSkillLine()
if type(openName) == "string" and candidateSet[openName:lower()] then
local link = LegacyGetTradeSkillListLink()
if type(link) == "string" and link ~= "" then
return link
end
end
end
-- Tier 4: Legacy global GetSpellLink fallback.
if LegacyGetSpellLink then
for _, name in ipairs(candidateNames) do
local _, link = LegacyGetSpellLink(name)
if type(link) == "string" and link ~= "" then
return link
end
end
end
return nil
end
--- Checks whether chat messaging is currently restricted by an encounter lockdown.
-- @return boolean True when outbound chat APIs are locked down
local function IsChatLockedDown()
return InChatMessagingLockdown ~= nil and InChatMessagingLockdown() == true
end
--- Checks whether any passed value is a 12.0+ tainted secret value.
-- Inspecting or comparing secret values throws Lua errors during chat lockdown.
-- @param ... any Values to inspect
-- @return boolean True if any argument is a secret value
local function IsAnySecret(...)
if not IsSecretValue then
return false
end
for i = 1, select("#", ...) do
if IsSecretValue(select(i, ...)) then
return true
end
end
return false
end
--- Determines whether an incoming chat author/GUID belongs to the local player.
-- @param author string Sender name from chat event
-- @param senderGUID string|nil Sender GUID from chat event
-- @return boolean True if the sender is the player
local function IsPlayerSelf(author, senderGUID)
if senderGUID and UnitGUID then
local playerGUID = UnitGUID("player")
if playerGUID and senderGUID == playerGUID then
return true
end
end
if type(author) ~= "string" then
return false
end
local playerName, playerRealm
if UnitFullName then
playerName, playerRealm = UnitFullName("player")
elseif UnitName then
playerName = UnitName("player")
end
if not playerName then
return false
end
if author == playerName then
return true
end
local normalizedRealm = (GetNormalizedRealmName and GetNormalizedRealmName()) or playerRealm
if normalizedRealm and normalizedRealm ~= "" and author == (playerName .. "-" .. normalizedRealm) then
return true
end
return false
end
--- Checks if an author is still within the cooldown window.
-- @param author string Sender name
-- @param delay number Cooldown duration in seconds
-- @param now number Current GetTime() timestamp
-- @return boolean True if throttled
local function IsThrottled(author, delay, now)
local lastSent = spamTable[author]
return lastSent ~= nil and now <= (lastSent + delay)
end
--- Records a sent reply timestamp and bounds memory usage on long sessions.
-- @param author string Sender name
-- @param now number Current GetTime() timestamp
local function MarkSent(author, now)
if spamTable[author] == nil then
spamCount = spamCount + 1
end
spamTable[author] = now
if spamCount > SPAM_TABLE_MAX_ENTRIES then
local db = GetDB()
local maxDelay = math.max(db.whisperDelay or 3, db.guildDelay or 3)
for key, timestamp in pairs(spamTable) do
if now > (timestamp + maxDelay) then
spamTable[key] = nil
spamCount = spamCount - 1
end
end
end
end
--- Sends a chat message safely, guarding against lockdown and missing APIs.
-- @param message string Message text
-- @param chatType string Chat channel type (e.g. "WHISPER", "GUILD", "CHANNEL")
-- @param target string|number|nil Target player name or channel ID
-- @return boolean True if dispatched
local function SafeSendChatMessage(message, chatType, target)
if IsChatLockedDown() or not SendChatMessage or type(message) ~= "string" or message == "" then
return false
end
SendChatMessage(message, chatType, nil, target)
return true
end
--- Sends a Battle.net whisper by account ID, guarding against lockdown and invalid payloads.
-- @param bnetIDAccount number|nil Battle.net account ID
-- @param message string Message text
-- @return boolean True if dispatched
local function SendBNetWhisperByID(bnetIDAccount, message)
if IsChatLockedDown() or type(bnetIDAccount) ~= "number" or type(message) ~= "string" or message == "" then
return false
end
if C_BattleNet and C_BattleNet.SendWhisper then
C_BattleNet.SendWhisper(bnetIDAccount, message)
return true
end
if BNSendWhisper then
BNSendWhisper(bnetIDAccount, message)
return true
end
return false
end
--- Appends the configured custom channel text without ever truncating the hyperlink.
-- @param link string Profession trade skill hyperlink
-- @return string Formatted chat payload within MAX_CHAT_LENGTH bytes
local function BuildChannelPayload(link)
local customText = Trim(GetDB().customText or "")
if customText == "" then
return link
end
local maxSuffix = MAX_CHAT_LENGTH - #link - 1
if maxSuffix <= 0 then
return link
end
return link .. " " .. customText:sub(1, maxSuffix)
end
--- Processes incoming whisper, Battle.net whisper, or guild chat profession link requests.
-- @param chatType string "WHISPER", "BN_WHISPER", or "GUILD"
-- @param delay number Per-sender throttle duration in seconds
-- @param replyWhenMissing boolean Whether to reply when the player lacks the profession
-- @param msg string Chat message payload
-- @param author string|nil Sender name
-- @param senderGUID string|nil Sender GUID
-- @param bnetIDAccount number|nil Sender Battle.net account ID (for BN_WHISPER)
local function HandleChatRequest(chatType, delay, replyWhenMissing, msg, author, senderGUID, bnetIDAccount)
if IsChatLockedDown() or IsAnySecret(msg, author, senderGUID, bnetIDAccount) then
return
end
if type(msg) ~= "string" then
return
end
local throttleKey
if chatType == "BN_WHISPER" then
if type(bnetIDAccount) ~= "number" then
return
end
throttleKey = "bn:" .. tostring(bnetIDAccount)
else
if type(author) ~= "string" or IsPlayerSelf(author, senderGUID) then
return
end
throttleKey = author
end
local trimmed = Trim(msg)
if trimmed:sub(1, 1) ~= "!" then
return
end
local profEntry = ResolveProfession(trimmed:sub(2))
if not profEntry then
return
end
local now = GetTime()
if IsThrottled(throttleKey, delay, now) then
return
end
local function DispatchReply(payload)
if chatType == "BN_WHISPER" then
return SendBNetWhisperByID(bnetIDAccount, payload)
end
local target = (chatType == "WHISPER") and author or nil
return SafeSendChatMessage(payload, chatType, target)
end
local link = GetProfessionTradeLink(profEntry)
if link then
if DispatchReply(link) then
MarkSent(throttleKey, now)
end
elseif replyWhenMissing then
local missingReply = WHISPER_MISSING_PREFIX .. GetLocalizedProfessionName(profEntry)
if DispatchReply(missingReply) then
MarkSent(throttleKey, now)
end
end
end
local frame = CreateFrame("Frame")
local eventHandlers = {}
function eventHandlers:ADDON_LOADED(loadedName)
if loadedName ~= ADDON_NAME then
return
end
GetDB()
self:UnregisterEvent("ADDON_LOADED")
end
function eventHandlers:CHAT_MSG_WHISPER(msg, author, _, _, _, _, _, _, _, _, _, senderGUID)
HandleChatRequest("WHISPER", GetDB().whisperDelay, true, msg, author, senderGUID)
end
function eventHandlers:CHAT_MSG_BN_WHISPER(msg, author, _, _, _, _, _, _, _, _, _, senderGUID, bnetIDAccount)
HandleChatRequest("BN_WHISPER", GetDB().whisperDelay, true, msg, author, senderGUID, bnetIDAccount)
end
function eventHandlers:CHAT_MSG_GUILD(msg, author, _, _, _, _, _, _, _, _, _, senderGUID)
HandleChatRequest("GUILD", GetDB().guildDelay, false, msg, author, senderGUID)
end
frame:SetScript("OnEvent", function(self, event, ...)
local handler = eventHandlers[event]
if handler then
handler(self, ...)
end
end)
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("CHAT_MSG_WHISPER")
frame:RegisterEvent("CHAT_MSG_BN_WHISPER")
frame:RegisterEvent("CHAT_MSG_GUILD")
--- Prints command usage, active flavor professions, and current channel message.
local function PrintHelp()
local db = GetDB()
local currentMsg = Trim(db.customText or "")
if currentMsg == "" then
currentMsg = "(none)"
end
local profNames = {}
for _, entry in ipairs(PROFESSIONS) do
table.insert(profNames, entry.name:lower() .. " (" .. entry.alias .. ")")
end
Print("Usage:")
print(" /pf <profession> (or /pl, /proflink) - Link a profession in your active chat")
print(" /pf msg <text> - Set custom text appended when linking in channels")
print(" /pf msg clear - Clear custom channel text")
print(" /pf help - Show this help")
print(" Professions: " .. table.concat(profNames, ", "))
print(" Current channel text: " .. currentMsg)
end
--- Resolves the active or most recent chat edit box cleanly without legacy chatStyle assumptions.
-- @param explicitEditBox Frame|nil Edit box passed to the slash command handler
-- @return Frame|nil Resolved chat edit box
local function ResolveEditBox(explicitEditBox)
if explicitEditBox then
return explicitEditBox
end
if ChatEdit_GetActiveWindow then
local active = ChatEdit_GetActiveWindow()
if active then
return active
end
end
if ChatEdit_GetLastActiveWindow then
local lastActive = ChatEdit_GetLastActiveWindow()
if lastActive then
return lastActive
end
end
if DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.editBox then
return DEFAULT_CHAT_FRAME.editBox
end
return nil
end
--- Sends a Battle.net whisper when the active chat target is BN_WHISPER.
-- @param target string BattleTag/presence target from editBox tellTarget
-- @param link string Profession trade skill hyperlink
-- @return boolean True if sent via Battle.net API
local function TrySendBNetWhisper(target, link)
if type(target) ~= "string" or target == "" or not BNet_GetBNetIDAccount then
return false
end
local bnetIDAccount = BNet_GetBNetIDAccount(target)
return SendBNetWhisperByID(bnetIDAccount, link)
end
SLASH_PROFESSIONLINK1 = "/pf"
SLASH_PROFESSIONLINK2 = "/pl"
SLASH_PROFESSIONLINK3 = "/proflink"
SlashCmdList["PROFESSIONLINK"] = function(rawArgs, editBox)
local trimmed = Trim(rawArgs)
local lower = trimmed:lower()
if trimmed == "" or lower == "help" then
PrintHelp()
return
end
if lower == "msg" then
local currentMsg = Trim(GetDB().customText or "")
Print("Current channel text: " .. (currentMsg ~= "" and currentMsg or "(none)"))
return
end
local msgArg = trimmed:match("^[Mm][Ss][Gg]%s+(.+)$")
if msgArg then
local cleanedArg = Trim(msgArg)
local cleanedLower = cleanedArg:lower()
if cleanedLower == "clear" or cleanedLower == "none" then
GetDB().customText = ""
Print("Custom channel text cleared.")
else
GetDB().customText = cleanedArg
Print("Custom channel text set to: " .. cleanedArg)
end
return
end
local profEntry = ResolveProfession(trimmed)
if not profEntry then
Print("Unknown profession \"" .. trimmed .. "\". Type /pf help for options.")
return
end
if IsChatLockedDown() then
Print("Cannot send profession links during chat messaging lockdown.")
return
end
local link = GetProfessionTradeLink(profEntry)
if not link then
Print("You don't seem to have " .. GetLocalizedProfessionName(profEntry) .. ".")
return
end
local eb = ResolveEditBox(editBox)
local chatType = (eb and eb:GetAttribute("chatType")) or "SAY"
if chatType == "WHISPER" then
local target = eb and eb:GetAttribute("tellTarget")
if type(target) == "string" and target ~= "" then
SafeSendChatMessage(link, "WHISPER", target)
else
Print("No whisper target found. Open a whisper first or use another chat channel.")
end
elseif chatType == "BN_WHISPER" then
local target = eb and eb:GetAttribute("tellTarget")
if not TrySendBNetWhisper(target, link) then
if ChatEdit_InsertLink then
ChatEdit_InsertLink(link)
else
Print("Unable to send Battle.net whisper directly.")
end
end
elseif chatType == "CHANNEL" then
local target = eb and eb:GetAttribute("channelTarget")
if (type(target) == "number" and target > 0) or (type(target) == "string" and Trim(target) ~= "") then
SafeSendChatMessage(BuildChannelPayload(link), "CHANNEL", target)
else
Print("No channel target found. Select a chat channel first.")
end
else
SafeSendChatMessage(link, chatType)
end
end