Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(gateway,model)!: rename GUILD_EMOJIS intent and make corresponding changes #1520

Merged
merged 12 commits into from
Feb 10, 2022
9 changes: 5 additions & 4 deletions cache/in-memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ impl InMemoryCache {

/// Gets an emoji by ID.
///
/// This requires the [`GUILD_EMOJIS`] intent.
/// This requires the [`GUILD_EMOJIS_AND_STICKERS`] intent.
///
/// [`GUILD_EMOJIS`]: ::twilight_model::gateway::Intents::GUILD_EMOJIS
/// [`GUILD_EMOJIS_AND_STICKERS`]: ::twilight_model::gateway::Intents::GUILD_EMOJIS_AND_STICKERS
pub fn emoji(
&self,
emoji_id: Id<EmojiMarker>,
Expand Down Expand Up @@ -516,10 +516,10 @@ impl InMemoryCache {

/// Gets the set of emojis in a guild.
///
/// This requires both the [`GUILDS`] and [`GUILD_EMOJIS`] intents.
/// This requires both the [`GUILDS`] and [`GUILD_EMOJIS_AND_STICKERS`] intents.
HTGAzureX1212 marked this conversation as resolved.
Show resolved Hide resolved
///
/// [`GUILDS`]: ::twilight_model::gateway::Intents::GUILDS
/// [`GUILD_EMOJIS`]: ::twilight_model::gateway::Intents::GUILD_EMOJIS
/// [`GUILD_EMOJIS_AND_STICKERS`]: ::twilight_model::gateway::Intents::GUILD_EMOJIS_AND_STICKERS
HTGAzureX1212 marked this conversation as resolved.
Show resolved Hide resolved
pub fn guild_emojis(
&self,
guild_id: Id<GuildMarker>,
Expand Down Expand Up @@ -940,6 +940,7 @@ impl UpdateCache for Event {
GuildCreate(v) => c.update(v.deref()),
GuildDelete(v) => c.update(v.deref()),
GuildEmojisUpdate(v) => c.update(v),
GuildStickersUpdate(v) => c.update(v),
GuildIntegrationsUpdate(_) => {}
GuildUpdate(v) => c.update(v.deref()),
IntegrationCreate(v) => c.update(v.deref()),
Expand Down
3 changes: 2 additions & 1 deletion examples/gateway-metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
// Initialize the tracing subscriber.
tracing_subscriber::fmt::init();

let intents = Intents::GUILD_BANS | Intents::GUILD_EMOJIS | Intents::GUILD_MESSAGES;
let intents =
Intents::GUILD_BANS | Intents::GUILD_EMOJIS_AND_STICKERS | Intents::GUILD_MESSAGES;
let (cluster, mut events) = Cluster::new(env::var("DISCORD_TOKEN")?, intents).await?;
println!("Created cluster");

Expand Down
2 changes: 1 addition & 1 deletion gateway/src/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let token = env::var("DISCORD_TOKEN")?;
//! let intents = Intents::GUILD_BANS | Intents::GUILD_EMOJIS | Intents::GUILD_MESSAGES;
//! let intents = Intents::GUILD_BANS | Intents::GUILD_EMOJIS_AND_STICKERS | Intents::GUILD_MESSAGES;
//! let (cluster, mut events) = Cluster::new(token, intents).await?;
//! let cluster = Arc::new(cluster);
//! cluster.up().await;
Expand Down
12 changes: 8 additions & 4 deletions gateway/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ bitflags! {
const GUILD_EMOJIS_UPDATE = 1 << 12;
/// A guild's integrations have been updated.
const GUILD_INTEGRATIONS_UPDATE = 1 << 13;
/// A guild's stickers have been updated.
const GUILD_STICKERS_UPDATE = 1 << 63;
/// A guild has been updated.
const GUILD_UPDATE = 1 << 14;
/// A guild integration was created.
Expand Down Expand Up @@ -195,11 +197,12 @@ impl EventTypeFlags {
EventTypeFlags::BAN_ADD.bits() | EventTypeFlags::BAN_REMOVE.bits(),
);

/// All [`EventTypeFlags`] in [`Intents::GUILD_EMOJIS`].
/// All [`EventTypeFlags`] in [`Intents::GUILD_EMOJIS_AND_STICKERS`].
///
/// [`Intents::GUILD_EMOJIS`]: crate::Intents::GUILD_EMOJIS
pub const GUILD_EMOJIS: EventTypeFlags =
EventTypeFlags::from_bits_truncate(EventTypeFlags::GUILD_EMOJIS_UPDATE.bits());
/// [`Intents::GUILD_EMOJIS_AND_STICKERS`]: crate::Intents::GUILD_EMOJIS_AND_STICKERS
pub const GUILD_EMOJIS_AND_STICKERS: EventTypeFlags = EventTypeFlags::from_bits_truncate(
EventTypeFlags::GUILD_EMOJIS_UPDATE.bits() | EventTypeFlags::GUILD_STICKERS_UPDATE.bits(),
);

/// All [`EventTypeFlags`] in [`Intents::GUILD_INTEGRATIONS`].
///
Expand Down Expand Up @@ -287,6 +290,7 @@ impl From<EventType> for EventTypeFlags {
EventType::GuildDelete => EventTypeFlags::GUILD_DELETE,
EventType::GuildEmojisUpdate => EventTypeFlags::GUILD_EMOJIS_UPDATE,
EventType::GuildIntegrationsUpdate => EventTypeFlags::GUILD_INTEGRATIONS_UPDATE,
EventType::GuildStickersUpdate => EventTypeFlags::GUILD_STICKERS_UPDATE,
EventType::GuildUpdate => EventTypeFlags::GUILD_UPDATE,
EventType::IntegrationCreate => EventTypeFlags::INTEGRATION_CREATE,
EventType::IntegrationDelete => EventTypeFlags::INTEGRATION_DELETE,
Expand Down
2 changes: 2 additions & 0 deletions model/src/gateway/event/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum EventType {
GuildDelete,
GuildEmojisUpdate,
GuildIntegrationsUpdate,
GuildStickersUpdate,
GuildUpdate,
IntegrationCreate,
IntegrationDelete,
Expand Down Expand Up @@ -97,6 +98,7 @@ impl EventType {
Self::GuildDelete => Some("GUILD_DELETE"),
Self::GuildEmojisUpdate => Some("GUILD_EMOJIS_UPDATE"),
Self::GuildIntegrationsUpdate => Some("GUILD_INTEGRATIONS_UPDATE"),
Self::GuildStickersUpdate => Some("GUILD_STICKERS_UPDATE"),
Self::GuildUpdate => Some("GUILD_UPDATE"),
Self::IntegrationCreate => Some("INTEGRATION_CREATE"),
Self::IntegrationDelete => Some("INTEGRATION_DELETE"),
Expand Down
3 changes: 3 additions & 0 deletions model/src/gateway/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub enum Event {
GuildEmojisUpdate(GuildEmojisUpdate),
/// A guild's integrations were updated.
GuildIntegrationsUpdate(GuildIntegrationsUpdate),
/// A guild's stickers were updated.
GuildStickersUpdate(GuildStickersUpdate),
/// A guild was updated.
GuildUpdate(Box<GuildUpdate>),
/// A guild integration was created.
Expand Down Expand Up @@ -181,6 +183,7 @@ impl Event {
Self::GuildDelete(_) => EventType::GuildDelete,
Self::GuildEmojisUpdate(_) => EventType::GuildEmojisUpdate,
Self::GuildIntegrationsUpdate(_) => EventType::GuildIntegrationsUpdate,
Self::GuildStickersUpdate(_) => EventType::GuildStickersUpdate,
Self::GuildUpdate(_) => EventType::GuildUpdate,
Self::IntegrationCreate(_) => EventType::IntegrationCreate,
Self::IntegrationDelete(_) => EventType::IntegrationDelete,
Expand Down
6 changes: 4 additions & 2 deletions model/src/gateway/intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ bitflags! {
/// [`GUILD_BAN_ADD`]: super::event::Event::BanAdd
/// [`GUILD_BAN_REMOVE`]: super::event::Event::BanRemove
const GUILD_BANS = 1 << 2;
/// Guild emojis intent.
/// Guild emojis and stickers intent.
///
/// Event(s) received:
/// - [`GUILD_EMOJIS_UPDATE`]
/// - [`GUILD_STICKERS_UPDATE`]
///
/// [`GUILD_EMOJIS_UPDATE`]: super::event::Event::GuildEmojisUpdate
const GUILD_EMOJIS = 1 << 3;
/// [`GUILD_STICKERS_UPDATE`]: super::event::Event::GuildStickersUpdate
const GUILD_EMOJIS_AND_STICKERS = 1 << 3;
/// Guild integrations intent.
///
/// Event(s) received:
Expand Down
1 change: 1 addition & 0 deletions standby/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub const fn guild_id(event: &Event) -> Option<Id<GuildMarker>> {
Event::GuildDelete(e) => Some(e.id),
Event::GuildEmojisUpdate(e) => Some(e.guild_id),
Event::GuildIntegrationsUpdate(e) => Some(e.guild_id),
Event::GuildStickersUpdate(e) => Some(e.guild_id),
Event::GuildUpdate(e) => Some(e.0.id),
Event::IntegrationCreate(e) => e.0.guild_id,
Event::IntegrationDelete(e) => Some(e.guild_id),
Expand Down