feat: add option to enable or disable pings when polling

This commit is contained in:
oSumAtrIX 2023-03-27 21:34:18 +02:00
parent 0793b1c6d1
commit 3e86a2cdb7
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -51,8 +51,9 @@ pub async fn reply(
pub async fn poll( pub async fn poll(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "The id of the poll"] id: u64, /* This is currently unused in the API, leaving as a placeholder in case it is required. */ #[description = "The id of the poll"] id: u64, /* This is currently unused in the API, leaving as a placeholder in case it is required. */
#[description = "The link to a message to clone"] message_link: String, #[description = "A link to a message to clone"] message_link: String,
#[description = "The minumum server age in days to allow members to poll"] age: u16, #[description = "The minumum server age in days to allow members to poll"] age: u16,
#[description = "Enable pings"] ping: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
let get_id = let get_id =
|segments: &mut std::str::Split<char>| segments.next_back().unwrap().parse::<u64>(); |segments: &mut std::str::Split<char>| segments.next_back().unwrap().parse::<u64>();
@ -74,21 +75,25 @@ pub async fn poll(
.await?; .await?;
ctx.send(|m| { ctx.send(|m| {
clone_message(&message, m) let mut clone = clone_message(&message, m).components(|c| {
.components(|c| { c.create_action_row(|r| {
c.create_action_row(|r| { r.create_button(|b| {
r.create_button(|b| { b.label("Vote")
b.label("Vote") .emoji(ReactionType::Unicode("🗳️".to_string()))
.emoji(ReactionType::Unicode("🗳️".to_string())) .custom_id(format!("poll:{id}:{age}"))
.custom_id(format!("poll:{id}:{age}"))
})
}) })
}) })
.allowed_mentions(|am| { });
if ping {
clone = clone.allowed_mentions(|am| {
am.parse(ParseValue::Users) am.parse(ParseValue::Users)
.parse(ParseValue::Roles) .parse(ParseValue::Roles)
.parse(ParseValue::Everyone) .parse(ParseValue::Everyone)
}) });
}
clone
}) })
.await?; .await?;