1 #![recursion_limit = "512"]
3 pub extern crate strum_macros;
5 pub extern crate lazy_static;
7 pub extern crate failure;
9 pub extern crate diesel;
10 pub extern crate actix;
11 pub extern crate actix_web;
12 pub extern crate bcrypt;
13 pub extern crate chrono;
14 pub extern crate dotenv;
15 pub extern crate jsonwebtoken;
16 pub extern crate rand;
17 pub extern crate regex;
18 pub extern crate serde;
19 pub extern crate serde_json;
20 pub extern crate strum;
28 use chrono::{DateTime, NaiveDateTime, Utc};
43 db_url: env::var("DATABASE_URL").expect("DATABASE_URL must be set"),
44 hostname: env::var("HOSTNAME").unwrap_or("rrr".to_string()),
45 jwt_secret: env::var("JWT_SECRET").unwrap_or("changeme".to_string()),
48 fn api_endpoint(&self) -> String {
49 format!("{}/api/v1", self.hostname)
53 pub fn to_datetime_utc(ndt: NaiveDateTime) -> DateTime<Utc> {
54 DateTime::<Utc>::from_utc(ndt, Utc)
57 pub fn naive_now() -> NaiveDateTime {
58 chrono::prelude::Utc::now().naive_utc()
61 pub fn naive_from_unix(time: i64) -> NaiveDateTime {
62 NaiveDateTime::from_timestamp(time, 0)
65 pub fn is_email_regex(test: &str) -> bool {
66 EMAIL_REGEX.is_match(test)
69 pub fn remove_slurs(test: &str) -> String {
70 SLUR_REGEX.replace_all(test, "*removed*").to_string()
73 pub fn has_slurs(test: &str) -> bool {
74 SLUR_REGEX.is_match(test)
79 use crate::{has_slurs, is_email_regex, remove_slurs, Settings};
82 assert_eq!(Settings::get().api_endpoint(), "rrr/api/v1");
87 assert!(is_email_regex("gush@gmail.com"));
88 assert!(!is_email_regex("nada_neutho"));
92 fn test_slur_filter() {
93 let test = "coons test dindu ladyboy tranny. This is a bunch of other safe text.".to_string();
94 let slur_free = "No slurs here";
97 "*removed* test *removed* *removed* *removed*. This is a bunch of other safe text."
100 assert!(has_slurs(&test));
101 assert!(!has_slurs(slur_free));
107 static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
108 static ref SLUR_REGEX: Regex = Regex::new(r"(fag(g|got|tard)?|maricos?|cock\s?sucker(s|ing)?|\bnig(\b|g?(a|er)?s?)\b|dindu(s?)|mudslime?s?|kikes?|mongoloids?|towel\s*heads?|\bspi(c|k)s?\b|\bchinks?|niglets?|beaners?|\bnips?\b|\bcoons?\b|jungle\s*bunn(y|ies?)|jigg?aboo?s?|\bpakis?\b|rag\s*heads?|gooks?|cunts?|bitch(es|ing|y)?|puss(y|ies?)|twats?|feminazis?|whor(es?|ing)|\bslut(s|t?y)?|\btrann?(y|ies?)|ladyboy(s?))").unwrap();