Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions rustmail/src/handlers/guild_messages_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ async fn manage_incoming_message(

let channel_id = ChannelId::new(channel_id_num);

const MAX_ATTACHMENT_SIZE: u32 = 8 * 1024 * 1024;
for attachment in &msg.attachments {
if attachment.size > MAX_ATTACHMENT_SIZE {
let _ = MessageBuilder::system_message(ctx, config)
.translated_content(
"discord.attachment_too_large",
None,
Some(msg.author.id),
None,
)
.await
.to_user(msg.author.id)
.send(true)
.await;

drop(guard);
return Ok(());
}
}

if let Err(e) = send_to_thread(ctx, channel_id, msg, config, false).await {
let error = validation_failed(&format!("Failed to forward message: {}", e));
let _ = error_handler
Expand Down
4 changes: 4 additions & 0 deletions rustmail/src/i18n/language/en.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ pub fn load_english_messages(dict: &mut ErrorDictionary) {
DictionaryMessage::new("Discord API error")
.with_description("An error occurred while communicating with Discord"),
);
dict.messages.insert(
"discord.attachment_too_large".to_string(),
DictionaryMessage::new("Your attachment is too large! Discord has a file size limit of 8 MB for attachments. Please reduce the file size or send a link."),
);
dict.messages.insert(
"discord.user_is_a_bot".to_string(),
DictionaryMessage::new("The specified user is a rustmail."),
Expand Down
4 changes: 4 additions & 0 deletions rustmail/src/i18n/language/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ pub fn load_french_messages(dict: &mut ErrorDictionary) {
DictionaryMessage::new("Erreur de l'API Discord")
.with_description("Une erreur s'est produite lors de la communication avec Discord"),
);
dict.messages.insert(
"discord.attachment_too_large".to_string(),
DictionaryMessage::new("Votre pièce jointe est trop volumineuse ! Discord a une limite de taille de fichier de 8 Mo pour les pièces jointes. Veuillez réduire la taille du fichier ou envoyer un lien."),
);
dict.messages.insert(
"discord.user_is_a_bot".to_string(),
DictionaryMessage::new("L'utilisateur spécifié est un rustmail"),
Expand Down
19 changes: 19 additions & 0 deletions rustmail/src/modules/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ pub async fn create_channel(ctx: &Context, msg: &Message, config: &Config) {
return;
}

const MAX_ATTACHMENT_SIZE: u32 = 8 * 1024 * 1024;
for attachment in &msg.attachments {
if attachment.size > MAX_ATTACHMENT_SIZE {
let _ = MessageBuilder::system_message(ctx, config)
.translated_content(
"discord.attachment_too_large",
None,
Some(msg.author.id),
None,
)
.await
.to_user(msg.author.id)
.send(true)
.await;

return;
}
}

let (target_channel_id, _is_new_thread) =
match create_or_get_thread_for_user(ctx, config, msg.author.id).await {
Ok(res) => res,
Expand Down