use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Intents {
pub bits: u32,
}
impl Intents {
pub const fn new() -> Self {
Self { bits: 0 }
}
pub const fn none() -> Self {
Self::new()
}
pub const fn all() -> Self {
Self {
bits: Self::GUILDS
| Self::GUILD_MEMBERS
| Self::GUILD_MESSAGES
| Self::GUILD_MESSAGE_REACTIONS
| Self::DIRECT_MESSAGE
| Self::INTERACTION
| Self::MESSAGE_AUDIT
| Self::FORUMS
| Self::AUDIO_ACTION
| Self::PUBLIC_GUILD_MESSAGES
| Self::AUDIO_OR_LIVE_CHANNEL_MEMBER
| Self::OPEN_FORUM_EVENT
| Self::ENTER_AIO
| Self::PUBLIC_MESSAGES,
}
}
pub const fn default() -> Self {
Self::all()
.without_intent(Self::GUILD_MESSAGES)
.without_intent(Self::FORUMS)
}
pub const GUILDS: u32 = 1 << 0;
pub const GUILD_MEMBERS: u32 = 1 << 1;
pub const GUILD_MESSAGES: u32 = 1 << 9;
pub const GUILD_MESSAGE_REACTIONS: u32 = 1 << 10;
pub const DIRECT_MESSAGE: u32 = 1 << 12;
pub const INTERACTION: u32 = 1 << 26;
pub const MESSAGE_AUDIT: u32 = 1 << 27;
pub const FORUMS: u32 = 1 << 28;
pub const AUDIO_ACTION: u32 = 1 << 29;
pub const PUBLIC_GUILD_MESSAGES: u32 = 1 << 30;
pub const AUDIO_OR_LIVE_CHANNEL_MEMBER: u32 = 1 << 19;
pub const OPEN_FORUM_EVENT: u32 = 1 << 18;
pub const ENTER_AIO: u32 = 1 << 23;
pub const PUBLIC_MESSAGES: u32 = 1 << 25;
pub const fn contains(self, intent: u32) -> bool {
(self.bits & intent) == intent
}
pub const fn with_intent(mut self, intent: u32) -> Self {
self.bits |= intent;
self
}
pub const fn without_intent(mut self, intent: u32) -> Self {
self.bits &= !intent;
self
}
pub const fn with_guilds(self) -> Self {
self.with_intent(Self::GUILDS)
}
pub const fn with_guild_members(self) -> Self {
self.with_intent(Self::GUILD_MEMBERS)
}
pub const fn with_guild_messages(self) -> Self {
self.with_intent(Self::GUILD_MESSAGES)
}
pub const fn with_guild_message_reactions(self) -> Self {
self.with_intent(Self::GUILD_MESSAGE_REACTIONS)
}
pub const fn with_direct_message(self) -> Self {
self.with_intent(Self::DIRECT_MESSAGE)
}
pub const fn with_interaction(self) -> Self {
self.with_intent(Self::INTERACTION)
}
pub const fn with_message_audit(self) -> Self {
self.with_intent(Self::MESSAGE_AUDIT)
}
pub const fn with_forums(self) -> Self {
self.with_intent(Self::FORUMS)
}
pub const fn with_audio_action(self) -> Self {
self.with_intent(Self::AUDIO_ACTION)
}
pub const fn with_public_guild_messages(self) -> Self {
self.with_intent(Self::PUBLIC_GUILD_MESSAGES)
}
pub const fn with_audio_or_live_channel_member(self) -> Self {
self.with_intent(Self::AUDIO_OR_LIVE_CHANNEL_MEMBER)
}
pub const fn with_open_forum_event(self) -> Self {
self.with_intent(Self::OPEN_FORUM_EVENT)
}
pub const fn with_enter_aio(self) -> Self {
self.with_intent(Self::ENTER_AIO)
}
pub const fn with_public_messages(self) -> Self {
self.with_intent(Self::PUBLIC_MESSAGES)
}
pub const fn guilds(self) -> bool {
self.contains(Self::GUILDS)
}
pub const fn guild_members(self) -> bool {
self.contains(Self::GUILD_MEMBERS)
}
pub const fn guild_messages(self) -> bool {
self.contains(Self::GUILD_MESSAGES)
}
pub const fn guild_message_reactions(self) -> bool {
self.contains(Self::GUILD_MESSAGE_REACTIONS)
}
pub const fn direct_message(self) -> bool {
self.contains(Self::DIRECT_MESSAGE)
}
pub const fn interaction(self) -> bool {
self.contains(Self::INTERACTION)
}
pub const fn message_audit(self) -> bool {
self.contains(Self::MESSAGE_AUDIT)
}
pub const fn forums(self) -> bool {
self.contains(Self::FORUMS)
}
pub const fn audio_action(self) -> bool {
self.contains(Self::AUDIO_ACTION)
}
pub const fn public_guild_messages(self) -> bool {
self.contains(Self::PUBLIC_GUILD_MESSAGES)
}
pub const fn audio_or_live_channel_member(self) -> bool {
self.contains(Self::AUDIO_OR_LIVE_CHANNEL_MEMBER)
}
pub const fn open_forum_event(self) -> bool {
self.contains(Self::OPEN_FORUM_EVENT)
}
pub const fn enter_aio(self) -> bool {
self.contains(Self::ENTER_AIO)
}
pub const fn public_messages(self) -> bool {
self.contains(Self::PUBLIC_MESSAGES)
}
pub const fn has_privileged(self) -> bool {
self.contains(Self::GUILD_MESSAGES) || self.contains(Self::FORUMS)
}
pub const fn bits(self) -> u32 {
self.bits
}
pub const fn from_bits(bits: u32) -> Self {
Self { bits }
}
}
impl Default for Intents {
fn default() -> Self {
Self::default()
}
}