mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
Permission check utils
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { GuildMember } from 'discord.js';
|
import { BaseGuildTextChannel, BaseGuildVoiceChannel, Guild, GuildChannelResolvable, GuildMember, VoiceBasedChannel } from 'discord.js';
|
||||||
import { I18n } from 'i18n';
|
import { I18n } from 'i18n';
|
||||||
import { COMMON_EMBEDS } from '../discord/Settings';
|
import { COMMON_EMBEDS } from '../discord/Settings';
|
||||||
import { sendHybridInteractionMessageResponse } from './DiscordMessage';
|
import { sendHybridInteractionMessageResponse } from './DiscordMessage';
|
||||||
@@ -19,7 +19,57 @@ export async function checkMemberPermissions({
|
|||||||
|
|
||||||
if (!hasPermissions && data && locale)
|
if (!hasPermissions && data && locale)
|
||||||
await sendHybridInteractionMessageResponse(data, {
|
await sendHybridInteractionMessageResponse(data, {
|
||||||
embeds: [COMMON_EMBEDS.NO_PERMISSION(data, locale, permissions)]
|
embeds: [COMMON_EMBEDS.MEMBER_NO_PERMISSION(data, locale, permissions)]
|
||||||
|
});
|
||||||
|
|
||||||
|
return hasPermissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function checkBotPermissions({
|
||||||
|
guild,
|
||||||
|
permissions,
|
||||||
|
data,
|
||||||
|
locale
|
||||||
|
}: {
|
||||||
|
guild: Guild;
|
||||||
|
permissions: bigint[];
|
||||||
|
data?: HybridInteractionMessage;
|
||||||
|
locale?: I18n;
|
||||||
|
}): Promise<boolean> {
|
||||||
|
const member = guild.members.me;
|
||||||
|
if(!member) return false;
|
||||||
|
|
||||||
|
const hasPermissions = member.permissions.has(permissions);
|
||||||
|
|
||||||
|
if (!hasPermissions && data && locale)
|
||||||
|
await sendHybridInteractionMessageResponse(data, {
|
||||||
|
embeds: [COMMON_EMBEDS.BOT_NO_PERMISSION(data, locale, permissions)]
|
||||||
|
});
|
||||||
|
|
||||||
|
return hasPermissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function checkBotPermissionsInChannel({
|
||||||
|
guild,
|
||||||
|
channel,
|
||||||
|
permissions,
|
||||||
|
data,
|
||||||
|
locale
|
||||||
|
}: {
|
||||||
|
guild: Guild;
|
||||||
|
channel: GuildChannelResolvable;
|
||||||
|
permissions: bigint[];
|
||||||
|
data?: HybridInteractionMessage;
|
||||||
|
locale?: I18n;
|
||||||
|
}): Promise<boolean> {
|
||||||
|
const member = guild.members.me;
|
||||||
|
if(!member) return false;
|
||||||
|
|
||||||
|
const hasPermissions = member.permissionsIn(channel).has(permissions);
|
||||||
|
|
||||||
|
if (!hasPermissions && data && locale)
|
||||||
|
await sendHybridInteractionMessageResponse(data, {
|
||||||
|
embeds: [COMMON_EMBEDS.BOT_NO_PERMISSION(data, locale, permissions)]
|
||||||
});
|
});
|
||||||
|
|
||||||
return hasPermissions;
|
return hasPermissions;
|
||||||
|
|||||||
Reference in New Issue
Block a user