Skip to content

Commit 677dc72

Browse files
committed
feat(gateway): Add Intents to EventTypeFlags mapping
1 parent 1b9581b commit 677dc72

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

twilight-gateway/src/event.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Optimization for skipping deserialization of unwanted events.
22
33
use bitflags::bitflags;
4-
use twilight_model::gateway::{OpCode, event::EventType};
4+
use twilight_model::gateway::{Intents, OpCode, event::EventType};
55

66
bitflags! {
77
/// Important optimization for narrowing requested event types.
@@ -335,6 +335,40 @@ bitflags! {
335335
}
336336
}
337337

338+
impl From<Intents> for EventTypeFlags {
339+
fn from(intents: Intents) -> Self {
340+
let mut event_type_flags = Self::empty();
341+
342+
for intent in intents {
343+
event_type_flags |= match intent {
344+
Intents::AUTO_MODERATION_CONFIGURATION => Self::AUTO_MODERATION_CONFIGURATION,
345+
Intents::AUTO_MODERATION_EXECUTION => Self::AUTO_MODERATION_EXECUTION,
346+
Intents::DIRECT_MESSAGES => Self::DIRECT_MESSAGES,
347+
Intents::DIRECT_MESSAGE_REACTIONS => Self::DIRECT_MESSAGE_REACTIONS,
348+
Intents::DIRECT_MESSAGE_TYPING => Self::DIRECT_MESSAGE_TYPING,
349+
Intents::GUILDS => Self::GUILDS,
350+
Intents::GUILD_MODERATION => Self::GUILD_MODERATION,
351+
Intents::GUILD_EMOJIS_AND_STICKERS => Self::GUILD_EMOJIS_AND_STICKERS,
352+
Intents::GUILD_INTEGRATIONS => Self::GUILD_INTEGRATIONS,
353+
Intents::GUILD_INVITES => Self::GUILD_INVITES,
354+
Intents::GUILD_MEMBERS => Self::GUILD_MEMBERS,
355+
Intents::GUILD_MESSAGES => Self::GUILD_MESSAGES,
356+
Intents::GUILD_MESSAGE_POLLS | Intents::DIRECT_MESSAGE_POLLS => Self::MESSAGE_POLLS,
357+
Intents::GUILD_MESSAGE_REACTIONS => Self::GUILD_MESSAGE_REACTIONS,
358+
Intents::GUILD_MESSAGE_TYPING => Self::GUILD_MESSAGE_TYPING,
359+
Intents::GUILD_PRESENCES => Self::GUILD_PRESENCES,
360+
Intents::GUILD_SCHEDULED_EVENTS => Self::GUILD_SCHEDULED_EVENTS,
361+
Intents::GUILD_VOICE_STATES => Self::GUILD_VOICE_STATES,
362+
Intents::GUILD_WEBHOOKS => Self::GUILD_WEBHOOKS,
363+
Intents::MESSAGE_CONTENT => Self::empty(),
364+
_ => unimplemented!("Unimplemented Intent to EventTypeFlags mapping"),
365+
}
366+
}
367+
368+
event_type_flags
369+
}
370+
}
371+
338372
impl From<EventType> for EventTypeFlags {
339373
fn from(event_type: EventType) -> Self {
340374
match event_type {

0 commit comments

Comments
 (0)