use twilight_model::application::interaction::{
InteractionData,
application_command::CommandData,
message_component::MessageComponentInteractionData,
modal::ModalInteractionData,
};
pub trait ExtractInteractionData {
fn command_data(self) -> Option<CommandData>;
fn component_data(self) -> Option<MessageComponentInteractionData>;
fn custom_id(&self) -> Option<&str>;
fn modal_data(self) -> Option<ModalInteractionData>;
}
impl ExtractInteractionData for InteractionData {
fn command_data(self) -> Option<CommandData> {
if let Self::ApplicationCommand(data) = self {
Some(*data)
} else {
None
}
}
fn component_data(self) -> Option<MessageComponentInteractionData> {
if let Self::MessageComponent(data) = self {
Some(*data)
} else {
None
}
}
fn custom_id(&self) -> Option<&str> {
match self {
Self::ApplicationCommand(command) => Some(&command.name),
Self::MessageComponent(component) => Some(&component.custom_id),
Self::ModalSubmit(modal) => Some(&modal.custom_id),
_ => None,
}
}
fn modal_data(self) -> Option<ModalInteractionData> {
if let Self::ModalSubmit(data) = self {
Some(data)
} else {
None
}
}
}