From da092f48b05de9a6741c99de42a5dc79f6a2db9a Mon Sep 17 00:00:00 2001 From: jamesbt365 Date: Sun, 3 Nov 2024 14:59:32 +0000 Subject: [PATCH] Add poll support --- src/reply/builder.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/reply/builder.rs b/src/reply/builder.rs index 8610c3f2cd2d..bb86ba60996a 100644 --- a/src/reply/builder.rs +++ b/src/reply/builder.rs @@ -12,6 +12,7 @@ pub struct CreateReply { pub(crate) ephemeral: Option, components: Option>, pub(crate) allowed_mentions: Option, + poll: Option>, reply: bool, } @@ -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, + ) -> 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). /// @@ -93,6 +105,7 @@ impl CreateReply { components, ephemeral, allowed_mentions, + poll, reply: _, // can't reply to a message in interactions } = self; @@ -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) } @@ -124,6 +140,7 @@ impl CreateReply { components, ephemeral, allowed_mentions, + poll, reply: _, } = self; @@ -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) } @@ -156,6 +176,7 @@ impl CreateReply { components, ephemeral: _, // can't edit ephemerality in retrospect allowed_mentions, + poll, reply: _, } = self; @@ -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) } @@ -181,6 +205,7 @@ impl CreateReply { components, ephemeral: _, // not supported in prefix allowed_mentions, + poll, reply: _, // can't edit reference message afterwards } = self; @@ -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) } @@ -214,6 +242,7 @@ impl CreateReply { components, ephemeral: _, // not supported in prefix allowed_mentions, + poll, reply, } = self; @@ -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);