Skip to content

Commit b771e83

Browse files
committed
fix(thread): add warning when attachments are too big
1 parent 097cae0 commit b771e83

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

rustmail/src/handlers/guild_messages_handler.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,26 @@ async fn manage_incoming_message(
143143

144144
let channel_id = ChannelId::new(channel_id_num);
145145

146+
const MAX_ATTACHMENT_SIZE: u32 = 8 * 1024 * 1024;
147+
for attachment in &msg.attachments {
148+
if attachment.size > MAX_ATTACHMENT_SIZE {
149+
let _ = MessageBuilder::system_message(ctx, config)
150+
.translated_content(
151+
"discord.attachment_too_large",
152+
None,
153+
Some(msg.author.id),
154+
None,
155+
)
156+
.await
157+
.to_user(msg.author.id)
158+
.send(true)
159+
.await;
160+
161+
drop(guard);
162+
return Ok(());
163+
}
164+
}
165+
146166
if let Err(e) = send_to_thread(ctx, channel_id, msg, config, false).await {
147167
let error = validation_failed(&format!("Failed to forward message: {}", e));
148168
let _ = error_handler

rustmail/src/i18n/language/en.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ pub fn load_english_messages(dict: &mut ErrorDictionary) {
4343
DictionaryMessage::new("Discord API error")
4444
.with_description("An error occurred while communicating with Discord"),
4545
);
46+
dict.messages.insert(
47+
"discord.attachment_too_large".to_string(),
48+
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."),
49+
);
4650
dict.messages.insert(
4751
"discord.user_is_a_bot".to_string(),
4852
DictionaryMessage::new("The specified user is a rustmail."),

rustmail/src/i18n/language/fr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub fn load_french_messages(dict: &mut ErrorDictionary) {
4141
DictionaryMessage::new("Erreur de l'API Discord")
4242
.with_description("Une erreur s'est produite lors de la communication avec Discord"),
4343
);
44+
dict.messages.insert(
45+
"discord.attachment_too_large".to_string(),
46+
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."),
47+
);
4448
dict.messages.insert(
4549
"discord.user_is_a_bot".to_string(),
4650
DictionaryMessage::new("L'utilisateur spécifié est un rustmail"),

rustmail/src/modules/threads.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ pub async fn create_channel(ctx: &Context, msg: &Message, config: &Config) {
140140
return;
141141
}
142142

143+
const MAX_ATTACHMENT_SIZE: u32 = 8 * 1024 * 1024;
144+
for attachment in &msg.attachments {
145+
if attachment.size > MAX_ATTACHMENT_SIZE {
146+
let _ = MessageBuilder::system_message(ctx, config)
147+
.translated_content(
148+
"discord.attachment_too_large",
149+
None,
150+
Some(msg.author.id),
151+
None,
152+
)
153+
.await
154+
.to_user(msg.author.id)
155+
.send(true)
156+
.await;
157+
158+
return;
159+
}
160+
}
161+
143162
let (target_channel_id, _is_new_thread) =
144163
match create_or_get_thread_for_user(ctx, config, msg.author.id).await {
145164
Ok(res) => res,

0 commit comments

Comments
 (0)