@@ -4,13 +4,14 @@ use crate::commands::delete::common::{
44} ;
55use crate :: commands:: { BoxFuture , RegistrableCommand } ;
66use crate :: config:: Config ;
7+ use crate :: db:: messages:: get_thread_message_by_message_id;
78use crate :: errors:: { MessageError , ModmailError , ModmailResult , common} ;
89use crate :: i18n:: get_translated_message;
910use crate :: utils:: command:: defer_response:: defer_response_ephemeral;
1011use crate :: utils:: message:: message_builder:: MessageBuilder ;
1112use serenity:: all:: {
12- CommandDataOptionValue , CommandInteraction , CommandOptionType , Context , CreateCommand ,
13- CreateCommandOption , ResolvedOption ,
13+ CommandDataOptionValue , CommandInteraction , CommandOptionType , CommandType , Context ,
14+ CreateCommand , CreateCommandOption , ResolvedOption ,
1415} ;
1516use std:: collections:: HashMap ;
1617
@@ -56,6 +57,7 @@ impl RegistrableCommand for DeleteCommand {
5657 )
5758 . required( true ) ,
5859 ) ,
60+ CreateCommand :: new( "delete" ) . kind( CommandType :: Message ) ,
5961 ]
6062 } )
6163 }
@@ -95,9 +97,32 @@ impl RegistrableCommand for DeleteCommand {
9597 let ( user_id, thread) = get_thread_info ( & command. channel_id . to_string ( ) , pool) . await ?;
9698
9799 if message_number < 0 {
98- return Err ( ModmailError :: Message ( MessageError :: MessageNotFound (
99- "" . to_string ( ) ,
100- ) ) ) ;
100+ if let Some ( message_id) = & command. data . target_id {
101+ let thread_message = match get_thread_message_by_message_id (
102+ & message_id. to_message_id ( ) . to_string ( ) ,
103+ pool,
104+ )
105+ . await
106+ {
107+ Ok ( thread_message) => thread_message,
108+ Err ( e) => {
109+ return Err ( ModmailError :: Message ( MessageError :: MessageNotFound (
110+ e. to_string ( ) ,
111+ ) ) ) ;
112+ }
113+ } ;
114+ if let Some ( msg_number) = thread_message. message_number {
115+ message_number = msg_number;
116+ } else {
117+ return Err ( ModmailError :: Message ( MessageError :: MessageNotFound (
118+ "" . to_string ( ) ,
119+ ) ) ) ;
120+ }
121+ } else {
122+ return Err ( ModmailError :: Message ( MessageError :: MessageNotFound (
123+ "" . to_string ( ) ,
124+ ) ) ) ;
125+ }
101126 }
102127
103128 let message_ids = get_message_ids ( user_id, & thread, message_number, pool) . await ?;
0 commit comments