forked from brewk/wowspreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guildroster.js
253 lines (198 loc) · 8.34 KB
/
guildroster.js
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
/* ***********************************
*** Copyright (c) 2018 bruk
*** This script is free software; you can redistribute it and/or modify
*** it under the terms of the GNU General Public License as published by
*** the Free Software Foundation; either version 3 of the License, or
*** (at your option) any later version.
********************************** */
// formula usage =guild(region,realmName,guildName,maxRank,sortMethod,minLevel)
// max rank is the maximum rank to output, we do this to try avoid too many calls to the api for big guilds with lots of alts
// Accepted sort methods: Level, Rank, CheevoPts, Role, Name
// enter your api key here:
// if you have this as part of a combined spreadsheet you can comment this line out
// var apikey = "";
// **************** BLACKLIST / WHITELIST ****************
// You can put these variables into a seperate .gs script file to facilitate updating your script in the future
// BLACK LIST: Add player names who you don't want to show up
// Usage: var BLACKLIST = ["Name1", "Name2", "Name3"];
var BLACKLIST = [];
// WHITE LIST: Add player names who you want to ALWAYS show up no matter the filter
// Usage: var WHITELIST = ["Name1", "Name2", "Name3"];
var WHITELIST = [];
// Non-Guild WHITELIST: These are players not in your guild
// Because they will not be in your guild's API they cannot be sorted properly and will appear at the bottom of the list
// Usage: var NONGUILD = [["Realm", "Character"], ["Realm", "Character"]];
var NONGUILD = [];
// **************** RANK BLACKLIST / WHITE LIST ****************
// If you want a certain rank of players to never or always be shown
// enter their number in the brackets, seperated by commas. Guild Master rank is 0
// Individuals listed in the above white/blacklist section will override rank white/blacklisting
// BLACK LIST: Add number of the rank yo udon't want to show up
// Usage: var BLACKLIST = [3, 4, 8];
var RANKBLACKLIST = [];
// BLACK LIST: Add number of the rank yo udon't want to show up
// Usage: var RANKWHITELIST = [2, 5, 7];
var RANKWHITELIST = [];
// ******************************************************
/* globals UrlFetchApp apikey*/
/* exported guildOut vercheckGuild*/
var current_versionGuild = 1.05;
function guildOut(region,realmName,guildName,maxRank,sortMethod,minLevel)
{
if (!guildName || !realmName )
{
return "\u2063"; // If there's nothing don't even bother calling the API
}
if (!apikey)
{
return "Error: No API key entered. Please visit http://dev.battle.net/ to obtain one. Instructions availible at http://bruk.org/wow";
}
//Getting rid of any sort of pesky no width white spaces we may run into
region = region.replace(/[\u200B-\u200D\uFEFF]/g, "");
realmName = realmName.replace(/[\u200B-\u200D\uFEFF]/g, "");
if (maxRank<0 || maxRank>10)
{
return "Error loading API: try refreshing and verify values are typed correctly. Ensure your API key is entered into the script correctly. Errors can also come from loading 100+ characters at a time";
}
var options={ muteHttpExceptions:true };
var guildJSON = UrlFetchApp.fetch("https://"+region+".api.battle.net/wow/guild/"+realmName+"/"+guildName+"?fields=members&?locale=en_US&apikey="+apikey+"", options);
var guild = JSON.parse(guildJSON);
if (!guild.members)
{
return "Error: verify your apikey is entered and values are entered correctly";
}
var membermatrix = [];
var arrayPosition = 0;
var roleSort = ["Tank","Healer","Ranged","Melee","BlizzError"];//this is the order it is going to get sorted by. Swap thise around if you want it in another order
var roles = {
Tank: ["Blood","Protection","Guardian","Brewmaster","Vengeance"],
Healer: ["Restoration", "Holy", "Discipline", "Mistweaver"],
Ranged: ["Elemental","Beast Mastery","Marksmanship","Balance","Affliction","Demonology","Destruction","Arcane","Fire","Frost","Shadow"],
Melee: ["Retribution","Frost","Unholy","Arms","Fury","Survival","Enhancement","Feral","Windwalker","Outlaw","Assassination","Subtlety","Havoc"]
};//frost dks and frost mages needs its own check
var classes = [//this is for detemening what playerclass the variable class refers to. Needed when we want to check if frost refers to DK or Mage.
"Error",
"Warrior",
"Paladin",
"Hunter",
"Rogue",
"Priest",
"Death Knight",
"Shaman",
"Mage",
"Warlock",
"Monk",
"Druid",
"Demon Hunter",
];
for (var i=0; i<guild.members.length; i++)
{
//The "manual" and more accurate code for role
//It's still a touch buggy (seemingly for "stale" characters) but is currently much more accurate than the api
var whiteListed = false;
var blackListed = false;
if (RANKBLACKLIST.indexOf(guild.members[i].rank) > -1)
{
blackListed = true;
}
else if (RANKWHITELIST.indexOf(guild.members[i].rank) > -1 && guild.members[i].character.level >= minLevel)
{
whiteListed = true;
}
// whitelist/blacklist of individual names will override the rank Black/whitelisting
if (BLACKLIST.indexOf(guild.members[i].character.name) > -1)
{
blackListed = true;
}
else if (WHITELIST.indexOf(guild.members[i].character.name) > -1)
{
whiteListed = true;
}
if (((guild.members[i].rank <= maxRank && guild.members[i].character.level >= minLevel) || whiteListed )&& !blackListed )
{
var playerRole = "BlizzError";
if (guild.members[i].character.spec)
{
for (var role in roles)
{
if (guild.members[i].character.spec.name=="Frost")
{
playerRole = classes[guild.members[i].character.class]=="Mage" ? "Ranged": "Melee";
}
else if (roles[role].indexOf(guild.members[i].character.spec.name) != -1)
{
playerRole = role;
}
}
}
if (!guild.members[i].character.realm)
{
guild.members[i].character.realm = guild.members[i].character.guildRealm;
}
membermatrix[arrayPosition] = [guild.members[i].character.realm, guild.members[i].character.name, guild.members[i].rank, guild.members[i].character.achievementPoints, guild.members[i].character.level, roleSort.indexOf(playerRole), playerRole];
arrayPosition++;
} // ...end of manual code for role
}
if (NONGUILD[0])
{
for (i=0; i<NONGUILD.length; i++)
{
// not sure how this got weirded out, but thanks to @mattsmorrison for noticing it!
membermatrix[arrayPosition] = [NONGUILD[i][0], NONGUILD[i][1], 99, 0, -1, -1, "NonGuild"];
arrayPosition++;
}
}
switch (sortMethod)
{
case "Level":
membermatrix.sort(function(a,b)
{
return b[4]-a[4];
});
break;
case "Rank":
membermatrix.sort(function(a,b)
{
return a[2]-b[2];
});
break;
case "CheevoPts":
membermatrix.sort(function(a,b)
{
return (b[3] < a[3]) ? -1 : 1;
});
break;
case "Name":
membermatrix.sort(function(a,b)
{
return (a[1] < b[1]) ? -1 : 1;
});
break;
case "Role":
membermatrix.sort(function(a,b)
{
if (a[5] === -1)
{
a = roleSort.length;
}
if (b[5] === -1)
{
b = roleSort.length;
}
return a[5]-b[5];
});
break;
default:
break;
}
for (i = 0 ; i < membermatrix.length ; i++)
{
membermatrix[i].splice(2,4);
}
return membermatrix;
}
function vercheckGuild()
{
return current_versionGuild;
}
//When copy pasting, delete 0Looking at the bottom if it shows up, otherwise it'll cause an error