diff options
Diffstat (limited to 'src/system/plugin/autoproxy.rs')
-rw-r--r-- | src/system/plugin/autoproxy.rs | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/system/plugin/autoproxy.rs b/src/system/plugin/autoproxy.rs index 67d93a0..0bbebf5 100644 --- a/src/system/plugin/autoproxy.rs +++ b/src/system/plugin/autoproxy.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use tokio::sync::Mutex; use twilight_model::{channel::{Channel, Message}, id::{marker::ChannelMarker, Id}, util::Timestamp}; use crate::system::types::{System, Member, Response}; -use super::{CommandOutcome, SeancePlugin}; +use super::SeancePlugin; use tokio::time::sleep; use std::time::Duration; use super::Logger; @@ -29,30 +29,31 @@ impl Autoproxy { } #[async_trait] -impl SeancePlugin for Autoproxy { - async fn handle_command(&self, logger: &Logger, system: &System, message: &Message) -> CommandOutcome { - if message.content.starts_with(format!("{}auto ", system.command_prefix).as_str()) { - let args = message.content.replace(format!("{}auto ", system.command_prefix).as_str(), ""); - let mut remainder = args.split_whitespace(); - let first_word = remainder.next(); - - match first_word { - Some("off") => *self.current_state.lock().await = InnerState::Off, - Some("latch") => *self.current_state.lock().await = InnerState::LatchInactive, - Some("member") => { - return CommandOutcome::Errored { message: "Member mode not supported yet".to_string() } - }, - Some(other) => return CommandOutcome::Errored { message: format!("Unknown autoproxy mode: {other}") }, - None => return CommandOutcome::Errored { message: "Must specify autoproxy mode".to_string() }, - } +impl<'system> SeancePlugin<'system> for Autoproxy { + fn get_commands(&self) -> Vec<&'static str> { + vec!["auto"] + } - CommandOutcome::Handled - } else { - CommandOutcome::Skipped - } + async fn handle_command<'message>(&self, logger: &'system Logger, system: &'system System, message: &'message Message, args: Vec<&'message str>) { + let mut args = args.iter().map(|r| *r); + let first_word = args.next(); + + match first_word { + Some("off") => *self.current_state.lock().await = InnerState::Off, + Some("latch") => *self.current_state.lock().await = InnerState::LatchInactive, + Some("member") => { + logger.log_err(None, "Member mode not supported yet".to_string()).await; + }, + Some(other) => { + logger.log_err(None, format!("Unknown autoproxy mode: {other}")).await; + }, + None => { + logger.log_err(None, "Must specify autoproxy mode".to_string()).await; + } + }; } - async fn handle_message(&self, logger: &Logger, system: &System, message: &Message, response: &mut Response) { + async fn handle_message<'message>(&self, logger: &'system Logger, system: &'system System, message: &'message Message, response: &'message mut Response) { let starting_state = {self.current_state.lock().await.clone()}; if message.content.starts_with("\\") { logger.log_line(None, "Skipping proxy".to_string()).await; @@ -97,10 +98,9 @@ impl SeancePlugin for Autoproxy { } } - async fn post_response(&self, logger: &Logger, system: &System, message: &Message, channel: Id<ChannelMarker>, response: &Response) { + async fn post_response<'message>(&self, logger: &'system Logger, system: &'system System, message: &'message Message, channel: Id<ChannelMarker>, response: &'message Response) { match response { - Response::Noop { delete_source } => return, - Response::Proxy { member, content } => { + Response::Proxy { member, content: _ } => { let current_state = {self.current_state.lock().await.clone()}; match current_state { InnerState::Off => return, @@ -156,6 +156,7 @@ impl SeancePlugin for Autoproxy { }, } }, + _ => return, } } |