-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathITTsRosterBotUtils.lua
157 lines (130 loc) · 4.64 KB
/
ITTsRosterBotUtils.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
local Utils = {}
ITTsRosterBot.Utils = Utils
Utils.memberCache = {}
local logger = LibDebugLogger( ITTsRosterBot.name .. " - Utils" )
logger:SetEnabled( false )
local SECONDS_IN_HOUR = 60 * 60
local SECONDS_IN_DAY = SECONDS_IN_HOUR * 24
local SECONDS_IN_WEEK = SECONDS_IN_DAY * 7
function Utils:CacheMembers()
for i = 1, GetNumGuilds() do
local guildId = GetGuildId( i )
local gname = GetGuildName( guildId )
local total = GetNumGuildMembers( guildId )
if gname ~= "" then
for l = 1, total do
local displayName, _, _, _, _ = GetGuildMemberInfo( guildId, l )
if self.memberCache[ displayName ] == nil then
self.memberCache[ displayName ] = {}
end
table.insert( self.memberCache[ displayName ], gname )
end
end
end
end
function Utils:HasValidHTag( needle, haystack, param )
local condition = false
if haystack and type( haystack ) == "string" then
if haystack:find( "^|[hH]" ) then
if string.find( haystack, "display" ) then
haystack = ZO_LinkHandler_ParseLink( haystack )
else
haystack = GetItemLinkName( haystack )
end
end
end
needle = string.lower( needle )
haystack = string.lower( haystack )
if string.find( haystack, needle ) ~= nil then
condition = true
end
return condition
end
function Utils:GetGuildDetails( settings )
local details = {}
details.id = 0
details.index = 0
if settings.index then
details.id = GetGuildId( settings.index )
details.index = settings.index
elseif settings.id or settings.name then
for i = 1, GetNumGuilds() do
if (settings.id and settings.id == GetGuildId( i )) or
(settings.name and settings.name == GetGuildName( GetGuildId( i ) )) then
details.index = i
details.id = GetGuildId( i )
break
end
end
end
details.name = GetGuildName( details.id )
return details
end
function Utils:GetGuildColor( guildIndex )
local r, g, b = GetChatCategoryColor( _G[ "CHAT_CATEGORY_GUILD_" .. tostring( guildIndex ) ] )
local colorObject = ZO_ColorDef:New( r, g, b )
return {
rgb = { r, g, b },
hex = colorObject:ToHex(),
zos = colorObject
}
end
function Utils:BuildInlineGuildName( settings )
local guild = self:GetGuildDetails( settings )
local color = self:GetGuildColor( guild.index )
return "|c" .. color.hex .. guild.name
end
function Utils:BuildInlineRelatedGuilds( displayName, guildId )
local guilds = self.memberCache[ displayName ]
-- local gtext = ""
local guildList = {}
local currentGuild = { name = "" }
if guildId then
currentGuild = self:GetGuildDetails( { id = guildId } )
end
if guilds ~= nil then
for k, v in pairs( guilds ) do
if currentGuild.name ~= nil and v == currentGuild.name then
else
-- if gtext ~= "" then
-- gtext = gtext .. ", "
-- end
-- gtext = gtext .. self:BuildInlineGuildName({ name = v })
table.insert( guildList, self:BuildInlineGuildName( { name = v } ) )
end
end
-- if gtext ~= "" then
-- gtext = gtext
-- end
end
return table.concat( guildList, "|cFFFFFF, " ), #guildList
end
--ITTsRosterBot.Utils:GetRelatedGuildInfo("@JN_Sepi0I")
--|H1:guild:559830|hEternal Forest Merchantry|h
function Utils:GetRelatedGuildInfo( displayName )
local memberInfo = {}
local count = 0
for i = 1, GetNumGuilds() do
local guildId = GetGuildId( i )
local memberIndex = GetGuildMemberIndexFromDisplayName( guildId, displayName )
local sales = 0
local name, memberNote, rankIndex, _, _ = GetGuildMemberInfo( guildId, memberIndex )
if displayName == name then
count = count + 1
local iconIndex = GetGuildRankIconIndex( guildId, rankIndex )
local rankIcon = GetGuildRankLargeIcon( iconIndex )
local guildColor = self:GetGuildColor( i ).hex
rankIcon = "|t25:25:" .. rankIcon .. ":inheritcolor|t"
logger:Warn( rankIcon )
if ITTsRosterBot:IsGuildEnabled( guildId ) then
memberInfo[ count ] = {
rankIndex = rankIndex,
rankIconString = rankIcon,
guildColor = guildColor,
guildId = guildId
}
end
end
end
return memberInfo
end