about summary refs log tree commit diff
path: root/src/util.rs
diff options
context:
space:
mode:
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
+}