generated from nhcarrigan/template
feat: build out discord support agent
All checks were successful
Node.js CI / Lint and Test (pull_request) Successful in 1m17s
All checks were successful
Node.js CI / Lint and Test (pull_request) Successful in 1m17s
This commit is contained in:
41
bot/prod/utils/checkEntitlement.js
Normal file
41
bot/prod/utils/checkEntitlement.js
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { entitledGuilds, entitledUsers } from "../config/entitlements.js";
|
||||
/**
|
||||
* Checks if a user has subscribed.
|
||||
* @param hikari - Hikari's Discord instance.
|
||||
* @param user - The user to check.
|
||||
* @returns A boolean indicating whether the user has an active subscription.
|
||||
*/
|
||||
const checkUserEntitlement = async (hikari, user) => {
|
||||
if (entitledUsers.includes(user.id)) {
|
||||
return true;
|
||||
}
|
||||
const entitlements = await hikari.application?.entitlements.fetch({
|
||||
excludeDeleted: true,
|
||||
excludeEnded: true,
|
||||
user: user,
|
||||
});
|
||||
return Boolean(entitlements && entitlements.size > 0);
|
||||
};
|
||||
/**
|
||||
* Checks if a guild has subscribed.
|
||||
* @param hikari - Hikari's Discord instance.
|
||||
* @param guild - The guild to check.
|
||||
* @returns A boolean indicating whether the guild has an active subscription.
|
||||
*/
|
||||
const checkGuildEntitlement = async (hikari, guild) => {
|
||||
if (entitledGuilds.includes(guild.id)) {
|
||||
return true;
|
||||
}
|
||||
const entitlements = await hikari.application?.entitlements.fetch({
|
||||
excludeDeleted: true,
|
||||
excludeEnded: true,
|
||||
guild: guild,
|
||||
});
|
||||
return Boolean(entitlements && entitlements.size > 0);
|
||||
};
|
||||
export { checkUserEntitlement, checkGuildEntitlement };
|
Reference in New Issue
Block a user