Skip to content

Commit 24ebaa2

Browse files
authored
Merge pull request #286 from Rustmail/215-register-commandinteraction-message-in-db
fix(commands): register commandinteraction message in db
2 parents d8b1808 + 744bd0d commit 24ebaa2

21 files changed

Lines changed: 146 additions & 186 deletions

File tree

rustmail/src/commands/add_reminder/common.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub async fn send_register_confirmation_from_command(
7979
}
8080

8181
if !reminder_content.is_empty() {
82-
let response = MessageBuilder::system_message(&ctx, &config)
82+
let _ = MessageBuilder::system_message(&ctx, &config)
8383
.translated_content(
8484
"reminder.registered_with_content",
8585
Some(&params),
@@ -89,12 +89,10 @@ pub async fn send_register_confirmation_from_command(
8989
.await
9090
.to_channel(command.channel_id)
9191
.footer(format!("{}: {}", "ID", reminder_id))
92-
.build_interaction_message_followup()
92+
.send_interaction_followup(&command, true)
9393
.await;
94-
95-
let _ = command.create_followup(&ctx.http, response).await;
9694
} else {
97-
let response = MessageBuilder::system_message(&ctx, &config)
95+
let _ = MessageBuilder::system_message(&ctx, &config)
9896
.translated_content(
9997
"reminder.registered_without_content",
10098
Some(&params),
@@ -104,10 +102,8 @@ pub async fn send_register_confirmation_from_command(
104102
.await
105103
.to_channel(command.channel_id)
106104
.footer(format!("{}: {}", "ID", reminder_id))
107-
.build_interaction_message_followup()
105+
.send_interaction_followup(&command, true)
108106
.await;
109-
110-
let _ = command.create_followup(&ctx.http, response).await;
111107
}
112108
}
113109

rustmail/src/commands/add_staff/slash_command/add_staff.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,13 @@ impl RegistrableCommand for AddStaffCommand {
111111
let mut params = HashMap::new();
112112
params.insert("user".to_string(), format!("<@{}>", user_id));
113113

114-
let response = MessageBuilder::system_message(&ctx, &config)
114+
let _ = MessageBuilder::system_message(&ctx, &config)
115115
.translated_content("add_staff.add_success", Some(&params), None, None)
116116
.await
117117
.to_channel(command.channel_id)
118-
.build_interaction_message_followup()
118+
.send_interaction_followup(&command, true)
119119
.await;
120120

121-
let _ = command.create_followup(&ctx.http, response).await;
122-
123121
Ok(())
124122
}
125123
Err(..) => Err(ModmailError::Command(CommandError::InvalidFormat)),

rustmail/src/commands/alert/common.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub async fn handle_cancel_alert_from_command(
101101
let mut params = HashMap::new();
102102
params.insert("user".to_string(), format!("<@{}>", user_id));
103103

104-
let response = MessageBuilder::system_message(ctx, config)
104+
let _ = MessageBuilder::system_message(ctx, config)
105105
.translated_content(
106106
"alert.cancel_confirmation",
107107
Some(&params),
@@ -110,11 +110,9 @@ pub async fn handle_cancel_alert_from_command(
110110
)
111111
.await
112112
.to_channel(command.channel_id)
113-
.build_interaction_message_followup()
113+
.send_interaction_followup(command, true)
114114
.await;
115115

116-
let _ = command.create_followup(&ctx.http, response).await;
117-
118116
Ok(())
119117
}
120118
}
@@ -163,7 +161,7 @@ pub async fn handle_set_alert_from_command(
163161
let mut params = HashMap::new();
164162
params.insert("user".to_string(), format!("<@{}>", user_id));
165163

166-
let response = MessageBuilder::system_message(ctx, config)
164+
let _ = MessageBuilder::system_message(ctx, config)
167165
.translated_content(
168166
"alert.confirmation",
169167
Some(&params),
@@ -172,11 +170,9 @@ pub async fn handle_set_alert_from_command(
172170
)
173171
.await
174172
.to_channel(command.channel_id)
175-
.build_interaction_message_followup()
173+
.send_interaction_followup(command, true)
176174
.await;
177175

178-
let _ = command.create_followup(&ctx.http, response).await;
179-
180176
Ok(())
181177
}
182178
}

rustmail/src/commands/close/slash_command/close.rs

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl RegistrableCommand for CloseCommand {
156156
.await
157157
.unwrap_or(false);
158158
return if existed {
159-
let response = MessageBuilder::system_message(&ctx, &config)
159+
let _ = MessageBuilder::system_message(&ctx, &config)
160160
.translated_content(
161161
"close.closure_canceled",
162162
None,
@@ -165,10 +165,8 @@ impl RegistrableCommand for CloseCommand {
165165
)
166166
.await
167167
.to_channel(command.channel_id)
168-
.build_interaction_message_followup()
168+
.send_interaction_followup(&command, true)
169169
.await;
170-
171-
let _ = command.create_followup(&ctx.http, response).await;
172170
Ok(())
173171
} else {
174172
Err(ModmailError::Command(
@@ -199,7 +197,7 @@ impl RegistrableCommand for CloseCommand {
199197
let mut warn_params = HashMap::new();
200198
warn_params.insert("old_time".to_string(), old_human);
201199

202-
let response = MessageBuilder::system_message(&ctx, &config)
200+
let _ = MessageBuilder::system_message(&ctx, &config)
203201
.translated_content(
204202
"close.replacing_existing_closure",
205203
Some(&warn_params),
@@ -208,10 +206,8 @@ impl RegistrableCommand for CloseCommand {
208206
)
209207
.await
210208
.to_channel(command.channel_id)
211-
.build_interaction_message_followup()
209+
.send_interaction_followup(&command, true)
212210
.await;
213-
214-
let _ = command.create_followup(&ctx.http, response).await;
215211
}
216212
}
217213

@@ -220,36 +216,24 @@ impl RegistrableCommand for CloseCommand {
220216
let mut params = HashMap::new();
221217
params.insert("time".to_string(), human);
222218

223-
let _ = if silent {
224-
let response = MessageBuilder::system_message(&ctx, &config)
225-
.translated_content(
226-
"close.silent_closing",
227-
Some(&params),
228-
Some(command.user.id),
229-
command.guild_id.map(|g| g.get()),
230-
)
231-
.await
232-
.to_channel(command.channel_id)
233-
.build_interaction_message_followup()
234-
.await;
235-
236-
command.create_followup(&ctx.http, response).await
219+
let close_key = if silent {
220+
"close.silent_closing"
237221
} else {
238-
let response = MessageBuilder::system_message(&ctx, &config)
239-
.translated_content(
240-
"close.closing",
241-
Some(&params),
242-
Some(command.user.id),
243-
command.guild_id.map(|g| g.get()),
244-
)
245-
.await
246-
.to_channel(command.channel_id)
247-
.build_interaction_message_followup()
248-
.await;
249-
250-
command.create_followup(&ctx.http, response).await
222+
"close.closing"
251223
};
252224

225+
let _ = MessageBuilder::system_message(&ctx, &config)
226+
.translated_content(
227+
close_key,
228+
Some(&params),
229+
Some(command.user.id),
230+
command.guild_id.map(|g| g.get()),
231+
)
232+
.await
233+
.to_channel(command.channel_id)
234+
.send_interaction_followup(&command, true)
235+
.await;
236+
253237
let closed_by = command.user.id.to_string();
254238

255239
let (category_id, category_name, required_permissions) =
@@ -336,7 +320,7 @@ impl RegistrableCommand for CloseCommand {
336320
let mut params = HashMap::new();
337321
params.insert("username".to_string(), thread.user_name.clone());
338322

339-
let response = MessageBuilder::system_message(&ctx, &config)
323+
let _ = MessageBuilder::system_message(&ctx, &config)
340324
.translated_content(
341325
"user.left_server_close",
342326
Some(&params),
@@ -345,10 +329,8 @@ impl RegistrableCommand for CloseCommand {
345329
)
346330
.await
347331
.to_channel(command.channel_id)
348-
.build_interaction_message_followup()
332+
.send_interaction_followup(&command, true)
349333
.await;
350-
351-
let _ = command.create_followup(&ctx.http, response).await;
352334
}
353335

354336
close_thread(

rustmail/src/commands/delete/slash_command/delete.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,14 @@ impl RegistrableCommand for DeleteCommand {
139139
let mut params = HashMap::new();
140140
params.insert("number".to_string(), message_number.to_string());
141141

142-
let response = MessageBuilder::system_message(&ctx, &config)
142+
let _ = MessageBuilder::system_message(&ctx, &config)
143143
.translated_content("delete.success", Some(&params), None, None)
144144
.await
145145
.to_channel(command.channel_id)
146146
.ephemeral(true)
147-
.build_interaction_message_followup()
147+
.send_interaction_followup(&command, true)
148148
.await;
149149

150-
let _ = command.create_followup(&ctx.http, response).await;
151-
152150
Ok(())
153151
})
154152
}

rustmail/src/commands/edit/slash_command/edit.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl RegistrableCommand for EditCommand {
178178
match edit_result {
179179
Ok(()) => {
180180
if config.notifications.show_success_on_edit {
181-
let response = MessageBuilder::system_message(&ctx, &config)
181+
let _ = MessageBuilder::system_message(&ctx, &config)
182182
.translated_content(
183183
"success.message_edited",
184184
None,
@@ -188,10 +188,8 @@ impl RegistrableCommand for EditCommand {
188188
.await
189189
.color(hex_string_to_int(&config.thread.system_message_color) as u32)
190190
.to_channel(command.channel_id)
191-
.build_interaction_message_followup()
191+
.send_interaction_followup(&command, true)
192192
.await;
193-
194-
let _ = command.create_followup(&ctx.http, response).await;
195193
};
196194

197195
if config.logs.show_log_on_edit {
@@ -214,7 +212,7 @@ impl RegistrableCommand for EditCommand {
214212
params.insert("after".to_string(), format!("`{}`", new_content.clone()));
215213
params.insert("link".to_string(), message_link);
216214

217-
let response = MessageBuilder::system_message(&ctx, &config)
215+
let _ = MessageBuilder::system_message(&ctx, &config)
218216
.translated_content(
219217
"edit.modification_from_staff",
220218
Some(&params),
@@ -223,10 +221,8 @@ impl RegistrableCommand for EditCommand {
223221
)
224222
.await
225223
.to_channel(command.channel_id)
226-
.build_interaction_message_followup()
224+
.send_interaction_followup(&command, true)
227225
.await;
228-
229-
let _ = command.create_followup(&ctx.http, response).await;
230226
}
231227

232228
match update_message_content(&dm_msg_id, &new_content, pool).await {

rustmail/src/commands/force_close/slash_command/force_close.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ impl RegistrableCommand for ForceCloseCommand {
5959
.as_ref()
6060
.ok_or_else(database_connection_failed)?;
6161

62+
defer_response(&ctx, &command).await?;
63+
6264
if !is_a_ticket_channel(command.channel_id, db_pool).await {
6365
match command.channel_id.to_channel(&ctx.http).await {
6466
Ok(channel) => {
@@ -119,7 +121,7 @@ impl RegistrableCommand for ForceCloseCommand {
119121
)
120122
.await
121123
.to_channel(serenity::all::ChannelId::new(logs_channel_id))
122-
.send(true)
124+
.send_interaction_followup(&command, true)
123125
.await;
124126
}
125127
}

rustmail/src/commands/help/common.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ pub async fn display_commands_list(
3333
}
3434

3535
if let Some(command) = command {
36-
let response = MessageBuilder::system_message(&ctx, config)
36+
let _ = MessageBuilder::system_message(&ctx, config)
3737
.content(docs_message)
3838
.to_channel(command.channel_id)
39-
.build_interaction_message_followup()
39+
.send_interaction_followup(&command, true)
4040
.await;
4141

42-
command.create_followup(&ctx.http, response).await?;
43-
4442
return Ok(());
4543
}
4644

@@ -73,13 +71,12 @@ pub async fn display_command_help(
7371
}
7472

7573
if let Some(command) = command {
76-
let response = MessageBuilder::system_message(&ctx, config)
74+
let _ = MessageBuilder::system_message(&ctx, config)
7775
.content(docs_message)
7876
.to_channel(command.channel_id)
79-
.build_interaction_message_followup()
77+
.send_interaction_followup(&command, true)
8078
.await;
8179

82-
command.create_followup(&ctx.http, response).await?;
8380
return Ok(());
8481
}
8582

rustmail/src/commands/id/slash_command/id.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,13 @@ impl RegistrableCommand for IdCommand {
8282
format!("||{}||", thread.user_id.to_string()),
8383
);
8484

85-
let response = MessageBuilder::system_message(&ctx, &config)
85+
let _ = MessageBuilder::system_message(&ctx, &config)
8686
.translated_content("id.show_id", Some(&params), None, None)
8787
.await
8888
.to_channel(command.channel_id)
89-
.build_interaction_message_followup()
89+
.send_interaction_followup(&command, true)
9090
.await;
9191

92-
let _ = command.create_followup(&ctx.http, response).await;
93-
9492
Ok(())
9593
})
9694
}

rustmail/src/commands/logs/common.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,12 @@ pub async fn get_response(
8686
if !command.is_none() {
8787
let command = command.unwrap();
8888

89-
let response = MessageBuilder::system_message(&ctx.clone(), &config.clone())
89+
MessageBuilder::system_message(&ctx.clone(), &config.clone())
9090
.content(content)
9191
.components(components)
9292
.to_channel(channel_id)
93-
.build_interaction_message_followup()
94-
.await;
95-
96-
let tkt = command.create_followup(&ctx.http, response).await;
97-
98-
Ok(tkt?)
93+
.send_interaction_followup(&command, true)
94+
.await
9995
} else {
10096
MessageBuilder::system_message(&ctx, &config)
10197
.content(content)

0 commit comments

Comments
 (0)