1. #1

    Need help with channel relay addon to bnet friend

    Could anyone make a quick simple addon so I can relay a selected channel to one of my battle.net friends. For instance If I wanted to relay trade chat all I would have to do is through a slash command choose a battle.net friend to relay do then select the channel I would want to relay. AN example of this slash command would be: /relay [Bnet Friend] [channel] without the brackets of course. Examples would be Trade, general, local def, etc. Thanks for anyone who can help.
    Old Computer

    New Computer

  2. #2
    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.
    Last edited by Treeston; 2014-05-26 at 08:58 AM.
    UI & AddOns expert | Interface & Macros moderator - My work

  3. #3
    Thank you so much this works great but sorry to sound picky but it will just be a quality of life improvement. Can you change a part of the code to add more info for /relay list? with the /relay list it shows this:
    Currently forwarding the following channels:
    General:
    General - Hellfire Peninsula:

    Is there anyway to add the extra info to tell you WHICH BNET friend you're also relaying it too as well? I see how the code works in a way that you can relay more then one channel to anyone or just multiple channels relayed to same person. Is there a way to set it up by grouping the info PER BNET friend like for instance:

    Currently forwarding the following channels to Bnet Friend "Name of Friend":
    General:
    General - Hellfire Peninsula:

    With this it will have a separate group for each Bnet friend if you're relaying it to more then one person and show the channel relayed for each friend as well. Sorry if you didn't understand my request and if that is too much to ask for then don't worry about.

    Sorry just one more request but could you add a string to abbreviate the realm names? The chat addon Prat has a setting to shorten the realm name to just the first 3 letters. For example my name could show up as IXBillyXI-Archimonde but an abbreviated version would show up as IXBillyXI-Arc. Sorry for another request just another quality of life improvement.
    Last edited by IXBillyXI; 2014-05-26 at 07:37 AM.
    Old Computer

    New Computer

  4. #4
    Added both above. The part where it didn't display who it's relaying to in /relay list was actually a bug.
    UI & AddOns expert | Interface & Macros moderator - My work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •