1 #![recursion_limit = "512"]
2 #[macro_use] pub extern crate strum_macros;
3 #[macro_use] pub extern crate lazy_static;
4 #[macro_use] pub extern crate failure;
5 #[macro_use] pub extern crate diesel;
6 pub extern crate dotenv;
7 pub extern crate chrono;
8 pub extern crate serde;
9 pub extern crate serde_json;
10 pub extern crate actix;
11 pub extern crate actix_web;
12 pub extern crate rand;
13 pub extern crate strum;
14 pub extern crate jsonwebtoken;
15 pub extern crate bcrypt;
16 pub extern crate regex;
27 use chrono::{DateTime, NaiveDateTime, Utc};
39 db_url: env::var("DATABASE_URL")
40 .expect("DATABASE_URL must be set"),
41 hostname: env::var("HOSTNAME").unwrap_or("rrr".to_string()),
42 jwt_secret: env::var("JWT_SECRET").unwrap_or("changeme".to_string()),
45 fn api_endpoint(&self) -> String {
46 format!("{}/api/v1", self.hostname)
50 pub fn to_datetime_utc(ndt: NaiveDateTime) -> DateTime<Utc> {
51 DateTime::<Utc>::from_utc(ndt, Utc)
54 pub fn naive_now() -> NaiveDateTime {
55 chrono::prelude::Utc::now().naive_utc()
58 pub fn naive_from_unix(time: i64) -> NaiveDateTime {
59 NaiveDateTime::from_timestamp(time, 0)
62 pub fn is_email_regex(test: &str) -> bool {
63 EMAIL_REGEX.is_match(test)
66 pub fn remove_slurs(test: &str) -> String {
67 SLUR_REGEX.replace_all(test, "*removed*").to_string()
70 pub fn has_slurs(test: &str) -> bool {
71 SLUR_REGEX.is_match(test)
76 use crate::{Settings, is_email_regex, remove_slurs, has_slurs};
79 assert_eq!(Settings::get().api_endpoint(), "rrr/api/v1");
82 #[test] fn test_email() {
83 assert!(is_email_regex("gush@gmail.com"));
84 assert!(!is_email_regex("nada_neutho"));
87 #[test] fn test_slur_filter() {
88 let test = "coons test dindu ladyboy tranny. This is a bunch of other safe text.".to_string();
89 let slur_free = "No slurs here";
90 assert_eq!(remove_slurs(&test), "*removed* test *removed* *removed* *removed*. This is a bunch of other safe text.".to_string());
91 assert!(has_slurs(&test));
92 assert!(!has_slurs(slur_free));
98 static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
99 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();