diff options
author | Ashelyn Rose <git@ashen.earth> | 2025-03-01 19:14:24 -0700 |
---|---|---|
committer | Ashelyn Rose <git@ashen.earth> | 2025-03-01 19:16:54 -0700 |
commit | 2cd846913aaba03dda8a6071ecc28c85c5a26fa4 (patch) | |
tree | 3b82a55ccc9a4d66c33a53e83c46376f56bee85c | |
parent | c3063561e247ddeba1ca337af23f53832e45001e (diff) |
Move autoproxy impl
-rw-r--r-- | src/system/plugin/autoproxy.rs | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/src/system/plugin/autoproxy.rs b/src/system/plugin/autoproxy.rs index 03e20b8..8f468a8 100644 --- a/src/system/plugin/autoproxy.rs +++ b/src/system/plugin/autoproxy.rs @@ -28,44 +28,6 @@ impl Autoproxy { } } -impl Autoproxy { - // Sets the latch and sets a timeout to unlatch it if - // state is identical when the timeout goes off - async fn set_latch(&self, member: &Member, latch_time: &Timestamp) { - let starting_state = {self.current_state.lock().await.clone()}; - - let is_latch = match starting_state { - InnerState::LatchActive { current_member: _, last_message: _ } - | InnerState::LatchInactive => true, - _ => false, - }; - - if !is_latch { - return - } - - {*self.current_state.lock().await = InnerState::LatchActive { - current_member: member.clone(), - last_message: latch_time.clone(), - }}; - - let state_arc = self.current_state.clone(); - let sent_member = member.clone(); - let sent_timestamp = latch_time.clone(); - - tokio::spawn(async move { - sleep(Duration::from_secs(15 * 60)).await; - let current_state = {state_arc.lock().await.clone()}; - - if let InnerState::LatchActive { current_member, last_message } = current_state { - if sent_member.discord_token == current_member.discord_token && sent_timestamp.as_micros() == last_message.as_micros() { - {*state_arc.lock().await = InnerState::LatchInactive}; - } - } - }); - } -} - #[async_trait] impl<'system> SeancePlugin<'system> for Autoproxy { fn get_commands(&self) -> Vec<PluginCommand> { @@ -173,3 +135,41 @@ impl<'system> SeancePlugin<'system> for Autoproxy { } } + +impl Autoproxy { + // Sets the latch and sets a timeout to unlatch it if + // state is identical when the timeout goes off + async fn set_latch(&self, member: &Member, latch_time: &Timestamp) { + let starting_state = {self.current_state.lock().await.clone()}; + + let is_latch = match starting_state { + InnerState::LatchActive { current_member: _, last_message: _ } + | InnerState::LatchInactive => true, + _ => false, + }; + + if !is_latch { + return + } + + {*self.current_state.lock().await = InnerState::LatchActive { + current_member: member.clone(), + last_message: latch_time.clone(), + }}; + + let state_arc = self.current_state.clone(); + let sent_member = member.clone(); + let sent_timestamp = latch_time.clone(); + + tokio::spawn(async move { + sleep(Duration::from_secs(15 * 60)).await; + let current_state = {state_arc.lock().await.clone()}; + + if let InnerState::LatchActive { current_member, last_message } = current_state { + if sent_member.discord_token == current_member.discord_token && sent_timestamp.as_micros() == last_message.as_micros() { + {*state_arc.lock().await = InnerState::LatchInactive}; + } + } + }); + } +} |