Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/twilight-rs/twilight into f…
Browse files Browse the repository at this point in the history
…eat/message-forwarding
  • Loading branch information
suneettipirneni committed Jul 17, 2024
2 parents ee96403 + dab3dbc commit db86119
Show file tree
Hide file tree
Showing 109 changed files with 3,291 additions and 418 deletions.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
identity and expression, level of experience, education, socioeconomic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

Expand Down
6 changes: 6 additions & 0 deletions twilight-cache-inmemory/src/event/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ mod tests {
accent_color: None,
avatar: Some(avatar3),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 1,
Expand All @@ -184,6 +185,7 @@ mod tests {
system: None,
verified: None,
},
call: None,
channel_id: Id::new(2),
components: Vec::new(),
content: "ping".to_owned(),
Expand Down Expand Up @@ -213,6 +215,7 @@ mod tests {
mentions: Vec::new(),
message_snapshots: Vec::new(),
pinned: false,
poll: None,
reactions: Vec::new(),
reference: None,
role_subscription_data: None,
Expand Down Expand Up @@ -251,6 +254,7 @@ mod tests {
accent_color: None,
avatar: Some(avatar2),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 5678,
Expand All @@ -270,6 +274,7 @@ mod tests {
}),
target_id: None,
}))),
entitlements: Vec::new(),
guild_id: Some(Id::new(3)),
guild_locale: None,
id: Id::new(4),
Expand All @@ -290,6 +295,7 @@ mod tests {
accent_color: None,
avatar: Some(avatar3),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 1234,
Expand Down
3 changes: 3 additions & 0 deletions twilight-cache-inmemory/src/event/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ mod tests {
accent_color: None,
avatar: Some(avatar),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 1,
Expand All @@ -136,6 +137,7 @@ mod tests {
system: None,
verified: None,
},
call: None,
channel_id: Id::new(2),
components: Vec::new(),
content: "ping".to_owned(),
Expand Down Expand Up @@ -165,6 +167,7 @@ mod tests {
mentions: Vec::new(),
message_snapshots: Vec::new(),
pinned: false,
poll: None,
reactions: Vec::new(),
reference: None,
role_subscription_data: None,
Expand Down
46 changes: 26 additions & 20 deletions twilight-cache-inmemory/src/event/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
CacheableModels, InMemoryCache, UpdateCache,
};
use twilight_model::{
channel::message::{Reaction, ReactionCountDetails, ReactionType},
channel::message::{EmojiReactionType, Reaction, ReactionCountDetails},
gateway::payload::incoming::{
ReactionAdd, ReactionRemove, ReactionRemoveAll, ReactionRemoveEmoji,
},
Expand Down Expand Up @@ -124,14 +124,16 @@ impl<CacheModels: CacheableModels> UpdateCache<CacheModels> for ReactionRemoveEm
}
}

fn reactions_eq(a: &ReactionType, b: &ReactionType) -> bool {
fn reactions_eq(a: &EmojiReactionType, b: &EmojiReactionType) -> bool {
match (a, b) {
(ReactionType::Custom { id: id_a, .. }, ReactionType::Custom { id: id_b, .. }) => {
id_a == id_b
}
(ReactionType::Unicode { name: name_a }, ReactionType::Unicode { name: name_b }) => {
name_a == name_b
}
(
EmojiReactionType::Custom { id: id_a, .. },
EmojiReactionType::Custom { id: id_b, .. },
) => id_a == id_b,
(
EmojiReactionType::Unicode { name: name_a },
EmojiReactionType::Unicode { name: name_b },
) => name_a == name_b,
_ => false,
}
}
Expand All @@ -141,7 +143,7 @@ mod tests {
use super::reactions_eq;
use crate::{model::CachedMessage, test};
use twilight_model::{
channel::message::{Reaction, ReactionType},
channel::message::{EmojiReactionType, Reaction},
gateway::{
payload::incoming::{ReactionRemove, ReactionRemoveAll, ReactionRemoveEmoji},
GatewayReaction,
Expand All @@ -153,7 +155,7 @@ mod tests {
msg.reactions.iter().find(|&r| {
reactions_eq(
&r.emoji,
&ReactionType::Custom {
&EmojiReactionType::Custom {
animated: false,
id: Id::new(6),
name: None,
Expand All @@ -172,11 +174,11 @@ mod tests {
let world_react = msg
.reactions
.iter()
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "🗺️"));
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "🗺️"));
let smiley_react = msg
.reactions
.iter()
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "😀"));
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "😀"));
let custom_react = find_custom_react(&msg);

assert!(world_react.is_some());
Expand All @@ -191,8 +193,10 @@ mod tests {
fn reaction_remove() {
let cache = test::cache_with_message_and_reactions();
cache.update(&ReactionRemove(GatewayReaction {
burst: false,
burst_colors: Vec::new(),
channel_id: Id::new(2),
emoji: ReactionType::Unicode {
emoji: EmojiReactionType::Unicode {
name: "😀".to_owned(),
},
guild_id: Some(Id::new(1)),
Expand All @@ -202,8 +206,10 @@ mod tests {
user_id: Id::new(5),
}));
cache.update(&ReactionRemove(GatewayReaction {
burst: false,
burst_colors: Vec::new(),
channel_id: Id::new(2),
emoji: ReactionType::Custom {
emoji: EmojiReactionType::Custom {
animated: false,
id: Id::new(6),
name: None,
Expand All @@ -222,11 +228,11 @@ mod tests {
let world_react = msg
.reactions
.iter()
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "🗺️"));
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "🗺️"));
let smiley_react = msg
.reactions
.iter()
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "😀"));
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "😀"));
let custom_react = find_custom_react(&msg);

assert!(world_react.is_some());
Expand Down Expand Up @@ -255,15 +261,15 @@ mod tests {
let cache = test::cache_with_message_and_reactions();
cache.update(&ReactionRemoveEmoji {
channel_id: Id::new(2),
emoji: ReactionType::Unicode {
emoji: EmojiReactionType::Unicode {
name: "😀".to_owned(),
},
guild_id: Id::new(1),
message_id: Id::new(4),
});
cache.update(&ReactionRemoveEmoji {
channel_id: Id::new(2),
emoji: ReactionType::Custom {
emoji: EmojiReactionType::Custom {
animated: false,
id: Id::new(6),
name: None,
Expand All @@ -279,11 +285,11 @@ mod tests {
let world_react = msg
.reactions
.iter()
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "🗺️"));
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "🗺️"));
let smiley_react = msg
.reactions
.iter()
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "😀"));
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "😀"));
let custom_react = find_custom_react(&msg);

assert!(world_react.is_some());
Expand Down
1 change: 1 addition & 0 deletions twilight-cache-inmemory/src/event/voice_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ mod tests {
accent_color: None,
avatar: Some(avatar),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 1,
Expand Down
5 changes: 5 additions & 0 deletions twilight-cache-inmemory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,9 @@ impl<CacheModels: CacheableModels> UpdateCache<CacheModels> for Event {
| Event::BanAdd(_)
| Event::BanRemove(_)
| Event::CommandPermissionsUpdate(_)
| Event::EntitlementCreate(_)
| Event::EntitlementDelete(_)
| Event::EntitlementUpdate(_)
| Event::GatewayClose(_)
| Event::GatewayHeartbeat(_)
| Event::GatewayHeartbeatAck
Expand All @@ -991,6 +994,8 @@ impl<CacheModels: CacheableModels> UpdateCache<CacheModels> for Event {
| Event::GuildScheduledEventUserRemove(_)
| Event::InviteCreate(_)
| Event::InviteDelete(_)
| Event::MessagePollVoteAdd(_)
| Event::MessagePollVoteRemove(_)
| Event::Resumed
| Event::ThreadMembersUpdate(_)
| Event::ThreadMemberUpdate(_)
Expand Down
1 change: 1 addition & 0 deletions twilight-cache-inmemory/src/model/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ mod tests {
accent_color: None,
avatar: None,
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 1,
Expand Down
10 changes: 9 additions & 1 deletion twilight-cache-inmemory/src/model/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use twilight_model::{
channel::{
message::{
sticker::MessageSticker, Component, Embed, Message, MessageActivity,
MessageApplication, MessageFlags, MessageInteraction, MessageReference,
MessageApplication, MessageCall, MessageFlags, MessageInteraction, MessageReference,
MessageSnapshot, MessageType, Reaction, RoleSubscriptionData,
},
Attachment, ChannelMention,
Expand All @@ -20,6 +20,7 @@ use twilight_model::{
},
Id,
},
poll::Poll,
util::Timestamp,
};

Expand Down Expand Up @@ -98,6 +99,7 @@ pub struct CachedMessage {
application_id: Option<Id<ApplicationMarker>>,
pub(crate) attachments: Vec<Attachment>,
author: Id<UserMarker>,
pub(crate) call: Option<MessageCall>,
channel_id: Id<ChannelMarker>,
components: Vec<Component>,
pub(crate) content: String,
Expand All @@ -115,6 +117,7 @@ pub struct CachedMessage {
pub(crate) mentions: Vec<Id<UserMarker>>,
pub(crate) message_snapshots: Vec<MessageSnapshot>,
pub(crate) pinned: bool,
pub(crate) poll: Option<Poll>,
pub(crate) reactions: Vec<Reaction>,
reference: Option<MessageReference>,
role_subscription_data: Option<RoleSubscriptionData>,
Expand Down Expand Up @@ -305,6 +308,7 @@ impl From<Message> for CachedMessage {
application_id,
attachments,
author,
call,
channel_id,
components,
content,
Expand All @@ -322,6 +326,7 @@ impl From<Message> for CachedMessage {
mentions,
message_snapshots,
pinned,
poll,
reactions,
reference,
referenced_message: _,
Expand All @@ -340,6 +345,7 @@ impl From<Message> for CachedMessage {
application_id,
attachments,
author: author.id,
call,
channel_id,
components,
content,
Expand All @@ -356,6 +362,7 @@ impl From<Message> for CachedMessage {
mentions: mentions.into_iter().map(|mention| mention.id).collect(),
message_snapshots,
pinned,
poll,
reactions,
reference,
role_subscription_data,
Expand All @@ -376,6 +383,7 @@ impl PartialEq<Message> for CachedMessage {
&& self.application_id == other.application_id
&& self.attachments == other.attachments
&& self.author == other.author.id
&& self.call == other.call
&& self.channel_id == other.channel_id
&& self.components == other.components
&& self.content == other.content
Expand Down
1 change: 1 addition & 0 deletions twilight-cache-inmemory/src/model/sticker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ mod tests {
accent_color: None,
avatar: Some(avatar),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 1,
Expand Down
Loading

0 comments on commit db86119

Please sign in to comment.