Skip to content

Commit

Permalink
Add support for allowed_mentions in EditMessage (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
arqunis committed Feb 4, 2022
1 parent 48ca506 commit 86dbaee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/builder/create_allowed_mentions.rs
Expand Up @@ -16,7 +16,8 @@ pub enum ParseValue {
}

/// A builder to manage the allowed mentions on a message,
/// used by the [`ChannelId::send_message`] method.
/// used by the [`ChannelId::send_message`] and
/// [`ChannelId::edit_message`] methods.
///
/// # Examples
///
Expand Down Expand Up @@ -60,6 +61,7 @@ pub enum ParseValue {
/// ```
///
/// [`ChannelId::send_message`]: crate::model::id::ChannelId::send_message
/// [`ChannelId::edit_message`]: crate::model::id::ChannelId::edit_message
#[derive(Clone, Debug)]
pub struct CreateAllowedMentions(pub HashMap<&'static str, Value>);

Expand Down
16 changes: 15 additions & 1 deletion src/builder/edit_message.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use super::CreateEmbed;
use super::{CreateAllowedMentions, CreateEmbed};
#[cfg(feature = "unstable_discord_api")]
use crate::builder::CreateComponents;
use crate::internal::prelude::*;
Expand Down Expand Up @@ -131,6 +131,20 @@ impl EditMessage {
self
}

/// Set the allowed mentions for the message.
pub fn allowed_mentions<F>(&mut self, f: F) -> &mut Self
where
F: FnOnce(&mut CreateAllowedMentions) -> &mut CreateAllowedMentions,
{
let mut allowed_mentions = CreateAllowedMentions::default();
f(&mut allowed_mentions);
let map = utils::hashmap_to_json_map(allowed_mentions.0);
let allowed_mentions = Value::Object(map);

self.0.insert("allowed_mentions", allowed_mentions);
self
}

/// Sets the components of this message.
#[cfg(feature = "unstable_discord_api")]
pub fn components<F>(&mut self, f: F) -> &mut Self
Expand Down

0 comments on commit 86dbaee

Please sign in to comment.