summary refs log tree commit diff
path: root/src/system.rs
diff options
context:
space:
mode:
authorashelyn ghost <git@ashen.earth>2024-07-08 21:30:34 -0600
committerAshelyn Rose <git@ashen.earth>2024-07-08 21:30:34 -0600
commitd22f2b74d8931a32da0ed970bedcb4e49f4934f7 (patch)
tree45a595ba1ef413a6719458a3a7aed2bd33cea791 /src/system.rs
parent2bacf887c0f3aff01d60dd1255b2d0e673f550ea (diff)
Basic proxying
Diffstat (limited to 'src/system.rs')
-rw-r--r--src/system.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/system.rs b/src/system.rs
index 9a8b327..332e901 100644
--- a/src/system.rs
+++ b/src/system.rs
@@ -2,7 +2,7 @@ use std::{collections::HashMap, num::NonZeroUsize, str::FromStr};
 
 use tokio::sync::mpsc::channel;
 use twilight_http::Client;
-use twilight_model::id::{Id, marker::{MessageMarker, UserMarker}};
+use twilight_model::id::{Id, marker::{ChannelMarker, MessageMarker, UserMarker}};
 use twilight_model::util::Timestamp;
 
 use crate::listener::{Listener, ClientEvent};
@@ -47,11 +47,11 @@ impl System {
         loop {
             match rx.recv().await {
                 Some(event) => match event {
-                    ClientEvent::Message { event_time, message_id, content, author: _ } => {
+                    ClientEvent::Message { event_time, message_id, channel_id, content, author: _ } => {
                         if self.is_new_message(message_id, event_time) {
-                            self.handle_message(content).await;
+                            self.handle_message(message_id, channel_id, content).await;
                         }
-                    }
+                    },
                     ClientEvent::Error(_err) => {
                         println!("Client ran into an error for system {}", self.name);
                         return
@@ -76,7 +76,20 @@ impl System {
         }
     }
 
-    async fn handle_message(&mut self, content: String) {
-        println!("Message: {}", content);
+    async fn handle_message(&mut self, message_id: Id<MessageMarker>, channel_id: Id<ChannelMarker>, content: String) {
+        // Check for command
+        
+        // Check for prefix
+        for member in self.config.members.iter() {
+            if let Some(captures) = member.message_pattern.captures(content.as_str()) {
+                let client = self.clients.get(&member.name).expect("No client for member");
+                let content = captures.name("content").expect("No capture group").as_str();
+
+                if let Ok(_) = client.create_message(channel_id)
+                    .content(content).expect("Cannot set content").await {
+                        client.delete_message(channel_id, message_id).await.expect("Could not delete message");
+                    }
+            }
+        }
     }
 }