Add Patreon auto-setup

This commit is contained in:
Dragon Fire
2021-05-18 18:09:28 -04:00
parent 03df60a9a5
commit 3f92f68ad7
4 changed files with 42 additions and 1 deletions
+20
View File
@@ -22,6 +22,8 @@ const {
REPORT_CHANNEL_ID,
JOIN_LEAVE_CHANNEL_ID,
COMMAND_CHANNEL_ID,
PATREON_ACCESS_TOKEN,
PATREON_CAMPAIGN_ID,
TOP_GG_TOKEN,
BOTS_GG_TOKEN,
DISCORDBOTLIST_TOKEN,
@@ -45,6 +47,7 @@ module.exports = class XiaoClient extends CommandoClient {
this.webhook = new WebhookClient(XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN, { disableMentions: 'everyone' });
this.timers = new TimerManager(this);
this.blacklist = { guild: [], user: [] };
this.patrons = null;
this.pokemon = new PokemonStore();
this.games = new Collection();
this.dispatchers = new Map();
@@ -74,6 +77,23 @@ module.exports = class XiaoClient extends CommandoClient {
moment.tz.link('America/New_York|Dragon');
}
async fetchPatrons() {
if (!PATREON_ACCESS_TOKEN || !PATREON_CAMPAIGN_ID) return null;
const { body } = await request
.get(`https://www.patreon.com/api/oauth2/v2/campaigns/${PATREON_CAMPAIGN_ID}/members`)
.set({ Authorization: `Bearer ${PATREON_ACCESS_TOKEN}` })
.query({ 'fields[user]': 'user' });
const patrons = [];
for (const patron of body.data) {
if (patron.attributes.patron_status !== 'active_patron') continue;
const userData = patron.user.social_connections.discord;
if (!userData) continue;
patrons.push(userData.user_id);
}
this.patrons = patrons;
return patrons;
}
async postTopGGStats() {
if (!TOP_GG_TOKEN) return null;
try {