summary refs log tree commit diff
path: root/src/system
diff options
context:
space:
mode:
Diffstat (limited to 'src/system')
-rw-r--r--src/system/message_parser.rs10
-rw-r--r--src/system/mod.rs26
2 files changed, 31 insertions, 5 deletions
diff --git a/src/system/message_parser.rs b/src/system/message_parser.rs
index e769eed..5d14095 100644
--- a/src/system/message_parser.rs
+++ b/src/system/message_parser.rs
@@ -65,7 +65,7 @@ impl MessageParser {
             }
         }
 
-        if let Some(parse) = MessageParser::check_member_patterns(message, system_config) {
+        if let Some(parse) = MessageParser::check_member_patterns(message, secondary_message, system_config) {
             return parse
         }
 
@@ -150,13 +150,15 @@ impl MessageParser {
         None
     }
 
-    fn check_member_patterns(message: &FullMessage, system_config: &System) -> Option<ParsedMessage> {
+    fn check_member_patterns(message: &FullMessage, secondary_message: Option<&FullMessage>, system_config: &System) -> Option<ParsedMessage> {
         let matches_prefix = system_config.members.iter().enumerate().find_map(|(member_id, member)|
             Some((member_id, member.matches_proxy_prefix(&message)?))
         );
 
         if let Some((member_id, matched_content)) = matches_prefix {
-            if matched_content.trim() != "" {
+            if matched_content.trim() == "*" {
+                Some(ParsedMessage::Command(Command::Reproxy(member_id, secondary_message.unwrap().id)))
+            } else if matched_content.trim() != "" {
                 Some(ParsedMessage::ProxiedMessage {
                     member_id,
                     message_content: matched_content.to_string(),
@@ -192,7 +194,7 @@ impl MessageParser {
         None
     }
 
-    fn get_member_id_from_user_id(user_id: UserId, system_config: &System) -> Option<MemberId> {
+    pub fn get_member_id_from_user_id(user_id: UserId, system_config: &System) -> Option<MemberId> {
         system_config.members.iter().enumerate()
             .filter(|(_id, m)| m.user_id.is_some())
             .find(|(_id, m)| m.user_id.unwrap() == user_id)
diff --git a/src/system/mod.rs b/src/system/mod.rs
index 8fea1fa..ad2031f 100644
--- a/src/system/mod.rs
+++ b/src/system/mod.rs
@@ -21,7 +21,7 @@ use aggregator::MessageAggregator;
 use bot::Bot;
 pub use types::*;
 
-use self::message_parser::Command;
+use self::message_parser::{Command, ParsedMessage};
 
 
 pub struct Manager {
@@ -207,6 +207,7 @@ impl Manager {
             message_parser::ParsedMessage::LatchClear(member_id) => {
                 let _ = self.bots.get(&member_id).unwrap().delete_message(message.channel_id, message.id).await;
                 self.latch_state = None;
+                self.update_status_of_system();
             },
 
             message_parser::ParsedMessage::SetProxyAndDelete(member_id) => {
@@ -240,6 +241,29 @@ impl Manager {
                 }
             }
 
+            message_parser::ParsedMessage::Command(Command::Reproxy(member_id, message_id)) => {
+                if !referenced_message.map(|message| message.id == message_id).unwrap_or(false) {
+                    println!("ERROR: Attempted reproxy on message other than referenced_message");
+                    let _ = self.bots.get(&member_id).unwrap().react_message(message.channel_id, message.id, &RequestReactionType::Unicode { name: "⁉️" }).await;
+                    return
+                }
+
+                let message_author = MessageParser::get_member_id_from_user_id(referenced_message.unwrap().author.id, &self.config).unwrap();
+                if message_author != member_id {
+                    // TODO: Don't allow this if other messages have been sent maybe?
+                    let orig = referenced_message.unwrap().clone();
+                    if let Ok(_) = self.proxy_message(&orig, member_id, orig.content.as_str()).await {
+                        self.update_autoproxy_state_after_message(member_id, timestamp);
+                        self.update_status_of_system().await;
+                    }
+                } else {
+                    println!("Not reproxying under same user");
+                }
+
+                let bot = self.bots.get(&member_id).unwrap();
+                let _ = bot.delete_message(message.channel_id, message.id).await;
+            }
+
             message_parser::ParsedMessage::Command(Command::UnknownCommand) => {
                 let member_id = if let Some((member_id, _)) = self.latch_state {
                     member_id