generated from nhcarrigan/template
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
/**
|
|
* @copyright nhcarrigan
|
|
* @license Naomi's Public License
|
|
* @author Naomi Carrigan
|
|
*/
|
|
|
|
import { entitledGuilds, naomiId } from "../config/entitlements.js";
|
|
import type { Client, Guild, User } from "discord.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: Client,
|
|
user: User,
|
|
): Promise<boolean> => {
|
|
if (user.id === naomiId) {
|
|
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: Client,
|
|
guild: Guild,
|
|
): Promise<boolean> => {
|
|
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 };
|