feat: check discord entitlements

This commit is contained in:
Naomi Carrigan 2024-06-30 20:08:20 -07:00
parent 7437deab71
commit b64871791d
No known key found for this signature in database
GPG Key ID: 7019A402E94A9808
3 changed files with 2754 additions and 2164 deletions

View File

@ -21,7 +21,7 @@
}, },
"engines": { "engines": {
"node": "20", "node": "20",
"pnpm": "8" "pnpm": "9"
}, },
"homepage": "https://github.com/nhcarrigan/mod-bot#readme", "homepage": "https://github.com/nhcarrigan/mod-bot#readme",
"devDependencies": { "devDependencies": {

4804
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -13,9 +13,17 @@ import { ExtendedClient } from "../interfaces/ExtendedClient";
export const checkEntitledGuild = async ( export const checkEntitledGuild = async (
bot: ExtendedClient, bot: ExtendedClient,
guild: Guild guild: Guild
): Promise<boolean> => ): Promise<boolean> => {
Boolean( const isGuildEntitled = await bot.application?.entitlements
await bot.db.entitlements .fetch({
guild,
excludeEnded: true
})
.catch(() => null);
const isManuallyEntitled = await bot.db.entitlements
.findFirst({ where: { serverId: guild.id } }) .findFirst({ where: { serverId: guild.id } })
.catch(() => null) .catch(() => null);
return Boolean(
(isGuildEntitled && isGuildEntitled.size) || isManuallyEntitled
); );
};