Update zz_Friends

This commit is contained in:
robin 2021-05-25 15:21:24 +02:00
parent 36a8822909
commit 2fa28f01a8
1 changed files with 23 additions and 10 deletions

View File

@ -2,7 +2,7 @@ local addonName, addon = ...
local childName = addon['childName'] local childName = addon['childName']
local child = addon[childName] local child = addon[childName]
local events = child['events'] local events = child['events']
local db, crealm local db
local fmt = "|c0000ff00%i|r/|c0000ffff%i|r|c00ff0000%s|r" local fmt = "|c0000ff00%i|r/|c0000ffff%i|r|c00ff0000%s|r"
local roster,friendroster,bnetroster = {}, {}, {} local roster,friendroster,bnetroster = {}, {}, {}
local GuildRoster = GuildRoster local GuildRoster = GuildRoster
@ -24,13 +24,29 @@ local function count(v)
end end
return c return c
end end
local function getBNFI(friendIndex)
if(C_BattleNet and C_BattleNet.GetFriendAccountInfo) then
return C_BattleNet.GetFriendAccountInfo(friendIndex)
else
local _, _, _, _, characterName, _, client, isOnline = BNGetFriendInfo(friendIndex)
if(characterName and isOnline and client == BNET_CLIENT_WOW) then
return {
['gameAccountInfo'] = {
['clientProgram'] = client,
['characterName'] = characterName,
['isOnline'] = isOnline
}
}
end
end
end
local function checkRoster(self, dummy, event, ...) local function checkRoster(self, dummy, event, ...)
local newroster = {} local newroster = {}
local rostername, online, _ local rostername, online, _
local dontShow = false local dontShow = false
if(event == "GUILD_ROSTER_UPDATE") then if(event == "GUILD_ROSTER_UPDATE") then
for i=1,GetNumGuildMembers() do for i = 1, GetNumGuildMembers() do
rostername, _, _, _, _, _, _, _, online = GetGuildRosterInfo(i) rostername, _, _, _, _, _, _, _, online = GetGuildRosterInfo(i)
if(online and rostername) then if(online and rostername) then
newroster[rostername]=true newroster[rostername]=true
@ -51,13 +67,13 @@ local function checkRoster(self, dummy, event, ...)
local _, numOnline = BNGetNumFriends() local _, numOnline = BNGetNumFriends()
local presenceID, isFriend,client,accid local presenceID, isFriend,client,accid
for i = 1, numOnline do for i = 1, numOnline do
local res = C_BattleNet.GetFriendAccountInfo(i) local res = getBNFI(i)
if(res) then if(res) then
local aci = res['gameAccountInfo'] local aci = res['gameAccountInfo']
dontShow = false dontShow = false
if(aci) then if(aci) then
if(aci['clientProgram'] == BNET_CLIENT_WOW) then if(aci['clientProgram'] == BNET_CLIENT_WOW) then
if(aci['realmName'] == crealm and friendroster[aci['characterName']]) then if(friendroster[aci['characterName']]) then
dontShow = true dontShow = true
end end
end end
@ -97,11 +113,8 @@ child['specs'] = {
} }
} }
function events:PLAYER_ENTERING_WORLD(event) function events:PLAYER_ENTERING_WORLD(event)
crealm = GetRealmName() child:UnregisterEvent('PLAYER_ENTERING_WORLD')
if(crealm) then child:RegisterEvent({"GUILD_ROSTER_UPDATE","FRIENDLIST_UPDATE","CHAT_MSG_CHANNEL_JOIN","CHAT_MSG_CHANNEL_LEAVE","PLAYER_FLAGS_CHANGED","UNIT_FLAGS","BN_FRIEND_INFO_CHANGED"}, checkRoster)
child:UnregisterEvent('PLAYER_ENTERING_WORLD') OnUpdate()
child:RegisterEvent({"GUILD_ROSTER_UPDATE","FRIENDLIST_UPDATE","CHAT_MSG_CHANNEL_JOIN","CHAT_MSG_CHANNEL_LEAVE","PLAYER_FLAGS_CHANGED","UNIT_FLAGS","BN_FRIEND_INFO_CHANGED"}, checkRoster)
OnUpdate()
end
end end
child:NewAddOn(...) child:NewAddOn(...)