Skip to content
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

Apply changes to interaction response types and add a new interaction type #1252

Merged
merged 3 commits into from
Mar 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update slash commands to the latest revision
arqunis committed Mar 6, 2021

Unverified

This user has not yet uploaded their public signing key.
commit d8ec6152da0427ba9e39f5094355ed78483c7be5
2 changes: 1 addition & 1 deletion src/builder/create_interaction_response.rs
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ impl CreateInteractionResponse {
impl<'a> Default for CreateInteractionResponse {
fn default() -> CreateInteractionResponse {
let mut map = HashMap::new();
map.insert("type", Value::Number(serde_json::Number::from(2)));
map.insert("type", Value::Number(serde_json::Number::from(4)));

CreateInteractionResponse(map)
}
8 changes: 8 additions & 0 deletions src/model/channel/message.rs
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@ use crate::client::bridge::gateway::ShardMessenger;
use crate::collector::{CollectReaction, ReactionCollectorBuilder};
#[cfg(feature = "model")]
use crate::http::{CacheHttp, Http};
#[cfg(feature = "unstable_discord_api")]
use crate::model::interactions::MessageInteraction;
use crate::model::prelude::*;
#[cfg(feature = "model")]
use crate::model::utils::U64Visitor;
@@ -104,6 +106,12 @@ pub struct Message {
pub stickers: Vec<Sticker>,
/// The message that was replied to using this message.
pub referenced_message: Option<Box<Message>>, // Boxed to avoid recusion
/// Sent if the message is a response to an [`Interaction`].
///
/// [`Interaction`]: crate::model::interactions::Interaction
#[cfg(feature = "unstable_discord_api")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable_discord_api")))]
pub interaction: Option<MessageInteraction>,
}

#[cfg(feature = "model")]
16 changes: 13 additions & 3 deletions src/model/interactions.rs
Original file line number Diff line number Diff line change
@@ -212,10 +212,8 @@ pub struct ApplicationCommandOptionChoice {
#[repr(u8)]
pub enum InteractionResponseType {
Pong = 1,
Acknowledge = 2,
ChannelMessage = 3,
ChannelMessageWithSource = 4,
AcknowledgeWithSource = 5,
DeferredChannelMessageWithSource = 5,
}

#[derive(Clone, Serialize)]
@@ -231,6 +229,18 @@ __impl_bitflags! {
}
}

/// Sent when a [`Message`] is a response to an [`Interaction`].
///
/// [`Message`]: crate::model::channel::Message
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MessageInteraction {
pub id: InteractionId,
#[serde(rename = "type")]
pub kind: InteractionType,
pub name: String,
pub user: User,
}

impl Interaction {
/// Creates a global [`ApplicationCommand`],
/// overriding an existing one with the same name if it exists.