pub fn content_safe(
cache: impl AsRef<Cache>,
s: impl AsRef<str>,
options: &ContentSafeOptions,
users: &[User],
) -> String
Expand description
Transforms role, channel, user, @everyone
and @here
mentions into raw text by using the
Cache
and the users passed in with users
.
ContentSafeOptions
decides what kind of mentions should be filtered and how the raw-text
will be displayed.
ยงExamples
Sanitise an @everyone
mention.
use serenity::utils::{content_safe, ContentSafeOptions};
let with_mention = "@everyone";
let without_mention = content_safe(&cache, &with_mention, &ContentSafeOptions::default(), &[]);
assert_eq!("@\u{200B}everyone".to_string(), without_mention);
Filtering out mentions from a message.
use serenity::client::Cache;
use serenity::model::channel::Message;
use serenity::utils::{content_safe, ContentSafeOptions};
fn filter_message(cache: &Cache, message: &Message) -> String {
content_safe(cache, &message.content, &ContentSafeOptions::default(), &message.mentions)
}