Skip to content

Commit

Permalink
Merge branch 'main' into feat/polls
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Jul 13, 2024
2 parents dd9d244 + c9e8013 commit 572d64b
Show file tree
Hide file tree
Showing 63 changed files with 552 additions and 145 deletions.
3 changes: 3 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 Down Expand Up @@ -251,6 +252,7 @@ mod tests {
accent_color: None,
avatar: Some(avatar2),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 5678,
Expand Down Expand Up @@ -291,6 +293,7 @@ mod tests {
accent_color: None,
avatar: Some(avatar3),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 1234,
Expand Down
1 change: 1 addition & 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 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
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
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
14 changes: 10 additions & 4 deletions twilight-cache-inmemory/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use twilight_model::{
channel::{
message::{
sticker::{Sticker, StickerFormatType, StickerType},
Message, MessageFlags, MessageType, ReactionType,
EmojiReactionType, Message, MessageFlags, MessageType,
},
Channel, ChannelType,
},
Expand Down Expand Up @@ -45,6 +45,7 @@ pub fn cache_with_message_and_reactions() -> DefaultInMemoryCache {
accent_color: None,
avatar: Some(avatar),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 1,
Expand Down Expand Up @@ -103,8 +104,10 @@ pub fn cache_with_message_and_reactions() -> DefaultInMemoryCache {
cache.update(&MessageCreate(msg));

let mut reaction = ReactionAdd(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 @@ -123,6 +126,7 @@ pub fn cache_with_message_and_reactions() -> DefaultInMemoryCache {
accent_color: None,
avatar: Some(avatar),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 1,
Expand Down Expand Up @@ -164,6 +168,7 @@ pub fn cache_with_message_and_reactions() -> DefaultInMemoryCache {
accent_color: None,
avatar: Some(user_5_avatar),
avatar_decoration: None,
avatar_decoration_data: None,
banner: None,
bot: false,
discriminator: 2,
Expand All @@ -184,13 +189,13 @@ pub fn cache_with_message_and_reactions() -> DefaultInMemoryCache {

cache.update(&reaction);

reaction.emoji = ReactionType::Unicode {
reaction.emoji = EmojiReactionType::Unicode {
name: "🗺️".to_owned(),
};

cache.update(&reaction);

reaction.emoji = ReactionType::Custom {
reaction.emoji = EmojiReactionType::Custom {
animated: true,
id: Id::new(6),
name: Some("custom".to_owned()),
Expand Down Expand Up @@ -359,6 +364,7 @@ pub fn user(id: Id<UserMarker>) -> User {
accent_color: None,
avatar: None,
avatar_decoration: None,
avatar_decoration_data: None,
banner: Some(banner),
bot: false,
discriminator: 1,
Expand Down
2 changes: 1 addition & 1 deletion twilight-http-ratelimiting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tokio = { version = "1", default-features = false, features = ["rt", "sync", "ti
tracing = { default-features = false, features = ["std", "attributes"], version = "0.1.23" }

[dev-dependencies]
criterion = { default-features = false, version = "0.4" }
criterion = { default-features = false, version = "0.5" }
http = { version = "1", default-features = false }
static_assertions = { default-features = false, version = "1.1.0" }
tokio = { default-features = false, features = ["macros", "rt-multi-thread"], version = "1.0" }
Expand Down
8 changes: 4 additions & 4 deletions twilight-http-ratelimiting/src/in_memory/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ impl Bucket {
/// Create a new bucket for the specified [`Path`].
pub fn new(path: Path) -> Self {
Self {
limit: AtomicU64::new(u64::max_value()),
limit: AtomicU64::new(u64::MAX),
path,
queue: BucketQueue::default(),
remaining: AtomicU64::new(u64::max_value()),
reset_after: AtomicU64::new(u64::max_value()),
remaining: AtomicU64::new(u64::MAX),
reset_after: AtomicU64::new(u64::MAX),
started_at: Mutex::new(None),
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Bucket {
}

if let Some((limit, remaining, reset_after)) = ratelimits {
if bucket_limit != limit && bucket_limit == u64::max_value() {
if bucket_limit != limit && bucket_limit == u64::MAX {
self.reset_after.store(reset_after, Ordering::SeqCst);
self.limit.store(limit, Ordering::SeqCst);
}
Expand Down
8 changes: 7 additions & 1 deletion twilight-http-ratelimiting/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl FromStr for Path {
let parts = s.split('/').skip(skip).collect::<Vec<&str>>();

Ok(match parts[..] {
["applications", "me"] => ApplicationsMe,
["applications", "@me"] => ApplicationsMe,
["applications", id, "commands"] => ApplicationCommand(parse_id(id)?),
["applications", id, "commands", _] => ApplicationCommandId(parse_id(id)?),
["applications", id, "entitlements"] => ApplicationIdEntitlements(parse_id(id)?),
Expand Down Expand Up @@ -401,6 +401,12 @@ impl FromStr for Path {
["guilds", "templates", code] => GuildsTemplatesCode(code.to_string()),
["guilds", id] => GuildsId(parse_id(id)?),
["guilds", id, "audit-logs"] => GuildsIdAuditLogs(parse_id(id)?),
["guilds", id, "auto-moderation", "rules"] => {
GuildsIdAutoModerationRules(parse_id(id)?)
}
["guilds", id, "auto-moderation", "rules", _] => {
GuildsIdAutoModerationRulesId(parse_id(id)?)
}
["guilds", id, "bans"] => GuildsIdBans(parse_id(id)?),
["guilds", id, "bans", _] => GuildsIdBansUserId(parse_id(id)?),
["guilds", id, "channels"] => GuildsIdChannels(parse_id(id)?),
Expand Down
7 changes: 5 additions & 2 deletions twilight-http/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ use tokio::time;
use twilight_http_ratelimiting::Ratelimiter;
use twilight_model::{
channel::{message::AllowedMentions, ChannelType},
guild::{auto_moderation::AutoModerationEventType, scheduled_event::PrivacyLevel, MfaLevel},
guild::{
auto_moderation::AutoModerationEventType, scheduled_event::PrivacyLevel, MfaLevel,
RolePosition,
},
http::{channel_position::Position, permission_overwrite::PermissionOverwrite},
id::{
marker::{
Expand Down Expand Up @@ -1709,7 +1712,7 @@ impl Client {
pub const fn update_role_positions<'a>(
&'a self,
guild_id: Id<GuildMarker>,
roles: &'a [(Id<RoleMarker>, u64)],
roles: &'a [RolePosition],
) -> UpdateRolePositions<'a> {
UpdateRolePositions::new(self, guild_id, roles)
}
Expand Down
6 changes: 4 additions & 2 deletions twilight-http/src/request/audit_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod private {
emoji::{CreateEmoji, DeleteEmoji, UpdateEmoji},
integration::DeleteGuildIntegration,
member::{AddRoleToMember, RemoveMember, RemoveRoleFromMember, UpdateGuildMember},
role::{CreateRole, DeleteRole, UpdateRole},
role::{CreateRole, DeleteRole, UpdateRole, UpdateRolePositions},
sticker::{CreateGuildSticker, UpdateGuildSticker},
update_guild_onboarding::UpdateGuildOnboarding,
CreateGuildChannel, CreateGuildPrune, UpdateCurrentMember, UpdateGuild, UpdateGuildMfa,
Expand Down Expand Up @@ -95,6 +95,7 @@ mod private {
impl Sealed for UpdateGuildSticker<'_> {}
impl Sealed for UpdateGuildWidgetSettings<'_> {}
impl Sealed for UpdateRole<'_> {}
impl Sealed for UpdateRolePositions<'_> {}
impl Sealed for UpdateThread<'_> {}
impl Sealed for UpdateWebhook<'_> {}
}
Expand All @@ -115,7 +116,7 @@ mod tests {
emoji::{CreateEmoji, DeleteEmoji, UpdateEmoji},
integration::DeleteGuildIntegration,
member::{AddRoleToMember, RemoveMember, RemoveRoleFromMember, UpdateGuildMember},
role::{CreateRole, DeleteRole, UpdateRole},
role::{CreateRole, DeleteRole, UpdateRole, UpdateRolePositions},
sticker::{CreateGuildSticker, UpdateGuildSticker},
CreateGuildChannel, CreateGuildPrune, UpdateCurrentMember, UpdateGuild,
},
Expand Down Expand Up @@ -157,5 +158,6 @@ mod tests {
assert_impl_all!(UpdateGuildMember<'_>: AuditLogReason<'static>);
assert_impl_all!(UpdateGuildSticker<'_>: AuditLogReason<'static>);
assert_impl_all!(UpdateRole<'_>: AuditLogReason<'static>);
assert_impl_all!(UpdateRolePositions<'_>: AuditLogReason<'static>);
assert_impl_all!(UpdateWebhook<'_>: AuditLogReason<'static>);
}
Loading

0 comments on commit 572d64b

Please sign in to comment.