use bitflags::__impl_bitflags;
use serde::{
de::{Deserialize, Deserializer},
ser::{Serialize, Serializer},
};
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
pub struct GatewayIntents {
pub bits: u64,
}
__impl_bitflags! {
GatewayIntents: u64 {
GUILDS = 1;
GUILD_MEMBERS = 1 << 1;
GUILD_BANS = 1 << 2;
GUILD_EMOJIS = 1 << 3;
GUILD_INTEGRATIONS = 1 << 4;
GUILD_WEBHOOKS = 1 << 5;
GUILD_INVITES = 1 << 6;
GUILD_VOICE_STATES = 1 << 7;
GUILD_PRESENCES = 1 << 8;
GUILD_MESSAGES = 1 << 9;
GUILD_MESSAGE_REACTIONS = 1 << 10;
GUILD_MESSAGE_TYPING = 1 << 11;
DIRECT_MESSAGES = 1 << 12;
DIRECT_MESSAGE_REACTIONS = 1 << 13;
DIRECT_MESSAGE_TYPING = 1 << 14;
}
}
impl Default for GatewayIntents {
fn default() -> Self {
Self::empty()
}
}
impl<'de> Deserialize<'de> for GatewayIntents {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Ok(Self::from_bits_truncate(u64::deserialize(deserializer)?))
}
}
impl Serialize for GatewayIntents {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_u64(self.bits())
}
}
#[cfg(feature = "model")]
impl GatewayIntents {
pub const fn non_privileged() -> GatewayIntents {
Self::from_bits_truncate(Self::all().bits() & !Self::privileged().bits())
}
pub const fn privileged() -> GatewayIntents {
Self::from_bits_truncate(Self::GUILD_MEMBERS.bits() | Self::GUILD_PRESENCES.bits())
}
pub fn is_privileged(self) -> bool {
self.guild_members() || self.guild_presences()
}
pub fn guilds(self) -> bool {
self.contains(Self::GUILDS)
}
pub fn guild_members(self) -> bool {
self.contains(Self::GUILD_MEMBERS)
}
pub fn guild_bans(self) -> bool {
self.contains(Self::GUILD_BANS)
}
pub fn guild_emojis(self) -> bool {
self.contains(Self::GUILD_EMOJIS)
}
pub fn guild_integrations(self) -> bool {
self.contains(Self::GUILD_INTEGRATIONS)
}
pub fn guild_webhooks(self) -> bool {
self.contains(Self::GUILD_WEBHOOKS)
}
pub fn guild_invites(self) -> bool {
self.contains(Self::GUILD_INVITES)
}
pub fn guild_voice_states(self) -> bool {
self.contains(Self::GUILD_VOICE_STATES)
}
pub fn guild_presences(self) -> bool {
self.contains(Self::GUILD_PRESENCES)
}
pub fn guild_message_reactions(self) -> bool {
self.contains(Self::GUILD_MESSAGE_REACTIONS)
}
pub fn guild_message_typing(self) -> bool {
self.contains(Self::GUILD_MESSAGE_TYPING)
}
pub fn direct_messages(self) -> bool {
self.contains(Self::DIRECT_MESSAGES)
}
pub fn direct_message_reactions(self) -> bool {
self.contains(Self::DIRECT_MESSAGE_REACTIONS)
}
pub fn direct_message_typing(self) -> bool {
self.contains(Self::DIRECT_MESSAGE_TYPING)
}
}