PageRenderTime 88ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 5ms

/Tukui/modules/misc/invite.lua

http://github.com/Asphyxia/Tukui
Lua | 108 lines | 76 code | 18 blank | 14 comment | 32 complexity | 8d1a2bba2c1d13d9c71fe56eeb2db201 MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2
  3------------------------------------------------------------------------
  4-- Auto accept invite
  5------------------------------------------------------------------------
  6
  7if C["invite"].autoaccept then
  8	local holder = CreateFrame("Frame")
  9	holder:RegisterEvent("PARTY_INVITE_REQUEST")
 10	holder:RegisterEvent("PARTY_MEMBERS_CHANGED")
 11	
 12	local hidestatic -- used to hide static popup when auto-accepting
 13	holder:SetScript("OnEvent", function(self, event, leader)
 14		local ingroup = false
 15		
 16		if event == "PARTY_INVITE_REQUEST" then
 17			if MiniMapLFGFrame:IsShown() then return end -- Prevent losing que inside LFD if someone invites you to group
 18			if GetNumPartyMembers() > 0 or GetNumRaidMembers() > 0 then return end
 19			hidestatic = true
 20		
 21			-- Update Guild and Friendlist
 22			if GetNumFriends() > 0 then ShowFriends() end
 23			if IsInGuild() then GuildRoster() end
 24			
 25			for friendindex = 1, GetNumFriends() do
 26				local friendname = GetFriendInfo(friendindex)
 27				if friendname == leader then
 28					AcceptGroup()
 29					ingroup = true
 30					break
 31				end
 32			end
 33			
 34			-------------------------------------------------------------------
 35			-- friend not found in friend index, so we look now into battle.net
 36			-------------------------------------------------------------------
 37			
 38			local playerFaction
 39			
 40			-- find which faction we play
 41			if select(1, UnitFactionGroup("player")) == "Horde" then playerFaction = 0 else playerFaction = 1 end
 42			
 43			if not ingroup then
 44				for i = 1, select(2, BNGetNumFriends()) do
 45					local presenceID, givenName, surname, toonName, toonID, client, isOnline = BNGetFriendInfo(i)
 46					local _, _, _, realmName, faction, race, class, _, zoneName, level = BNGetToonInfo(presenceID)
 47
 48					if client == "WoW" and realmName == T.myrealm and faction == playerFaction then
 49						if toonName == leader then
 50							AcceptGroup()
 51							ingroup = true
 52							break
 53						end
 54					end
 55				end
 56			end
 57			
 58			-----------------------------------------------------------------------------
 59			-- friend not found in battle.net friend index, so we look now into our guild
 60			-----------------------------------------------------------------------------
 61			
 62			if not ingroup then
 63				for guildindex = 1, GetNumGuildMembers(true) do
 64					local guildmembername = GetGuildRosterInfo(guildindex)
 65					if guildmembername == leader then
 66						AcceptGroup()
 67						break
 68					end
 69				end
 70			end
 71			
 72		elseif event == "PARTY_MEMBERS_CHANGED" and hidestatic == true then
 73			StaticPopup_Hide("PARTY_INVITE")
 74			hidestatic = false
 75		end
 76	end)
 77end
 78
 79------------------------------------------------------------------------
 80-- Auto invite by whisper
 81------------------------------------------------------------------------
 82
 83local ainvenabled = false
 84local ainvkeyword = "invite"
 85
 86local autoinvite = CreateFrame("frame")
 87autoinvite:RegisterEvent("CHAT_MSG_WHISPER")
 88autoinvite:SetScript("OnEvent", function(self,event,arg1,arg2)
 89	if ((not UnitExists("party1") or IsPartyLeader("player") or IsRaidOfficer("player") or IsRaidLeader("player")) and arg1:lower():match(ainvkeyword)) and ainvenabled == true then
 90		InviteUnit(arg2)
 91	end
 92end)
 93
 94function SlashCmdList.AUTOINVITE(msg, editbox)
 95	if msg == "off" then
 96		ainvenabled = false
 97		print(L.core_autoinv_disable)
 98	elseif msg == "" then
 99		ainvenabled = true
100		print(L.core_autoinv_enable)
101		ainvkeyword = "invite"
102	else
103		ainvenabled = true
104		print(L.core_autoinv_enable_c .. msg)
105		ainvkeyword = msg
106	end
107end
108SLASH_AUTOINVITE1 = "/ainv"