-
-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(model, validate, cache)!: Add new select components #2051
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,10 @@ | |
//! | ||
//! [`MessageComponent`]: crate::application::interaction::InteractionType::MessageComponent | ||
|
||
use crate::channel::message::component::ComponentType; | ||
use crate::{ | ||
application::interaction::resolved::InteractionDataResolved, | ||
channel::message::component::ComponentType, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Data received when an [`MessageComponent`] interaction is executed. | ||
|
@@ -11,7 +14,15 @@ use serde::{Deserialize, Serialize}; | |
/// | ||
/// [`MessageComponent`]: crate::application::interaction::InteractionType::MessageComponent | ||
/// [Discord Docs/Message Component Data Structure]: https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-message-component-data-structure | ||
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] | ||
#[derive( | ||
Clone, | ||
Debug, | ||
Deserialize, | ||
Eq, | ||
// Hash, | ||
PartialEq, | ||
Serialize, | ||
)] | ||
pub struct MessageComponentInteractionData { | ||
/// User defined identifier for the component. | ||
/// | ||
|
@@ -23,33 +34,41 @@ pub struct MessageComponentInteractionData { | |
pub component_type: ComponentType, | ||
/// Values selected by the user. | ||
/// | ||
/// Only used for [`SelectMenu`] components. | ||
/// | ||
/// [`SelectMenu`]: ComponentType::SelectMenu | ||
/// Only used for Select Menu components. | ||
#[serde(default)] | ||
pub values: Vec<String>, | ||
/// Resolved data from the interaction's select menu. | ||
/// | ||
/// Only used for Select Menu components. | ||
pub resolved: Option<InteractionDataResolved>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::MessageComponentInteractionData; | ||
use crate::channel::message::component::ComponentType; | ||
use crate::{ | ||
application::interaction::resolved::InteractionDataResolved, | ||
channel::message::component::ComponentType, | ||
guild::{Permissions, Role}, | ||
id::Id, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_test::Token; | ||
use static_assertions::{assert_fields, assert_impl_all}; | ||
use std::{fmt::Debug, hash::Hash}; | ||
use std::{collections::HashMap, fmt::Debug}; | ||
|
||
assert_fields!( | ||
MessageComponentInteractionData: custom_id, | ||
component_type, | ||
values | ||
values, | ||
resolved | ||
); | ||
assert_impl_all!( | ||
MessageComponentInteractionData: Clone, | ||
Debug, | ||
Deserialize<'static>, | ||
Eq, | ||
Hash, | ||
// Hash, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just leaving a pr comment on this (todo?) for visibility |
||
PartialEq, | ||
Send, | ||
Serialize, | ||
|
@@ -62,14 +81,38 @@ mod tests { | |
custom_id: "test".to_owned(), | ||
component_type: ComponentType::Button, | ||
values: Vec::from(["1".to_owned(), "2".to_owned()]), | ||
resolved: Some(InteractionDataResolved { | ||
attachments: HashMap::new(), | ||
channels: HashMap::new(), | ||
members: HashMap::new(), | ||
messages: HashMap::new(), | ||
roles: IntoIterator::into_iter([( | ||
Id::new(400), | ||
Role { | ||
color: 0, | ||
hoist: true, | ||
icon: None, | ||
id: Id::new(400), | ||
managed: false, | ||
mentionable: true, | ||
name: "test".to_owned(), | ||
permissions: Permissions::ADMINISTRATOR, | ||
position: 12, | ||
tags: None, | ||
unicode_emoji: None, | ||
}, | ||
)]) | ||
.collect(), | ||
users: HashMap::new(), | ||
}), | ||
}; | ||
|
||
serde_test::assert_tokens( | ||
&value, | ||
&[ | ||
Token::Struct { | ||
name: "MessageComponentInteractionData", | ||
len: 3, | ||
len: 4, | ||
}, | ||
Token::String("custom_id"), | ||
Token::String("test"), | ||
|
@@ -80,6 +123,40 @@ mod tests { | |
Token::String("1"), | ||
Token::String("2"), | ||
Token::SeqEnd, | ||
Token::String("resolved"), | ||
Token::Some, | ||
Token::Struct { | ||
name: "InteractionDataResolved", | ||
len: 1, | ||
}, | ||
Token::Str("roles"), | ||
Token::Map { len: Some(1) }, | ||
Token::NewtypeStruct { name: "Id" }, | ||
Token::Str("400"), | ||
Token::Struct { | ||
name: "Role", | ||
len: 8, | ||
}, | ||
Token::Str("color"), | ||
Token::U32(0), | ||
Token::Str("hoist"), | ||
Token::Bool(true), | ||
Token::Str("id"), | ||
Token::NewtypeStruct { name: "Id" }, | ||
Token::Str("400"), | ||
Token::Str("managed"), | ||
Token::Bool(false), | ||
Token::Str("mentionable"), | ||
Token::Bool(true), | ||
Token::Str("name"), | ||
Token::Str("test"), | ||
Token::Str("permissions"), | ||
Token::Str("8"), | ||
Token::Str("position"), | ||
Token::I64(12), | ||
Token::StructEnd, | ||
Token::MapEnd, | ||
Token::StructEnd, | ||
Token::StructEnd, | ||
], | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just leaving a pr comment on this (todo?) for visibility