zz_MiscHelper/Moduls/autogroup.lua

98 lines
2.7 KiB
Lua

local name, addon = ...
local modName = "autogroup"
local message = {
["enUS"] = "Autoaccept invites",
["deDE"] = "Gruppeneinladungen annehmen"
}
local f
local accepted = false
addon['mhmods'] = addon['mhmods'] or {}
local defaults = {
['fugonly'] = true,
}
local function myGuild(unitname)
for i=1,GetNumGuildMembers() do
local rostername, _, _, _, _, _, _, _, online = GetGuildRosterInfo(i)
if(rostername) then
local shortname = strsplit("-",rostername,2)
if(online and (rostername == unitname or shortname == unitname)) then
return true
end
end
end
return false
end
local function myFriend(unitname)
for i = 1, C_FriendList.GetNumFriends() do
local res = C_FriendList.GetFriendInfoByIndex(i)
if(res and res['connected']) then
local shortname = strsplit("-",res['name'],2)
if(res['name'] == unitname or shortname == unitname) then
return true
end
end
end
return false
end
local function myBNetFriend(unitname)
local numFriends,numOnline = BNGetNumFriends()
for i = 1, numFriends do
local res = C_BattleNet.GetFriendAccountInfo(i)
if(res and res['gameAccountInfo'] and res['gameAccountInfo']['isOnline']) then
if(res['gameAccountInfo']['clientProgram'] == BNET_CLIENT_WOW) then
return res['gameAccountInfo']['characterName'] == unitname
end
end
end
end
local function getPref2(key)
local db = addon['MH_GetDB'](modName, defaults)
return db[key]
end
local function getPref(pref)
return getPref2(pref[#pref])
end
local function setPref(pref,value)
local db = addon['MH_GetDB'](modName, defaults)
db[pref[#pref]] = value
end
local options
local function watch(self)
if(self['delay'] > GetTime()) then return end
for index = 1, STATICPOPUP_NUMDIALOGS, 1 do
local frame = _G["StaticPopup"..index];
if( frame:IsShown() and (frame['which'] == "PARTY_INVITE") ) then
local btn = _G["StaticPopup"..index..(accepted and "Button1" or "Button2")]
btn:GetScript("OnClick")(btn,'LeftButton',0)
end
end
accepted = nil
self:Hide()
end
addon['mhmods'][#addon['mhmods'] + 1] = {
['name'] = modName,
['message'] = message[GetLocale()] or message["enUS"],
['init'] = function()
f = CreateFrame("Frame")
f['delay']=0
f:Hide()
f:SetScript("OnUpdate", watch)
options = addon['MH_GetOptions']()
local grp = addon:AddConfigMenu({['name'] = modName, ['order'] = 20,['menuGet'] = getPref,['menuSet'] = setPref},options)
addon:AddConfigEntry("zz_MiscHelper","toggle","fugonly","Friends&Guild only",nil,1,nil,nil,nil,nil,grp)
end,
['events'] = { "PARTY_INVITE_REQUEST" },
['onevent'] = function (event, arg1)
if((getPref2('fugonly') and (myBNetFriend(arg1) or myFriend(arg1) or myGuild(arg1))) or not getPref2('fugonly')) then
accepted = true
end
f['delay'] = GetTime() + 0.25
f:Show()
end,
}