mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-22 19:01:32 +00:00
* Actualize a comment about config initialization * Add additional slurs functionality. It is possible to additional regex for slurs filtering. It can be done through `additional_slurs` option in config file.
This commit is contained in:
parent
100a56e8ef
commit
7008848f9c
5 changed files with 20 additions and 5 deletions
|
@ -90,4 +90,8 @@
|
||||||
# # whether or not smtp connections should use tls
|
# # whether or not smtp connections should use tls
|
||||||
# use_tls: true
|
# use_tls: true
|
||||||
# }
|
# }
|
||||||
|
# additional_slurs:
|
||||||
|
# '''
|
||||||
|
# (\bThis\b)|(\bis\b)|(\bsample\b)
|
||||||
|
# '''
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ impl Default for Settings {
|
||||||
jwt_secret: Some("changeme".into()),
|
jwt_secret: Some("changeme".into()),
|
||||||
pictrs_url: Some("http://pictrs:8080".into()),
|
pictrs_url: Some("http://pictrs:8080".into()),
|
||||||
iframely_url: Some("http://iframely".into()),
|
iframely_url: Some("http://iframely".into()),
|
||||||
|
additional_slurs: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,10 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
/// Reads config from the files and environment.
|
/// Reads config from configuration file.
|
||||||
/// First, defaults are loaded from CONFIG_FILE_DEFAULTS, then these values can be overwritten
|
/// Then values from the environment (with prefix LEMMY) are added to the config.
|
||||||
/// from CONFIG_FILE (optional). Finally, values from the environment (with prefix LEMMY) are
|
/// And then default values are merged into config.
|
||||||
/// added to the config.
|
/// Defaults are controlled by Default trait implemntation for Settings structs.
|
||||||
///
|
///
|
||||||
/// Note: The env var `LEMMY_DATABASE_URL` is parsed in
|
/// Note: The env var `LEMMY_DATABASE_URL` is parsed in
|
||||||
/// `lemmy_db_queries/src/lib.rs::get_database_url_from_env()`
|
/// `lemmy_db_queries/src/lib.rs::get_database_url_from_env()`
|
||||||
|
|
|
@ -17,6 +17,7 @@ pub struct Settings {
|
||||||
pub(crate) captcha: Option<CaptchaConfig>,
|
pub(crate) captcha: Option<CaptchaConfig>,
|
||||||
pub(crate) email: Option<EmailConfig>,
|
pub(crate) email: Option<EmailConfig>,
|
||||||
pub(crate) setup: Option<SetupConfig>,
|
pub(crate) setup: Option<SetupConfig>,
|
||||||
|
pub(crate) additional_slurs: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
|
|
|
@ -7,7 +7,16 @@ use regex::{Regex, RegexBuilder};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").expect("compile regex");
|
static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").expect("compile regex");
|
||||||
static ref SLUR_REGEX: Regex = RegexBuilder::new(r"(fag(g|got|tard)?\b|cock\s?sucker(s|ing)?|ni((g{2,}|q)+|[gq]{2,})[e3r]+(s|z)?|mudslime?s?|kikes?|\bspi(c|k)s?\b|\bchinks?|gooks?|bitch(es|ing|y)?|whor(es?|ing)|\btr(a|@)nn?(y|ies?)|\b(b|re|r)tard(ed)?s?)").case_insensitive(true).build().expect("compile regex");
|
static ref SLUR_REGEX: Regex = {
|
||||||
|
let mut slurs = r"(fag(g|got|tard)?\b|cock\s?sucker(s|ing)?|ni((g{2,}|q)+|[gq]{2,})[e3r]+(s|z)?|mudslime?s?|kikes?|\bspi(c|k)s?\b|\bchinks?|gooks?|bitch(es|ing|y)?|whor(es?|ing)|\btr(a|@)nn?(y|ies?)|\b(b|re|r)tard(ed)?s?)".to_string();
|
||||||
|
if let Some(additional_slurs) = Settings::get().additional_slurs {
|
||||||
|
slurs.push('|');
|
||||||
|
slurs.push_str(&additional_slurs);
|
||||||
|
};
|
||||||
|
RegexBuilder::new(&&slurs).case_insensitive(true).build().expect("compile regex")
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static ref USERNAME_MATCHES_REGEX: Regex = Regex::new(r"/u/[a-zA-Z][0-9a-zA-Z_]*").expect("compile regex");
|
static ref USERNAME_MATCHES_REGEX: Regex = Regex::new(r"/u/[a-zA-Z][0-9a-zA-Z_]*").expect("compile regex");
|
||||||
// TODO keep this old one, it didn't work with port well tho
|
// TODO keep this old one, it didn't work with port well tho
|
||||||
// static ref MENTIONS_REGEX: Regex = Regex::new(r"@(?P<name>[\w.]+)@(?P<domain>[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)").expect("compile regex");
|
// static ref MENTIONS_REGEX: Regex = Regex::new(r"@(?P<name>[\w.]+)@(?P<domain>[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)").expect("compile regex");
|
||||||
|
|
Loading…
Reference in a new issue