mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-02 16:41:25 +03:00
feat(api): show guilds that the bot isn't in
This commit is contained in:
@@ -27,7 +27,7 @@ module.exports = async client => {
|
||||
},
|
||||
},
|
||||
name: 'discord',
|
||||
scope: ['identify'],
|
||||
scope: ['applications.commands.permissions.update', 'guilds', 'identify'],
|
||||
startRedirectPath: '/auth/login',
|
||||
});
|
||||
|
||||
|
@@ -3,18 +3,17 @@ const { PermissionsBitField } = require('discord.js');
|
||||
module.exports.get = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
const { client } = res.context.config;
|
||||
const guilds = client.guilds.cache
|
||||
.filter(async guild => {
|
||||
const member = await guild.members.fetch(req.user.payload.id);
|
||||
if (!member) return false;
|
||||
return member.permissions.has(PermissionsBitField.Flags.ManageGuild);
|
||||
})
|
||||
.map(guild => ({
|
||||
id: guild.id,
|
||||
logo: guild.iconURL(),
|
||||
name: guild.name,
|
||||
}));
|
||||
res.send(guilds);
|
||||
const guilds = await (await fetch('https://discordapp.com/api/users/@me/guilds', { headers: { 'Authorization': `Bearer ${req.user.payload.access_token}` } })).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],
|
||||
});
|
@@ -1,16 +1,19 @@
|
||||
const { domain } = require('../../lib/http');
|
||||
|
||||
module.exports.get = () => ({
|
||||
handler: async function (req, res) { // must NOT use arrow function syntax
|
||||
handler: async function (req, res) { // MUST NOT use arrow function syntax
|
||||
const {
|
||||
access_token, expires_in,
|
||||
access_token,
|
||||
expires_in,
|
||||
} = await this.discord.getAccessTokenFromAuthorizationCodeFlow(req);
|
||||
const user = await (await fetch('https://discordapp.com/api/users/@me', { headers: { 'Authorization': `Bearer ${access_token}` } })).json();
|
||||
const payload = {
|
||||
access_token,
|
||||
avatar: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.webp`,
|
||||
discriminator: user.discriminator,
|
||||
expiresAt: Date.now() + (expires_in * 1000),
|
||||
id: user.id,
|
||||
locale: user.locale,
|
||||
username: user.username,
|
||||
|
||||
};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
module.exports.get = () => ({
|
||||
handler: async function (req, res) { // must NOT use arrow function syntax
|
||||
handler: async function (req, res) {
|
||||
res
|
||||
.clearCookie('token', '/')
|
||||
.send('Logged out.');
|
||||
|
Reference in New Issue
Block a user