Skip to content

Commit

Permalink
Add poll support (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbt365 authored Nov 13, 2024
1 parent d416114 commit 3eefed4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 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.
pub 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,8 @@ impl CreateReply {
components,
ephemeral: _, // can't edit ephemerality in retrospect
allowed_mentions,
// cannot edit polls.
poll: _,
reply: _,
__non_exhaustive: (),
} = self;
Expand Down Expand Up @@ -188,6 +211,8 @@ impl CreateReply {
components,
ephemeral: _, // not supported in prefix
allowed_mentions,
// cannot edit polls.
poll: _,
reply: _, // can't edit reference message afterwards
__non_exhaustive: (),
} = self;
Expand Down Expand Up @@ -222,6 +247,7 @@ impl CreateReply {
components,
ephemeral: _, // not supported in prefix
allowed_mentions,
poll,
reply,
__non_exhaustive: (),
} = self;
Expand All @@ -239,6 +265,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 3eefed4

Please sign in to comment.