Isaac 5f77b28012
fix(http): fastify dependencies (closes #461, #491) (#520)
* 🚨 **[WIP]** fix: fastify dependencies

* update & fix http stuff
2024-01-21 02:19:26 +00:00

20 lines
731 B
JavaScript

const { PermissionsBitField } = require('discord.js');
module.exports.get = fastify => ({
handler: async (req, res) => {
const { client } = req.routeOptions.config;
const guilds = await (await fetch('https://discordapp.com/api/users/@me/guilds', { headers: { 'Authorization': `Bearer ${req.user.accessToken}` } })).json();
res.send(
guilds
.filter(guild => guild.owner || new PermissionsBitField(guild.permissions.toString()).has(PermissionsBitField.Flags.ManageGuild))
.map(guild => ({
added: client.guilds.cache.has(guild.id),
id: guild.id,
logo: `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.webp`,
name: guild.name,
})),
);
},
onRequest: [fastify.authenticate],
});