-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathpatreonUpdate.js
69 lines (61 loc) · 1.66 KB
/
patreonUpdate.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
let request = require("request");
let _ = require("lodash");
let creator_access_token = process.env.NODE_PATREON_TOKEN;
let campaignID = "440241";
const fs = require("fs");
let apiPath = `campaigns/${campaignID}/members`;
function getData(path, params, done) {
let url = `https://www.patreon.com/api/oauth2/v2/${path}`;
if (params) {
url = `${url}?${params}`;
}
console.log("URL", url);
request(
{
url,
headers: {
Authorization: "Bearer " + creator_access_token,
"User-Agent": "PostmanRuntime/7.39.0",
},
},
(err, result, body) => {
if (err) return console.log("error trying to update patreon info ", err);
try {
body = JSON.parse(body);
} catch (error) {
return console.log(error, body);
}
return done(err, body);
}
);
}
function getMembers(members, newpath, done) {
return getData(apiPath, newpath, function (err, body) {
members = _.concat(
members,
_.map(body.data, function (member) {
return _.get(member, "attributes.full_name");
})
);
// console.log(members);
if (body.links && body.links.next) {
let params = new URL(body.links.next).searchParams;
return getMembers(members, params.toString(), done);
}
return done(err, members);
});
}
getMembers([], "fields%5Bmember%5D=full_name", function (err, result) {
let memberList = _.sortBy(result);
let output = `local GSE = GSE
local Statics = GSE.Static
Statics.Patrons = {
"${memberList.join('",\n "')}"
}`;
console.log(output);
fs.writeFile("GSE_Utils/Patrons.lua", output, (err) => {
if (err) {
console.error(err);
}
});
});