Code:
local forwards={}
local f=CreateFrame("Frame")
f:SetScript("OnEvent",function(s,e,msg,send,_,_,_,_,_,_,name)
if forwards[name] then
local sName,sRealm=send:match("^([^%-]+)%-(...).+$")
if sName and sRealm then send=("%s-%s"):format(sName,sRealm) end
local m = ("[%s - %s]: %s"):format(name,send,msg)
if m:len() > 255 then m = ("%s..."):format(m:sub(1,252)) end
for n in pairs(forwards[name]) do
local pID = BNet_GetPresenceID(n)
if pID then
BNSendWhisper(pID,m)
end
end
end
end)
f:RegisterEvent("CHAT_MSG_CHANNEL")
SlashCmdList["RELAY"]=function(input)
local cmd,sub = input:match("^(%S+)%s*(.*)$")
if cmd == "start" then
local target,channel = sub:match("^%s*\"([^\"]+)\"%s*(%d+)%s*$")
if target and channel then
local c=tonumber(channel)
channel = select(2,GetChannelName(c))
if not channel then
print(("Channel with ID %d not found."):format(c))
end
else
target,channel = sub:match("^%s*\"([^\"]+)\"%s*\"([^\"]+)\"%s*$")
if not (target and channel) then
print("Usage: |cffffff00/relay start \"Name of Friend\" channelID|r or |cffffff00/relay start \"Name of Friend\" \"Name of channel\"|r")
end
end
if target and channel then
forwards[channel] = forwards[channel] or {}
forwards[channel][target] = true
print(("Target '%s' added for channel '%s'."):format(target,channel))
if not BNet_GetPresenceID(target) then
print(("Note: BNet_PresenceID returned nothing for name '%s'. Are you sure the name is spelled correctly?"):format(target))
end
end
elseif cmd == "stop" then
local target,channel = sub:match("^%s*\"([^\"]+)\"%s*(%d+)%s*$")
if target and channel then
local c=tonumber(channel)
channel = select(2,GetChannelName(c))
if not channel then
print(("Channel with ID %d not found."):format(c))
end
else
target,channel = sub:match("^%s*\"([^\"]+)\"%s*\"([^\"]+)\"%s*$")
if not (target and channel) then
print("Usage: |cffffff00/relay stop \"Name of Friend\" channelID|r or |cffffff00/relay stop \"Name of Friend\" \"Name of channel\"|r")
end
end
if target and channel then
if (not forwards[channel]) or (not forwards[channel][target]) then
print(("Channel '%s' is currently not being relayed to friend '%s'."):format(channel,target))
else
forwards[channel][target] = nil
if not next(forwards[channel]) then forwards[channel] = nil end
print(("Channel '%s' is no longer being relayed to friend '%s'."):format(channel,target))
end
end
elseif cmd == "list" then
print("Currently forwarding the following channels:")
for n,l in pairs(forwards) do
local t={} for key in pairs(l) do table.insert(t,key) end
print(("%s: %s"):format(n,table.concat(t,", ")))
end
else
print("Usage: |cffffff00/relay (start|stop|list)|r")
end
end
SLASH_RELAY1 = "/relay"
How to use. Drycoded and untested.