DiscordTickets/src/lib/users.js

31 lines
1014 B
JavaScript
Raw Normal View History

2022-10-04 23:23:01 +03:00
const { PermissionsBitField } = require('discord.js');
2022-08-06 00:21:55 +03:00
/**
*
* @param {import("client")} client
* @param {string} userId
* @returns {Promise<Collection<import("discord.js").Guild>}
*/
module.exports.getCommonGuilds = async (client, userId) => await client.guilds.cache.filter(async guild => {
const member = await guild.members.fetch(userId);
return !!member;
});
/**
*
* @param {import("discord.js").Guild} guild
* @param {string} userId
* @returns {Promise<boolean>}
*/
module.exports.isStaff = async (guild, userId) => {
/** @type {import("client")} */
const client = guild.client;
if (guild.client.supers.includes(userId)) return true;
const guildMember = await guild.members.fetch(userId);
2022-10-04 23:23:01 +03:00
if (guildMember?.permissions.has(PermissionsBitField.Flags.ManageGuild)) return true;
2022-08-06 00:21:55 +03:00
const { categories } = await client.prisma.guild.findUnique({
select: { categories: true },
where: { id: guild.id },
});
return categories.some(cat => cat.roles.some(r => guildMember.roles.cache.has(r)));
};