forked from brewk/wowspreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguildoutput.js
83 lines (66 loc) · 2.24 KB
/
guildoutput.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
/* ***********************************
*** Copyright (c) 2016 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, realm, guildname, outputMethod)
// outputMethod should be 0 or 1
// method 0 = output by rank
// method 1 = output by achievement points, to find alts
// enter your api key here:
// if you have this as part of a combined spreadsheet you can comment this line out
var apikey = "";
/* globals UrlFetchApp */
/* exported guildOut */
function sortFunction(a, b)
{
if (a[0] === b[0])
{
return 0;
}
else
{
return (a[0] > b[0]) ? -1 : 1;
}
}
function guildOut(region,realmName,guildName,outputMethod)
{
if (!guildName || !realmName )
{
return "\u2063"; // If there's nothing don't even bother calling the API
}
//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 (outputMethod != 0 && outputMethod != 1)
{
return "Invalid outputMethod, please select 0 for rank output, or 1 for alt finder";
}
var guildJSON = UrlFetchApp.fetch("https://"+region+".api.battle.net/wow/guild/"+realmName+"/"+guildName+"?fields=members&?locale=en_US&apikey="+apikey+"");
var guild = JSON.parse(guildJSON);
var membermatrix = [ ];
var rank = 0;
if (outputMethod === 1)
{
for (var i=0; i<guild.members.length; i++)
{
membermatrix[i] = [guild.members[i].character.achievementPoints, guild.members[i].character.name, guild.members[i].rank];
}
membermatrix.sort(sortFunction);
}
else
{
for (i=0; i<10; i++)
{
membermatrix[i] = [];
}
for (i=0; i<guild.members.length; i++)
{
rank=guild.members[i].rank;
membermatrix[rank].push(guild.members[i].character.name);
}
}
return membermatrix;
}