Skip to content

Commit

Permalink
Add poll support
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbt365 committed Nov 3, 2024
1 parent 1184e33 commit ac52825
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/reply/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct CreateReply {
pub components: Option<Vec<serenity::CreateActionRow>>,
/// The allowed mentions for the message.
pub allowed_mentions: Option<serenity::CreateAllowedMentions>,
/// Message poll, if present.
poll: Option<serenity::CreatePoll<serenity::builder::create_poll::Ready>>,
/// Whether this message is an inline reply.
pub reply: bool,
#[doc(hidden)]
Expand Down Expand Up @@ -68,6 +70,17 @@ impl CreateReply {
self
}

/// Adds a poll to the message. Only one poll can be added per message.
///
/// See [`serenity::CreatePoll`] for more information on creating and configuring a poll.
pub fn poll(
mut self,
poll: serenity::CreatePoll<serenity::builder::create_poll::Ready>,
) -> Self {
self.poll = Some(poll);
self
}

/// Makes this message an inline reply to another message like [`serenity::Message::reply`]
/// (prefix-only, because slash commands are always inline replies anyways).
///
Expand All @@ -94,6 +107,7 @@ impl CreateReply {
components,
ephemeral,
allowed_mentions,
poll,
reply: _, // can't reply to a message in interactions
__non_exhaustive: (),
} = self;
Expand All @@ -110,6 +124,9 @@ impl CreateReply {
if let Some(ephemeral) = ephemeral {
builder = builder.ephemeral(ephemeral);
}
if let Some(poll) = poll {
builder = builder.poll(poll);
}

builder.add_files(attachments).embeds(embeds)
}
Expand All @@ -126,6 +143,7 @@ impl CreateReply {
components,
ephemeral,
allowed_mentions,
poll,
reply: _,
__non_exhaustive: (),
} = self;
Expand All @@ -143,6 +161,9 @@ impl CreateReply {
if let Some(ephemeral) = ephemeral {
builder = builder.ephemeral(ephemeral);
}
if let Some(poll) = poll {
builder = builder.poll(poll);
}

builder.add_files(attachments)
}
Expand All @@ -159,6 +180,7 @@ impl CreateReply {
components,
ephemeral: _, // can't edit ephemerality in retrospect
allowed_mentions,
poll,
reply: _,
__non_exhaustive: (),
} = self;
Expand All @@ -175,6 +197,9 @@ impl CreateReply {
for attachment in attachments {
builder = builder.new_attachment(attachment);
}
if let Some(poll) = poll {
builder = builder.poll(poll);
}

builder.embeds(embeds)
}
Expand All @@ -188,6 +213,7 @@ impl CreateReply {
components,
ephemeral: _, // not supported in prefix
allowed_mentions,
poll,
reply: _, // can't edit reference message afterwards
__non_exhaustive: (),
} = self;
Expand All @@ -206,6 +232,9 @@ impl CreateReply {
if let Some(components) = components {
builder = builder.components(components);
}
if let Some(poll) = poll {
builder = builder.poll(poll);
}

builder.embeds(embeds).attachments(attachments_builder)
}
Expand All @@ -222,6 +251,7 @@ impl CreateReply {
components,
ephemeral: _, // not supported in prefix
allowed_mentions,
poll,
reply,
__non_exhaustive: (),
} = self;
Expand All @@ -239,6 +269,9 @@ impl CreateReply {
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);
Expand Down

0 comments on commit ac52825

Please sign in to comment.