-
Notifications
You must be signed in to change notification settings - Fork 586
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
Add MessageReferenceKind
enum
#2996
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0b2fa3e
Add `MessageReferenceKind` enum
MarkusTheOrt 07c4ff8
remove `From<>` impl for `MessageReference`
MarkusTheOrt 52ad32f
add `#[must_use]` to `MessageReference::new`
MarkusTheOrt 26027a6
remove deprecate marker
MarkusTheOrt feef68b
add builder for message reference
MarkusTheOrt 68bff8b
add `#[must_use]` markers
MarkusTheOrt ecd1e0f
remove breaking changes
MarkusTheOrt 29759f0
fix wrong import in `message.rs`
MarkusTheOrt f4d5e2e
fix missing feature flag for import
MarkusTheOrt 3cd878e
add clippy suggestions regarding cfg flags
MarkusTheOrt 9c27704
remove create_message_reference.rs
MarkusTheOrt 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::model::prelude::*; | ||
|
||
/// Reference data sent with crossposted messages. | ||
/// | ||
/// [Discord docs](https://discord.com/developers/docs/resources/channel#message-reference-object-message-reference-structure). | ||
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))] | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
#[non_exhaustive] | ||
pub struct CreateMessageReference { | ||
/// The type of Message Reference. | ||
#[serde(rename = "type", default = "MessageReferenceKind::default")] | ||
pub kind: MessageReferenceKind, | ||
/// The ID of the originating messages's channel. | ||
pub channel_id: ChannelId, | ||
/// The ID of the originating message. | ||
pub message_id: Option<MessageId>, | ||
/// The ID of the originating messages's guild. | ||
pub guild_id: Option<GuildId>, | ||
/// When sending, whether to error if the referenced message doesn't exist instead of sending | ||
/// as a normal(non-reply) message, default true. | ||
pub fail_if_not_exists: Option<bool>, | ||
} | ||
|
||
impl CreateMessageReference { | ||
#[must_use] | ||
pub fn new(kind: MessageReferenceKind, message_id: MessageId, channel_id: ChannelId) -> Self { | ||
Self { | ||
kind, | ||
channel_id, | ||
message_id: Some(message_id), | ||
guild_id: None, | ||
fail_if_not_exists: None, | ||
} | ||
} | ||
|
||
#[must_use] | ||
pub fn guild(mut self, guild: GuildId) -> Self { | ||
self.guild_id = Some(guild); | ||
self | ||
} | ||
|
||
#[must_use] | ||
pub fn fail_if_not_exists(mut self, fail_if_not_exists: bool) -> Self { | ||
self.fail_if_not_exists = Some(fail_if_not_exists); | ||
self | ||
} | ||
} | ||
|
||
impl From<MessageReference> for CreateMessageReference { | ||
fn from(value: MessageReference) -> Self { | ||
Self { | ||
kind: value.kind, | ||
channel_id: value.channel_id, | ||
message_id: value.message_id, | ||
guild_id: value.guild_id, | ||
fail_if_not_exists: value.fail_if_not_exists, | ||
} | ||
} | ||
} | ||
|
||
impl From<&Message> for CreateMessageReference { | ||
fn from(value: &Message) -> Self { | ||
Self { | ||
kind: MessageReferenceKind::default(), | ||
channel_id: value.channel_id, | ||
message_id: Some(value.id), | ||
guild_id: value.guild_id, | ||
fail_if_not_exists: None, | ||
} | ||
} | ||
} |
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.
Isn't this completely unused now? This shouldn't be added for
current
, you can make a separate PR after this is merged andnext
is rebased to add this builder and swapCreateMessage::reference_message
to use this.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.
I can remove this if you want, but I made an from impl to convert a CreateMessageReference into a MessageReference, so not 100% unused but I get your point.
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.
Yep, please remove it for now.