summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAshelyn Rose <git@ashen.earth>2024-10-01 00:00:45 -0600
committerAshelyn Rose <git@ashen.earth>2024-10-01 00:00:45 -0600
commit7c3f983bc830a85641e8a38545dfb9220570c5a2 (patch)
treee7f1c90ca6e060fb49dab8bf79d8c862255e1035 /src
parentf8d2b25d1a4a5ef33b5343e5bff0a48a4a41a702 (diff)
Allow use of !panic to reload config, also set presence on startup
Diffstat (limited to 'src')
-rw-r--r--src/listener.rs1
-rw-r--r--src/system.rs19
2 files changed, 19 insertions, 1 deletions
diff --git a/src/listener.rs b/src/listener.rs
index 31c134d..3b432cf 100644
--- a/src/listener.rs
+++ b/src/listener.rs
@@ -100,6 +100,7 @@ impl Listener {
 }
 
 pub enum ClientEvent {
+    Startup,
     Ready {
         client_name: String,
         send_channel: MessageSender,
diff --git a/src/system.rs b/src/system.rs
index d708074..f62eeb6 100644
--- a/src/system.rs
+++ b/src/system.rs
@@ -1,4 +1,4 @@
-use std::{collections::HashMap, num::NonZeroUsize, str::FromStr, time::Duration};
+use std::{collections::HashMap, convert::Infallible, num::NonZeroUsize, str::FromStr, time::Duration};
 
 use tokio::{sync::mpsc::{channel, Receiver, Sender}, time::{Sleep,sleep}};
 use futures::future::join_all;
@@ -47,6 +47,8 @@ impl System {
 
             let tx = self.channel.0.clone();
             let member = member.clone();
+
+            // Start gateway listener
             tokio::spawn(async move {
                 let mut listener = Listener::new(member, reference_user_id);
                 listener.start_listening(tx).await;
@@ -58,6 +60,14 @@ impl System {
                 Some(event) => match event {
                     ClientEvent::Ready { client_name, send_channel } => {
                         self.gateway_channels.insert(client_name, send_channel);
+
+                        if self.gateway_channels.len() == self.clients.len() {
+                            let tx = self.channel.0.clone();
+                            tokio::spawn(async move {
+                                sleep(Duration::from_secs(10)).await;
+                                let _ = tx.send(ClientEvent::Startup).await;
+                            });
+                        }
                     },
                     ClientEvent::Message { event_time, message } => {
                         if self.is_new_message(message.id, event_time) {
@@ -77,6 +87,10 @@ impl System {
                             }
                         }
                     },
+                    ClientEvent::Startup => {
+                        println!("Attempting to set startup status for system {}", self.name.clone());
+                        self.update_status_of_system();
+                    },
                 },
                 None => {
                     return
@@ -99,6 +113,9 @@ impl System {
 
     async fn handle_message(&mut self, message: Message, timestamp: Timestamp) {
         // TODO: Commands
+        if message.content.eq("!panic") {
+            panic!("Exiting due to user command");
+        }
 
         // Escape sequence
         if message.content.starts_with(r"\") {