From e9253bd959bf5bf6e8bcc6de4db247895b015a16 Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Fri, 28 Feb 2025 21:52:16 -0700 Subject: Partial refactor Handles message prefixes and autoproxy --- src/system/plugin/prefixes.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/system/plugin/prefixes.rs (limited to 'src/system/plugin/prefixes.rs') diff --git a/src/system/plugin/prefixes.rs b/src/system/plugin/prefixes.rs new file mode 100644 index 0000000..a513573 --- /dev/null +++ b/src/system/plugin/prefixes.rs @@ -0,0 +1,40 @@ +use async_trait::async_trait; +use twilight_model::id::{marker::ChannelMarker, Id}; +use crate::system::types::Response; + +use super::{CommandOutcome, SeancePlugin}; + +pub struct ProxyPrefixes; + +#[async_trait] +impl SeancePlugin for ProxyPrefixes { + async fn handle_command(&self, _system: &crate::system::types::System, _message: &twilight_model::channel::Message) -> CommandOutcome { + CommandOutcome::Skipped + } + + async fn handle_message(&self, system: &crate::system::types::System, message: &twilight_model::channel::Message, response: &mut crate::system::types::Response) { + if let Response::Noop { delete_source: _ } = response { + for member in &system.members { + println!("Checking member prefix: {:?}", member.message_pattern); + match member.message_pattern.captures(message.content.as_str()) { + None => { + println!("Nope"); + continue; + }, + Some(captures) => match captures.name("content") { + None => continue, + Some(matched_content) => { + println!("Matched member prefix: {:?}", member.message_pattern); + *response = Response::Proxy { member: member.clone(), content: matched_content.as_str().to_string() }; + return + }, + } + } + } + } + } + + async fn post_response(&self, _system: &crate::system::types::System, _message: &twilight_model::channel::Message, _channel: Id, _response: &crate::system::types::Response) { + return + } +} -- cgit 1.4.1