summary refs log tree commit diff
path: root/src/system/plugin/prefixes.rs
blob: a5135732a2e99b29a4b87a3ec5401c0da02ad54d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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<ChannelMarker>, _response: &crate::system::types::Response) {
        return
    }
}