Files
hikari/bot/src/utils/checkEntitlement.ts
T
hikari b5d29025b3
Node.js CI / CI (pull_request) Failing after 1m5s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 1m48s
refactor: replace entitledUsers owner gate with naomiId
2026-03-23 15:08:37 -07:00

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 };