Skip to content

Commit 27a4955

Browse files
committed
refactor(message_builder): add method to save command interaction messages
1 parent d8b1808 commit 27a4955

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

rustmail/src/utils/message/message_builder.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,48 @@ impl<'a> MessageBuilder<'a> {
587587
eprintln!("Failed to send message: {}", e);
588588
}
589589
}
590+
591+
pub async fn send_interaction_followup(
592+
self,
593+
command: &CommandInteraction,
594+
to_be_recorded: bool,
595+
) -> Result<Message, ModmailError> {
596+
let pool = match &self.config.db_pool {
597+
Some(pool) => pool,
598+
None => {
599+
return Err(ModmailError::Database(DatabaseError::ConnectionFailed));
600+
}
601+
};
602+
603+
let response = self.build_interaction_message_followup().await;
604+
605+
let message = command
606+
.create_followup(&self.ctx.http, response)
607+
.await
608+
.map_err(ModmailError::from)?;
609+
610+
if to_be_recorded {
611+
let thread_id = get_thread_by_channel_id(&command.channel_id.to_string(), pool)
612+
.await
613+
.map(|t| t.id)
614+
.unwrap_or_default();
615+
616+
let _ = insert_staff_message(
617+
self.ctx,
618+
&message,
619+
None,
620+
&thread_id,
621+
self.bot_user_id,
622+
false,
623+
pool,
624+
self.config,
625+
None,
626+
)
627+
.await;
628+
}
629+
630+
Ok(message)
631+
}
590632
}
591633

592634
impl<'a> MessageBuilder<'a> {

0 commit comments

Comments
 (0)