@@ -7,19 +7,14 @@ use serenity::all::{CommandInteraction, Context, CreateInteractionResponse, Mess
77use std:: collections:: HashMap ;
88
99pub async fn get_thread_user_id_from_msg (
10- ctx : & Context ,
1110 msg : & Message ,
12- config : & Config ,
1311 pool : & sqlx:: SqlitePool ,
1412) -> ModmailResult < i64 > {
1513 let channel_id = msg. channel_id . to_string ( ) ;
1614
1715 match get_user_id_from_channel_id ( & channel_id, pool) . await {
1816 Some ( uid) => Ok ( uid) ,
19- None => {
20- send_alert_message ( ctx, msg, config, "alert.not_in_thread" , None ) . await ;
21- Err ( common:: validation_failed ( "Not in a thread" ) )
22- }
17+ None => Err ( ModmailError :: Command ( CommandError :: NotInThread ( ) ) ) ,
2318 }
2419}
2520
@@ -78,7 +73,18 @@ pub async fn handle_cancel_alert_from_msg(
7873 let mut params = HashMap :: new ( ) ;
7974 params. insert ( "user" . to_string ( ) , format ! ( "<@{}>" , user_id) ) ;
8075
81- send_alert_message ( ctx, msg, config, "alert.cancel_confirmation" , Some ( & params) ) . await ;
76+ let _ = MessageBuilder :: system_message ( ctx, config)
77+ . translated_content (
78+ "alert.cancel_confirmation" ,
79+ Some ( & params) ,
80+ Some ( msg. author . id ) ,
81+ msg. guild_id . map ( |g| g. get ( ) ) ,
82+ )
83+ . await
84+ . to_channel ( msg. channel_id )
85+ . send ( true )
86+ . await ;
87+
8288 Ok ( ( ) )
8389}
8490
@@ -120,15 +126,25 @@ pub async fn handle_set_alert_from_msg(
120126 user_id : i64 ,
121127 pool : & sqlx:: SqlitePool ,
122128) -> ModmailResult < ( ) > {
123- if let Err ( e) = set_alert_for_staff ( msg. author . id , user_id, pool) . await {
124- send_alert_message ( ctx, msg, config, "alert.set_failed" , None ) . await ;
125- return Ok ( ( ) ) ;
129+ if let Err ( ..) = set_alert_for_staff ( msg. author . id , user_id, pool) . await {
130+ return Err ( ModmailError :: Command ( CommandError :: AlertSetFailed ) ) ;
126131 }
127132
128133 let mut params = HashMap :: new ( ) ;
129134 params. insert ( "user" . to_string ( ) , format ! ( "<@{}>" , user_id) ) ;
130135
131- send_alert_message ( ctx, msg, config, "alert.confirmation" , Some ( & params) ) . await ;
136+ let _ = MessageBuilder :: system_message ( ctx, config)
137+ . translated_content (
138+ "alert.confirmation" ,
139+ Some ( & params) ,
140+ Some ( msg. author . id ) ,
141+ msg. guild_id . map ( |g| g. get ( ) ) ,
142+ )
143+ . await
144+ . to_channel ( msg. channel_id )
145+ . send ( true )
146+ . await ;
147+
132148 Ok ( ( ) )
133149}
134150
@@ -165,26 +181,6 @@ pub async fn handle_set_alert_from_command(
165181 }
166182}
167183
168- pub async fn send_alert_message (
169- ctx : & Context ,
170- msg : & Message ,
171- config : & Config ,
172- message_key : & str ,
173- params : Option < & HashMap < String , String > > ,
174- ) {
175- let _ = MessageBuilder :: system_message ( ctx, config)
176- . translated_content (
177- message_key,
178- params,
179- Some ( msg. author . id ) ,
180- msg. guild_id . map ( |g| g. get ( ) ) ,
181- )
182- . await
183- . to_channel ( msg. channel_id )
184- . send ( true )
185- . await ;
186- }
187-
188184pub async fn extract_alert_action ( msg : & Message , config : & Config ) -> bool {
189185 let content = msg. content . trim ( ) ;
190186 let prefix = & config. command . prefix ;
0 commit comments