add: ability to ban strings/characters through server config
This commit is contained in:
parent
701ea79c9a
commit
c9983b8dcb
3 changed files with 48 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
use super::*;
|
||||
use crate::cache::Cache;
|
||||
use crate::config::StringBan;
|
||||
use crate::model::auth::Notification;
|
||||
use crate::model::communities::Question;
|
||||
use crate::model::communities_permissions::CommunityPermission;
|
||||
|
@ -1153,6 +1154,25 @@ impl DataManager {
|
|||
/// # Arguments
|
||||
/// * `data` - a mock [`Post`] object to insert
|
||||
pub async fn create_post(&self, mut data: Post) -> Result<usize> {
|
||||
// check characters
|
||||
for ban in &self.0.banned_data {
|
||||
match ban {
|
||||
StringBan::String(x) => {
|
||||
if data.content.contains(x) {
|
||||
return Ok(0);
|
||||
}
|
||||
}
|
||||
StringBan::Unicode(x) => {
|
||||
if data.content.contains(&match char::from_u32(x.to_owned()) {
|
||||
Some(c) => c.to_string(),
|
||||
None => continue,
|
||||
}) {
|
||||
return Ok(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check values (if this isn't reposting something else)
|
||||
let is_reposting = if let Some(ref repost) = data.context.repost {
|
||||
repost.reposting.is_some()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue