From 2c3a7c253b1e0bc996a50e5f64fc589eb660c03c Mon Sep 17 00:00:00 2001 From: benthecarman Date: Mon, 5 Feb 2024 21:04:14 +0000 Subject: [PATCH] Add lightning regex --- Cargo.lock | 2 ++ Cargo.toml | 2 ++ src/utils.rs | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 7184f57..65e4325 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2604,6 +2604,7 @@ dependencies = [ "futures", "hex", "itertools", + "lazy_static", "lightning", "lightning-invoice", "lnurl-rs", @@ -2611,6 +2612,7 @@ dependencies = [ "nostr", "nostr-sdk", "pretty_env_logger", + "regex", "serde", "serde_json", "tokio", diff --git a/Cargo.toml b/Cargo.toml index e04ea05..88e4f3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,8 @@ serde_json = "1.0" tokio = { version = "1.12.0", features = ["full"] } tower-http = { version = "0.4.0", features = ["cors"] } urlencoding = "2.1.2" +regex = "1.10.2" +lazy_static = "1.4" [dev-dependencies] dotenv = "0.15.0" diff --git a/src/utils.rs b/src/utils.rs index eef5b61..6da6c20 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,12 +1,25 @@ use bitcoin::bip32::ExtendedPrivKey; use bitcoin::hashes::{sha256, Hash}; +use lazy_static::lazy_static; use nostr::key::XOnlyPublicKey; +use regex::Regex; + +lazy_static! { + static ref LN_REG: Regex = + Regex::new(r"^\u{26A1}[\u{FE00}-\u{FE0F}]?$").expect("Invalid regex"); +} pub fn map_emoji(emoji: &str) -> Option<&str> { match emoji { "❤" | "+" | "" => Some("❤️"), "⚡️" => Some("⚡"), - _ => None, + str => { + if LN_REG.is_match(str) { + Some("⚡") + } else { + None + } + } } }