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 96cff2c commit da092f4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/reply/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct CreateReply {
pub(crate) ephemeral: Option<bool>,
components: Option<Vec<serenity::CreateActionRow>>,
pub(crate) allowed_mentions: Option<serenity::CreateAllowedMentions>,
poll: Option<serenity::CreatePoll<serenity::builder::create_poll::Ready>>,
reply: bool,
}

Expand Down Expand Up @@ -67,6 +68,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 @@ -93,6 +105,7 @@ impl CreateReply {
components,
ephemeral,
allowed_mentions,
poll,
reply: _, // can't reply to a message in interactions
} = self;

Expand All @@ -108,6 +121,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 @@ -124,6 +140,7 @@ impl CreateReply {
components,
ephemeral,
allowed_mentions,
poll,
reply: _,
} = self;

Expand All @@ -140,6 +157,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 @@ -156,6 +176,7 @@ impl CreateReply {
components,
ephemeral: _, // can't edit ephemerality in retrospect
allowed_mentions,
poll,
reply: _,
} = self;

Expand All @@ -168,6 +189,9 @@ impl CreateReply {
if let Some(allowed_mentions) = allowed_mentions {
builder = builder.allowed_mentions(allowed_mentions);
}
if let Some(poll) = poll {
builder = builder.poll(poll);
}

builder.embeds(embeds)
}
Expand All @@ -181,6 +205,7 @@ impl CreateReply {
components,
ephemeral: _, // not supported in prefix
allowed_mentions,
poll,
reply: _, // can't edit reference message afterwards
} = self;

Expand All @@ -198,6 +223,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 @@ -214,6 +242,7 @@ impl CreateReply {
components,
ephemeral: _, // not supported in prefix
allowed_mentions,
poll,
reply,
} = self;

Expand All @@ -230,6 +259,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 da092f4

Please sign in to comment.