1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 00:15:17 +00:00

Can create custom emoji

This commit is contained in:
2021-01-20 18:31:01 +01:00
parent 110f84eb0a
commit 99c7bb2899
12 changed files with 126 additions and 15 deletions

View File

@ -5,6 +5,7 @@
use std::str::FromStr;
use actix_web::http::Uri;
use regex::Regex;
/// Escape an HTML string
///
@ -71,4 +72,24 @@ pub fn check_youtube_id(id: &str) -> bool {
&& !id.contains(".")
&& !id.contains("'")
&& !id.contains("\"")
}
/// Check the validity of an emoji shortcut
///
/// ```
/// use comunic_server::utils::string_utils::check_emoji_code;
///
/// assert_eq!(check_emoji_code(":comunic:"), true);
/// assert_eq!(check_emoji_code(":comunic"), false);
/// assert_eq!(check_emoji_code("::"), false);
/// assert_eq!(check_emoji_code("a:comunic:"), false);
/// assert_eq!(check_emoji_code(":comunic:a"), false);
/// assert_eq!(check_emoji_code(":co:munic:"), false);
/// assert_eq!(check_emoji_code(":comuni@c:"), false);
/// assert_eq!(check_emoji_code("bbb:comuni@c:123"), false);
/// ```
pub fn check_emoji_code(shortcut: &str) -> bool {
let r = Regex::new(r"^:[a-zA-Z0-9]+:$").unwrap();
r.is_match(shortcut)
}