mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-07 06:45:31 +02:00
Add Patreon auto-setup
This commit is contained in:
@@ -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=
|
||||
|
||||
@@ -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();
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "140.1.0",
|
||||
"version": "140.1.1",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"private": true,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user