Thread: realid aiv
View Single Post
12-13-10, 08:18 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The code you just posted still contains all of the errors I corrected in my last post. Did you even read what I wrote? >_<

Here is the code I've been successfully using for years to auto-accept party invites from friends and guildmates. Note that I just added the Battle.net friend support, and haven't actively tested it since I don't use Real ID, but the basic syntax and API usage is at least error-free.

Code:
local function IsFriend(name)
	if UnitIsInMyGuild(name) then
		return true
	end

	for i = 1, GetNumFriends() do
		if GetFriendInfo(i) == name then
			return true
		end
	end

	for i = 1, select(2, BNGetNumFriends()) do
		for j = 1, BNGetNumFriendToons(i) do
			local _, toonName, client, realm = BNGetFriendToonInfo(i, j)
			if toonName == name and client == "WoW" and realm == GetRealmName() then
				return true
			end
		end
	end
end

local f = CreateFrame("Frame")
f:RegisterEvent("PARTY_INVITE_REQUEST")
f:SetScript("OnEvent", function(self, event, sender)
	if IsFriend(sender) then
		AcceptGroup()
	else
		SendWho("n-\"" .. sender .. "\"")
		StaticPopup_Show("PARTY_INVITE", sender)
	end
end

UIParent:UnregisterEvent("PARTY_INVITE_REQUEST")
If you don't want to run a /who on people who invite you but aren't in your guild or friends list, remove the SendWho line.

On a side note, putting everything on one line is not a good way to "cut it down". It makes your code a pain in the ass to read, and does not improve runtime performance at all.
  Reply With Quote