|
1 | 1 | //! Optimization for skipping deserialization of unwanted events. |
2 | 2 |
|
3 | 3 | use bitflags::bitflags; |
4 | | -use twilight_model::gateway::{OpCode, event::EventType}; |
| 4 | +use twilight_model::gateway::{Intents, OpCode, event::EventType}; |
5 | 5 |
|
6 | 6 | bitflags! { |
7 | 7 | /// Important optimization for narrowing requested event types. |
@@ -335,6 +335,40 @@ bitflags! { |
335 | 335 | } |
336 | 336 | } |
337 | 337 |
|
| 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 | + |
338 | 372 | impl From<EventType> for EventTypeFlags { |
339 | 373 | fn from(event_type: EventType) -> Self { |
340 | 374 | match event_type { |
|
0 commit comments