diff --git a/.env.example b/.env.example index 99ef9cd5..403f5f4f 100644 --- a/.env.example +++ b/.env.example @@ -66,6 +66,8 @@ GOV_KEY= IMGUR_KEY= OPENWEATHERMAP_KEY= OSU_KEY= +PATREON_ACCESS_TOKEN= +PATREON_CAMPAIGN_ID= PERSONAL_GOOGLE_CALENDAR_ID= SPOTIFY_KEY= SPOTIFY_SECRET= diff --git a/Xiao.js b/Xiao.js index 01a6e1d4..c8ed98b4 100644 --- a/Xiao.js +++ b/Xiao.js @@ -211,6 +211,25 @@ client.on('ready', async () => { client.logger.error(`[NSFW MODEL] Failed to load NSFW model\n${err.stack}`); } + // Import Patrons + try { + await client.fetchPatrons(); + for (const patron of client.patrons) { + if (client.allowedUsers.includes(patron)) continue; + client.allowedUsers.push(patron); + } + setInterval(() => { + client.fetchPatrons().catch(() => null); + for (const patron of client.patrons) { + if (client.allowedUsers.includes(patron)) continue; + client.allowedUsers.push(patron); + } + }, 3.6e+6); + client.logger.info(`[PATREON] Fetched ${client.patrons.length} patrons.`); + } catch (err) { + client.logger.error(`[PATREON] Failed to fetch patrons:\n${err.stack}`); + } + // Post bot list stats await client.postTopGGStats(); await client.postBotsGGStats(); diff --git a/package.json b/package.json index 36f9c5b5..791d445b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "140.1.0", + "version": "140.1.1", "description": "Your personal server companion.", "main": "Xiao.js", "private": true, diff --git a/structures/Client.js b/structures/Client.js index 64273798..dce1f833 100644 --- a/structures/Client.js +++ b/structures/Client.js @@ -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 {