use crate::serenity_prelude as serenity;
#[derive(Default, Clone)]
pub struct CreateReply {
pub content: Option<String>,
pub embeds: Vec<serenity::CreateEmbed>,
pub attachments: Vec<serenity::CreateAttachment>,
pub ephemeral: Option<bool>,
pub components: Option<Vec<serenity::CreateActionRow>>,
pub allowed_mentions: Option<serenity::CreateAllowedMentions>,
pub poll: Option<serenity::CreatePoll<serenity::builder::create_poll::Ready>>,
pub reply: bool,
#[doc(hidden)]
pub __non_exhaustive: (),
}
impl CreateReply {
pub fn content(mut self, content: impl Into<String>) -> Self {
self.content = Some(content.into());
self
}
pub fn embed(mut self, embed: serenity::CreateEmbed) -> Self {
self.embeds.push(embed);
self
}
pub fn components(mut self, components: Vec<serenity::CreateActionRow>) -> Self {
self.components = Some(components);
self
}
pub fn attachment(mut self, attachment: serenity::CreateAttachment) -> Self {
self.attachments.push(attachment);
self
}
pub fn ephemeral(mut self, ephemeral: bool) -> Self {
self.ephemeral = Some(ephemeral);
self
}
pub fn allowed_mentions(mut self, allowed_mentions: serenity::CreateAllowedMentions) -> Self {
self.allowed_mentions = Some(allowed_mentions);
self
}
pub fn poll(
mut self,
poll: serenity::CreatePoll<serenity::builder::create_poll::Ready>,
) -> Self {
self.poll = Some(poll);
self
}
pub fn reply(mut self, reply: bool) -> Self {
self.reply = reply;
self
}
}
impl CreateReply {
pub fn to_slash_initial_response(
self,
mut builder: serenity::CreateInteractionResponseMessage,
) -> serenity::CreateInteractionResponseMessage {
let crate::CreateReply {
content,
embeds,
attachments,
components,
ephemeral,
allowed_mentions,
poll,
reply: _, __non_exhaustive: (),
} = self;
if let Some(content) = content {
builder = builder.content(content);
}
if let Some(allowed_mentions) = allowed_mentions {
builder = builder.allowed_mentions(allowed_mentions);
}
if let Some(components) = components {
builder = builder.components(components);
}
if let Some(ephemeral) = ephemeral {
builder = builder.ephemeral(ephemeral);
}
if let Some(poll) = poll {
builder = builder.poll(poll);
}
builder.add_files(attachments).embeds(embeds)
}
pub fn to_slash_followup_response(
self,
mut builder: serenity::CreateInteractionResponseFollowup,
) -> serenity::CreateInteractionResponseFollowup {
let crate::CreateReply {
content,
embeds,
attachments,
components,
ephemeral,
allowed_mentions,
poll,
reply: _,
__non_exhaustive: (),
} = self;
if let Some(content) = content {
builder = builder.content(content);
}
builder = builder.embeds(embeds);
if let Some(components) = components {
builder = builder.components(components)
}
if let Some(allowed_mentions) = allowed_mentions {
builder = builder.allowed_mentions(allowed_mentions);
}
if let Some(ephemeral) = ephemeral {
builder = builder.ephemeral(ephemeral);
}
if let Some(poll) = poll {
builder = builder.poll(poll);
}
builder.add_files(attachments)
}
pub fn to_slash_initial_response_edit(
self,
mut builder: serenity::EditInteractionResponse,
) -> serenity::EditInteractionResponse {
let crate::CreateReply {
content,
embeds,
attachments,
components,
ephemeral: _, allowed_mentions,
poll: _,
reply: _,
__non_exhaustive: (),
} = self;
if let Some(content) = content {
builder = builder.content(content);
}
if let Some(components) = components {
builder = builder.components(components);
}
if let Some(allowed_mentions) = allowed_mentions {
builder = builder.allowed_mentions(allowed_mentions);
}
for attachment in attachments {
builder = builder.new_attachment(attachment);
}
builder.embeds(embeds)
}
pub fn to_prefix_edit(self, mut builder: serenity::EditMessage) -> serenity::EditMessage {
let crate::CreateReply {
content,
embeds,
attachments,
components,
ephemeral: _, allowed_mentions,
poll: _,
reply: _, __non_exhaustive: (),
} = self;
let mut attachments_builder = serenity::EditAttachments::new();
for attachment in attachments {
attachments_builder = attachments_builder.add(attachment);
}
if let Some(content) = content {
builder = builder.content(content);
}
if let Some(allowed_mentions) = allowed_mentions {
builder = builder.allowed_mentions(allowed_mentions);
}
if let Some(components) = components {
builder = builder.components(components);
}
builder.embeds(embeds).attachments(attachments_builder)
}
pub fn to_prefix(
self,
invocation_message: serenity::MessageReference,
) -> serenity::CreateMessage {
let crate::CreateReply {
content,
embeds,
attachments,
components,
ephemeral: _, allowed_mentions,
poll,
reply,
__non_exhaustive: (),
} = self;
let mut builder = serenity::CreateMessage::new();
if let Some(content) = content {
builder = builder.content(content);
}
if let Some(allowed_mentions) = allowed_mentions {
builder = builder.allowed_mentions(allowed_mentions);
}
if let Some(components) = components {
builder = builder.components(components);
}
if reply {
builder = builder.reference_message(invocation_message);
}
if let Some(poll) = poll {
builder = builder.poll(poll);
}
for attachment in attachments {
builder = builder.add_file(attachment);
}
builder.embeds(embeds)
}
}