forked from TheGeneticsGuy/Guild-Roster-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGRM_API.lua
268 lines (196 loc) · 10.3 KB
/
GRM_API.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
-- GRM PUBLIC ACCESS API TO QUERY GRM DATABASE
-- NOTES ON USE AND DESIGN STYLE
-- Note 1: Name format input
-- Since GRM deals with so many aspects of merged realm, cross-realm, classic and retail servers, all as a single universal code-base, to make our lives easier a full "Name-Server" format must be used for implementation on input. The server MUST be in the proper Blizzard database format too which I will explain below. Be aware that when querying the Blizzard servers this automatically has the name-serverName in proper format, so you don't need to do much work here, but for people that might be more hands-on in customizing the input arguments, follow these recommendations.
-- Example on Name Format:
-- Name: Arkaan-Zul'jin -- CORRECT
-- Name: Arkaan -- INCORRECT
--
-- Example on Server Format:
-- Name: Arkaan-AlteracMountains -- CORRECT
-- Name: Arkaan-Alterac Mountains -- INCORRECT
-- Note: The server name must also be appended to the name of the guild.
-- guildName: "Is a Subatomic Particle-Zul'jin" -- CORRECT
-- guildName: "Is a Subatomic Particle" -- INCORRECT
-- There are many varied realm names beyond just a simple white space removal, so I wrote a script to auto-format your guild name to the proper format, if needed at all. I suspect most will never need it.
-- Function: GRM_API.ConvertRealmNameToDatabaseFormat ( realmName );
-- Note 2: Return results
-- If the player calls a function and it returns "nil" then one can assume there is no data to return. In other words, the player is non-existent given the input.
-- Example:
-- local isMain = GRM_API.IsMain( playerName ); -- One could also write it: local isMain = playerName:GRM_API.IsMain();
--
-- If the "isMain" variable is true/false, then we know the player has been found in the database AND they are or are not a main. If the "isMain" == nil, then the playerName was not found in the given database.
-- Note 3: Default inputs can be changed
-- By default, to make this as simple as possible, the only thing that needs to be entered as an input is the player's name. The code will auto-default to using your current faction and guild as the database to look through. However, if you wish, you can modify the database query to any faction/guild you wish.
-- Example:
-- "Default" local isMain = GRM_API.IsMain ( "Arkaan-Zul'jin" ) -- CORRECT -- addon defaults to current faction and guild
-- This "default" == local isMain = GRM_API.IsMain ( "Arkaan-Zul'jin" , "Is a Subatomic Particle-Zul'jin" ) -- CORRECT -- This is the exact same thing as previous. As can be seen, previous format is to simplify process.
-- "Search Database" local isMain = GRM_API.IsMain ( "Arkaan-Tanaris" , "Dawn of the Dead-Tanaris" ) -- CORRECT -- addon now searches current faction, but guild on another server
-- Note: You will receive an error text notifaction that catches the failure to find results in a query. It will inform you what it could not find, the guild or the player. This will auto-query the whole databse be it Horde or Ally, so the only thing you really need to ensure is proper playerName spelling and proper guildName spelling/formatting.
-- FUNCTION ARGUMENTS
--
-- [, argument] -- this indicates an "optional" argument.
-- EXAMPLE: GRM_API.IsMain ( string [, string ] )
--
-- GRM_API.IsMain ( "Arkaan-Zul'jin" ) -- CORRECT
-- GRM_API.IsMain ( "Arkaan-ConnectedRealm" , "connectedRealmGuild-ConnectedRealm" ) -- CORRECT
-- Table to hold all methods.
GRM_API = {};
GRM_API.Initialized = false;
-- GRM API ACCESS MISC - Public use general tools further down
-- Method: GateCheck ( string , string )
-- What it Does: Acts as a gate check to not throw errors, validates input information
-- Purpose: Since this is public access API, it is being built with some safeguards in place to prevent Lua errors.
local function GateCheck ( playerName , guildName )
if not GRM_API.Initialized then -- return nil every time until initialized
return;
end
local isValid = true;
local gName,f;
-- Guild Name Check
local gName = guildName or GRM_G.guildName;
if gName == "" then
isValid = false;
end
-- Validate player info
if isValid then
if GRM_G.F == "H" then
f = "A";
else
f = "H";
end
if not GRM_GuildMemberHistory_Save[GRM_G.F][gName] and not GRM_GuildMemberHistory_Save[f][gName] then
isValid = false;
GRM.Report ( GRM.L ( "GRM API Error:" ) .. " " .. GRM.L ( "The guild name \"{name}\" cannot be found in the database. Ensure proper formatting." , gName ) );
else
-- Setting which faction it is properly for return
if GRM_GuildMemberHistory_Save[GRM_G.F][gName] then
f = GRM_G.F;
end
end
if isValid then
if not GRM_GuildMemberHistory_Save[f][gName][playerName] then
isValid = false;
GRM.Report ( GRM.L ( "GRM API Error:" ) .. " " .. GRM.L ( "The player name \"{name}\" cannot be found in the database. Ensure proper spelling." , playerName ) );
end
end
end
return isValid , gName , f;
end
-- Method: GRM_API.ConvertRealmToDatabaseFormat ( string )
-- What it Does: Converts the Realm format to proper format\
-- Purpose: Necessary for database talk.
GRM_API.ConvertRealmNameToDatabaseFormat = function ( realmName )
return string.gsub ( string.gsub ( realmName , "-" , "" ) , "%s+" , "" );
end
-- Method: GRM.ClearFriendsList()
-- What it Does: Clears the entire server side, non-battletag friends list completely to zero
-- Purpose: For debugging cleanup
GRM_API.ClearFriendsList = function()
for i = C_FriendList.GetNumFriends() , 1 , -1 do
local name = C_FriendList.GetFriendInfoByIndex ( i ).name;
C_FriendList.RemoveFriend ( name );
end
end
-- Method: GRM.ClearAllOfficerNotes()
-- What it Does: Clears every officer note to every player in the guild
-- Purpose: Mass cleanup abilities
GRM_API.ClearAllOfficerNotes = function()
if CanEditOfficerNote() then
for i = 1 , GetNumGuildMembers() do
GuildRosterSetOfficerNote ( i , "" );
end
else
if IsInGuild() then
GRM.Report ( GRM.L ( "Unable to change officer notes at current rank" ) );
else
GRM.Report ( GRM.L ( "Player is not currently in a Guild" ) );
end
end
end
--------------------------------
-- Public Access GRM database --
--------------------------------
-- Method: GRM_API.GetMemberData ( string [, string ] )
-- What it Does: Returns the entire metaData profile on a player as a table. The data is washed and rebuilt so the values cannot be modified.
-- Purpose: Database access
GRM_API.GetMemberData = function ( playerName , guildName )
local valid , memberData , gName , faction;
valid , gName , faction = GateCheck ( playerName , gName );
if valid then
memberData = GRM.DeepCopyArray ( GRM_GuildMemberHistory_Save[faction][gName][playerName] );
end
return valid , memberData
end
-- Method: GRM_API.GetMain ( string [, string ] );
-- What it does: Returns the player's main if they are part of an alt grouping. Or, retuns nil if there is no main designation. It can return its own name.
-- Purpose: Database access
GRM_API.GetMain = function( playerName , guildName )
local valid , result , gName , faction;
valid , gName , faction = GateCheck ( playerName , guildName );
if valid then
if GRM_GuildMemberHistory_Save[faction][gName][playerName].isMain then
result = playerName;
elseif #GRM_GuildMemberHistory_Save[faction][gName][playerName].alts > 0 then
local alts = GRM_GuildMemberHistory_Save[faction][gName][playerName].alts;
for i = 1 , #alts do
-- main found!
if alts[i][5] then
result = GRM.DeepCopyArray ( alts[i][1] );
break;
end
end
end
end
return result;
end
-- Method: GRM_API.IsMain ( string [, string ] );
-- What it does: Returns true or false if the player is a main. If player cannot be found, it returns nil.
-- Purpose: Database access
GRM_API.IsMain = function( playerName , guildName )
local valid , result , faction , gName;
valid , gName , faction = GateCheck ( playerName , guildName );
if valid then
if GRM_GuildMemberHistory_Save[faction][gName][playerName].isMain then
result = true;
else
result = false;
end
end
return result;
end
GRM_API.GetAlts = function( playerName , namesOnly , guildName )
local valid , result , gName , faction;
valid , gName , faction = GateCheck ( playerName , gName );
if valid then
end
return result;
end
GRM_API.GetJoinDate = function( playerName , getOriginal , guildName )
local valid , result , gName , faction , verified;
valid , gName , faction = GateCheck ( playerName , gName );
if valid then
end
return result , verified;
end
GRM_API.GetLastPromotionDate = function( playerName , guildName )
local valid , result , gName , faction , verified;
valid , gName , faction = GateCheck ( playerName , gName );
if valid then
end
return result , verified;
end
GRM_API.GetBirthday = function( playerName , guildName )
local valid , day , month , timestamp , gName , faction;
valid , gName , faction = GateCheck ( playerName , gName );
if valid then
end
return day , month, timestamp;
end
GRM_API.GetCustomNote = function( playerName , guildName )
local valid , result , gName , faction;
valid , gName , faction = GateCheck ( playerName , gName );
if valid then
end
return result;
end