summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAshelyn Rose <git@ashen.earth>2024-10-06 18:15:01 -0600
committerAshelyn Rose <git@ashen.earth>2024-10-06 18:15:01 -0600
commit5b9a118c3a2a3f421b0a8a2d69b3a85c2c7b27b2 (patch)
tree16749f34c3fc7ce8cd69f46b9d396a82f0dd18a9 /src
parent27d7107a127f3ff513b6281d94e22ce6ff781115 (diff)
Implement delete
Diffstat (limited to 'src')
-rw-r--r--src/system/message_parser.rs4
-rw-r--r--src/system/mod.rs36
2 files changed, 36 insertions, 4 deletions
diff --git a/src/system/message_parser.rs b/src/system/message_parser.rs
index 5d14095..59bfb7f 100644
--- a/src/system/message_parser.rs
+++ b/src/system/message_parser.rs
@@ -26,6 +26,7 @@ pub enum ParsedMessage {
 pub enum Command {
     Edit(MemberId, MessageId, String),
     Reproxy(MemberId, MessageId),
+    Delete(MessageId),
     Nick(MemberId, String),
     ReloadSystemConfig,
     ExitSéance,
@@ -97,6 +98,9 @@ impl MessageParser {
                         return Command::Reproxy(member, secondary_message.unwrap().id);
                     }
                 },
+                "delete" => {
+                    return Command::Delete(secondary_message.unwrap().id);
+                }
                 _ => (),
             },
             None => return Command::UnknownCommand,
diff --git a/src/system/mod.rs b/src/system/mod.rs
index ad2031f..d993731 100644
--- a/src/system/mod.rs
+++ b/src/system/mod.rs
@@ -207,13 +207,13 @@ 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();
+                self.update_status_of_system().await;
             },
 
             message_parser::ParsedMessage::SetProxyAndDelete(member_id) => {
                 let _ = self.bots.get(&member_id).unwrap().delete_message(message.channel_id, message.id).await;
                 self.update_autoproxy_state_after_message(member_id, message.timestamp);
-                self.update_status_of_system();
+                self.update_status_of_system().await;
             }
 
             message_parser::ParsedMessage::ProxiedMessage { member_id, message_content, latch } => {
@@ -228,6 +228,13 @@ impl Manager {
             message_parser::ParsedMessage::Command(Command::Edit(member_id, message_id, new_content)) => {
                 let bot = self.bots.get(&member_id).unwrap();
 
+                let author = MessageParser::get_member_id_from_user_id(referenced_message.unwrap().author.id, &self.config);
+                if author.is_none() {
+                    println!("Cannot edit another user's message");
+                    let _ = self.bots.get(&member_id).unwrap().react_message(message.channel_id, message.id, &RequestReactionType::Unicode { name: "🛑" }).await;
+                    return
+                }
+
                 if let Ok(new_message) = bot.edit_message(message.channel_id, message_id, new_content).await {
 
                     // If we just edited the most recently sent message in this channel, update
@@ -248,8 +255,14 @@ impl Manager {
                     return
                 }
 
-                let message_author = MessageParser::get_member_id_from_user_id(referenced_message.unwrap().author.id, &self.config).unwrap();
-                if message_author != member_id {
+                let author = MessageParser::get_member_id_from_user_id(referenced_message.unwrap().author.id, &self.config);
+                if author.is_none() {
+                    println!("Cannot reproxy another user's message");
+                    let _ = self.bots.get(&member_id).unwrap().react_message(message.channel_id, message.id, &RequestReactionType::Unicode { name: "🛑" }).await;
+                    return
+                }
+
+                if author.unwrap() != 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 {
@@ -264,6 +277,21 @@ impl Manager {
                 let _ = bot.delete_message(message.channel_id, message.id).await;
             }
 
+            message_parser::ParsedMessage::Command(Command::Delete(message_id)) => {
+                let member_id = self.latch_state.map(|(id,_)| id).unwrap_or(0);
+
+                let author = MessageParser::get_member_id_from_user_id(referenced_message.unwrap().author.id, &self.config);
+                if author.is_none() {
+                    println!("Cannot delete another user's message");
+                    let _ = self.bots.get(&member_id).unwrap().react_message(message.channel_id, message.id, &RequestReactionType::Unicode { name: "🛑" }).await;
+                    return
+                }
+
+                let bot = self.bots.get(&member_id).unwrap();
+                let _ = bot.delete_message(message.channel_id, message_id).await;
+                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