Skip to content

Commit

Permalink
cleaned up the pr so it is in a better shape
Browse files Browse the repository at this point in the history
  • Loading branch information
Erk- committed Jun 3, 2024
1 parent 4b2eeac commit e3ac893
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 41 deletions.
2 changes: 1 addition & 1 deletion twilight-cache-inmemory/src/event/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mod tests {
let cache = DefaultInMemoryCache::new();

cache.update(&InteractionCreate(Interaction {
app_permissions: Permissions::SEND_MESSAGES,
app_permissions: Some(Permissions::SEND_MESSAGES),
application_id: Id::new(1),
authorizing_integration_owners: ApplicationIntegrationMap {
guild: None,
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 @@ -102,6 +102,7 @@ mod tests {
util::{image_hash::ImageHashParseError, ImageHash, Timestamp},
};

#[allow(deprecated)]
#[test]
fn message_create() -> Result<(), ImageHashParseError> {
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
Expand Down
2 changes: 1 addition & 1 deletion twilight-cache-inmemory/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn cache() -> DefaultInMemoryCache {
DefaultInMemoryCache::new()
}

#[allow(clippy::too_many_lines)]
#[allow(clippy::too_many_lines, deprecated)]
pub fn cache_with_message_and_reactions() -> DefaultInMemoryCache {
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
let cache = DefaultInMemoryCache::new();
Expand Down
5 changes: 3 additions & 2 deletions twilight-http/src/request/application/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ mod tests {
/// `Command` or a type is changed then the destructure of it and creation
/// of `CommandBorrowed` will fail.
#[test]
#[allow(deprecated)]
fn command_borrowed_from_command() {
let command = Command {
application_id: Some(Id::new(1)),
contexts: None,
default_member_permissions: Some(Permissions::ADMINISTRATOR),
dm_permission: Some(true),
description: "command description".to_owned(),
Expand All @@ -88,6 +90,7 @@ mod tests {
)])),
guild_id: Some(Id::new(2)),
id: Some(Id::new(3)),
integration_types: None,
kind: CommandType::ChatInput,
name: "command name".to_owned(),
name_localizations: Some(HashMap::from([(
Expand All @@ -97,8 +100,6 @@ mod tests {
nsfw: Some(true),
options: Vec::new(),
version: Id::new(1),
contexts: None,
integration_types: None,
};
_ = CommandBorrowed {
application_id: command.application_id,
Expand Down
6 changes: 3 additions & 3 deletions twilight-model/src/application/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ mod tests {
use std::collections::HashMap;

#[test]
#[allow(clippy::too_many_lines)]
#[allow(clippy::too_many_lines, deprecated)]
fn command_option_full() {
let value = Command {
application_id: Some(Id::new(100)),
contexts: None,
default_member_permissions: Some(Permissions::ADMINISTRATOR),
dm_permission: Some(false),
description: "this command is a test".into(),
Expand All @@ -126,6 +127,7 @@ mod tests {
)])),
guild_id: Some(Id::new(300)),
id: Some(Id::new(200)),
integration_types: None,
kind: CommandType::ChatInput,
name: "test command".into(),
name_localizations: Some(HashMap::from([("en-US".into(), "test command".into())])),
Expand Down Expand Up @@ -320,8 +322,6 @@ mod tests {
required: None,
}]),
version: Id::new(1),
contexts: None,
integration_types: None,
};

serde_test::assert_tokens(
Expand Down
23 changes: 18 additions & 5 deletions twilight-model/src/application/interaction/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,29 @@ use crate::{

use super::InteractionType;

/// Structure containing metadata for interactions.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct InteractionMetadata {
/// IDs for installation context(s) related to an interaction.
pub authorizing_integration_owners:
ApplicationIntegrationMap<AnonymizableId<GuildMarker>, Id<UserMarker>>,
/// ID of the interaction.
pub id: Id<InteractionMarker>,
/// ID of the message that contained interactive component, present only on
/// messages created from component interactions
#[serde(skip_serializing_if = "Option::is_none")]
pub interacted_message_id: Option<Id<MessageMarker>>,
/// Type of interaction.
#[serde(rename = "type")]
pub kind: InteractionType,
pub user_id: Id<UserMarker>,
pub authorizing_integration_owners:
ApplicationIntegrationMap<AnonymizableId<GuildMarker>, Id<UserMarker>>,
/// ID of the original response message, present only on follow-up messages.
#[serde(skip_serializing_if = "Option::is_none")]
pub original_response_message_id: Option<Id<MessageMarker>>,
pub interacted_message_id: Option<Id<MessageMarker>>,
/// Metadata for the interaction that was used to open the modal,
/// present only on modal submit interactions
// This field cannot be in the nested interaction metadata.
pub triggering_interaction_metadata: Box<InteractionMetadata>,
#[serde(skip_serializing_if = "Option::is_none")]
pub triggering_interaction_metadata: Option<Box<InteractionMetadata>>,
/// ID of the user who triggered the interaction.
pub user_id: Id<UserMarker>,
}
36 changes: 17 additions & 19 deletions twilight-model/src/application/interaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ use std::fmt::{Formatter, Result as FmtResult};
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct Interaction {
/// App's permissions in the channel the interaction was sent from.
pub app_permissions: Permissions,
#[serde(skip_serializing_if = "Option::is_none")]
pub app_permissions: Option<Permissions>,
/// ID of the associated application.
pub application_id: Id<ApplicationMarker>,
/// Mapping of installation contexts that the interaction was
/// authorized for to related user or guild IDs.
pub authorizing_integration_owners:
ApplicationIntegrationMap<AnonymizableId<GuildMarker>, Id<UserMarker>>,
/// The channel the interaction was invoked in.
Expand Down Expand Up @@ -347,8 +350,6 @@ impl<'de> Visitor<'de> for InteractionVisitor {
}
}

let app_permissions =
app_permissions.ok_or_else(|| DeError::missing_field("app_permissions"))?;
let application_id =
application_id.ok_or_else(|| DeError::missing_field("application_id"))?;
let authorizing_integration_owners = authorizing_integration_owners
Expand Down Expand Up @@ -396,6 +397,7 @@ impl<'de> Visitor<'de> for InteractionVisitor {
Ok(Self::Value {
app_permissions,
application_id,
authorizing_integration_owners,
channel,
channel_id,
data,
Expand All @@ -408,7 +410,6 @@ impl<'de> Visitor<'de> for InteractionVisitor {
message,
token,
user,
authorizing_integration_owners,
})
}
}
Expand Down Expand Up @@ -460,8 +461,12 @@ mod tests {
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let value = Interaction {
app_permissions: Permissions::SEND_MESSAGES,
app_permissions: Some(Permissions::SEND_MESSAGES),
application_id: Id::new(100),
authorizing_integration_owners: ApplicationIntegrationMap {
guild: None,
user: None,
},
channel: Some(Channel {
bitrate: None,
guild_id: None,
Expand Down Expand Up @@ -594,10 +599,6 @@ mod tests {
message: None,
token: "interaction token".into(),
user: None,
authorizing_integration_owners: ApplicationIntegrationMap {
guild: None,
user: None,
},
};

// TODO: switch the `assert_tokens` see #2190
Expand All @@ -609,10 +610,17 @@ mod tests {
len: 13,
},
Token::Str("app_permissions"),
Token::Some,
Token::Str("2048"),
Token::Str("application_id"),
Token::NewtypeStruct { name: "Id" },
Token::Str("100"),
Token::Str("authorizing_integration_owners"),
Token::Struct {
name: "ApplicationIntegrationMap",
len: 0,
},
Token::StructEnd,
Token::Str("channel"),
Token::Some,
Token::Struct {
Expand Down Expand Up @@ -795,16 +803,6 @@ mod tests {
Token::StructEnd,
Token::Str("token"),
Token::Str("interaction token"),
Token::Str("authorizing_integration_owners"),
Token::Struct {
name: "ApplicationIntegrationMap",
len: 2,
},
Token::Str("guild"),
Token::None,
Token::Str("user"),
Token::None,
Token::StructEnd,
Token::StructEnd,
],
);
Expand Down
8 changes: 4 additions & 4 deletions twilight-model/src/application/interaction/resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod tests {
use std::str::FromStr;

#[test]
#[allow(clippy::too_many_lines)]
#[allow(clippy::too_many_lines, deprecated)]
fn test_data_resolved() -> Result<(), TimestampParseError> {
let joined_at = Some(Timestamp::from_str("2021-08-10T12:18:37.000000+00:00")?);
let timestamp = Timestamp::from_str("2020-02-02T02:02:02.020000+00:00")?;
Expand Down Expand Up @@ -204,6 +204,7 @@ mod tests {
guild_id: Some(Id::new(1)),
id: Id::new(4),
interaction: None,
interaction_metadata: None,
kind: MessageType::Regular,
member: Some(PartialMember {
avatar: None,
Expand All @@ -225,18 +226,17 @@ mod tests {
pinned: false,
reactions: Vec::new(),
reference: None,
referenced_message: None,
role_subscription_data: None,
sticker_items: vec![MessageSticker {
format_type: StickerFormatType::Png,
id: Id::new(1),
name: "sticker name".to_owned(),
}],
referenced_message: None,
thread: None,
timestamp,
thread: None,
tts: false,
webhook_id: None,
interaction_metadata: None,
},
)])
.collect(),
Expand Down
9 changes: 6 additions & 3 deletions twilight-model/src/channel/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub use self::{

use self::sticker::MessageSticker;
use crate::{
application::interaction::InteractionMetadata,
channel::{Attachment, Channel, ChannelMention},
guild::PartialMember,
id::{
Expand All @@ -43,7 +44,7 @@ use crate::{
Id,
},
user::User,
util::Timestamp, application::interaction::InteractionMetadata,
util::Timestamp,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -136,6 +137,8 @@ pub struct Message {
#[deprecated(note = "use interaction_metadata instead")]
#[serde(skip_serializing_if = "Option::is_none")]
pub interaction: Option<MessageInteraction>,
/// Contains metadata related to the interacting if the message is
/// sent as a result of an interaction.
#[serde(skip_serializing_if = "Option::is_none")]
pub interaction_metadata: Option<Box<InteractionMetadata>>,
/// Type of message.
Expand Down Expand Up @@ -215,7 +218,7 @@ mod tests {
use serde_test::Token;
use std::str::FromStr;

#[allow(clippy::too_many_lines)]
#[allow(clippy::too_many_lines, deprecated)]
#[test]
fn message_deserialization() {
let joined_at = Some(Timestamp::from_str("2020-01-01T00:00:00.000000+00:00").unwrap());
Expand Down Expand Up @@ -409,7 +412,7 @@ mod tests {
);
}

#[allow(clippy::too_many_lines)]
#[allow(clippy::too_many_lines, deprecated)]
#[test]
fn message_deserialization_complete() -> Result<(), TimestampParseError> {
let edited_timestamp = Timestamp::from_str("2021-08-10T12:41:51.602000+00:00")?;
Expand Down
5 changes: 3 additions & 2 deletions twilight-standby/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,13 +1075,14 @@ mod tests {
},
guild::Permissions,
id::{marker::GuildMarker, Id},
oauth::{ApplicationFlags, PartialApplication, ApplicationIntegrationMap},
oauth::{ApplicationFlags, ApplicationIntegrationMap, PartialApplication},
user::{CurrentUser, User},
util::Timestamp,
};

assert_impl_all!(Standby: Debug, Default, Send, Sync);

#[allow(deprecated)]
fn message() -> Message {
Message {
activity: None,
Expand Down Expand Up @@ -1153,7 +1154,7 @@ mod tests {
#[allow(deprecated)]
fn button() -> Interaction {
Interaction {
app_permissions: Permissions::SEND_MESSAGES,
app_permissions: Some(Permissions::SEND_MESSAGES),
application_id: Id::new(1),
authorizing_integration_owners: ApplicationIntegrationMap {
guild: None,
Expand Down
2 changes: 1 addition & 1 deletion twilight-util/src/builder/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ mod tests {
assert_impl_all!(UserBuilder: Clone, Debug, Send, Sync);

#[test]
#[allow(clippy::too_many_lines)]
#[allow(clippy::too_many_lines, deprecated)]
fn construct_command_with_builder() {
let command =
CommandBuilder::new(
Expand Down
2 changes: 2 additions & 0 deletions twilight-validate/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ mod tests {

// This tests [`description`] and [`name`] by proxy.
#[test]
#[allow(deprecated)]
fn command_length() {
let valid_command = Command {
application_id: Some(Id::new(1)),
Expand Down Expand Up @@ -910,6 +911,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn command_combined_limit() {
let mut command = Command {
application_id: Some(Id::new(1)),
Expand Down

0 comments on commit e3ac893

Please sign in to comment.