about summary refs log tree commit diff
path: root/src/util.rs
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2025-08-03 22:08:44 -0500
committergennyble <gen@nyble.dev>2025-08-03 22:08:44 -0500
commit76c1f83074e84a21eb5f5a69b160b1facbeb9cac (patch)
tree9a53a3a5d65678a41dfbbac1c91d26b46de06768 /src/util.rs
parent61927e384d5fc07c7094d0cdf77b8c246d456a63 (diff)
downloadleaberblord-76c1f83074e84a21eb5f5a69b160b1facbeb9cac.tar.gz
leaberblord-76c1f83074e84a21eb5f5a69b160b1facbeb9cac.zip
code cleanup; break commands into their own module
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/util.rs b/src/util.rs
index a05eeb9..a746cb3 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,7 +1,36 @@
 //! Uh-oh, a `util.rs` file. That can't be good.
 
+use twilight_model::id::{Id, marker::UserMarker};
+
 use crate::database::{BoardRow, Placement};
 
+#[macro_export]
+macro_rules! bail {
+	($msg:expr) => {
+		return twilight_util::builder::InteractionResponseDataBuilder::new()
+			.content(&format!("❌ {}", $msg))
+			.build()
+	};
+}
+
+#[macro_export]
+macro_rules! fail {
+	($msg:expr) => {
+		twilight_util::builder::InteractionResponseDataBuilder::new()
+			.content(&format!("❌ {}", $msg))
+			.build()
+	};
+}
+
+#[macro_export]
+macro_rules! success {
+	($msg:expr) => {
+		twilight_util::builder::InteractionResponseDataBuilder::new()
+			.content(&format!("✅ {}", $msg))
+			.build()
+	};
+}
+
 pub fn tiebreak_shared_positions(board: Vec<BoardRow>) -> Vec<Placement> {
 	let first = match board.first() {
 		Some(r) => r.clone(),
@@ -40,3 +69,29 @@ pub fn tiebreak_shared_positions(board: Vec<BoardRow>) -> Vec<Placement> {
 
 	placed
 }
+
+/// Takes a `&str` and extracts all mentions of users, sticking them in a Vec
+pub fn extract_user_mentions(mut raw: &str) -> Vec<Id<UserMarker>> {
+	let mut ret = vec![];
+
+	loop {
+		let Some(start) = raw.find("<@") else {
+			break;
+		};
+
+		let Some(end) = raw.find('>') else {
+			break;
+		};
+
+		let id_str = &raw[start + 2..end];
+		raw = &raw[end + 1..];
+
+		let Ok(id) = u64::from_str_radix(id_str, 10) else {
+			continue;
+		};
+
+		ret.push(Id::new(id));
+	}
+
+	ret
+}