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

Add poll support #324

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Changes from all commits
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
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
Loading