APRK01 commited on
Commit Β·
81f0e16
1
Parent(s): fbe00fc
feat: add image attachment support to mass drop system
Browse files- src/systems/massdrop.js +49 -9
src/systems/massdrop.js
CHANGED
|
@@ -168,17 +168,37 @@ async function handleMassDropMessage(message) {
|
|
| 168 |
else if (session.step === 'listening') {
|
| 169 |
// Collect any attachments dropped
|
| 170 |
if (message.attachments.size > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
message.attachments.forEach(attachment => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
session.files.push({
|
| 173 |
-
title:
|
| 174 |
-
name:
|
| 175 |
-
url:
|
| 176 |
-
size:
|
| 177 |
description: session.config.about,
|
| 178 |
status: session.config.status,
|
| 179 |
-
isExternal: false
|
|
|
|
| 180 |
});
|
| 181 |
-
}
|
| 182 |
|
| 183 |
// Brief confirmation logic
|
| 184 |
await message.react('β
').catch(() => { });
|
|
@@ -254,7 +274,7 @@ async function handleMassDropMessage(message) {
|
|
| 254 |
status: fileConf.status,
|
| 255 |
about: fileConf.description,
|
| 256 |
file: fileConf,
|
| 257 |
-
image:
|
| 258 |
});
|
| 259 |
|
| 260 |
const finalRow = new ActionRowBuilder().addComponents(
|
|
@@ -264,10 +284,30 @@ async function handleMassDropMessage(message) {
|
|
| 264 |
.setURL(permanentUrl)
|
| 265 |
);
|
| 266 |
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
embeds: [finalEmbed],
|
| 269 |
components: [finalRow]
|
| 270 |
-
}
|
|
|
|
|
|
|
|
|
|
| 271 |
|
| 272 |
successCount++;
|
| 273 |
stmts.logDrop.run(userId, fileConf.title, channelId);
|
|
|
|
| 168 |
else if (session.step === 'listening') {
|
| 169 |
// Collect any attachments dropped
|
| 170 |
if (message.attachments.size > 0) {
|
| 171 |
+
// First, see if there's a main file and an image file in this single message
|
| 172 |
+
let mainFile = null;
|
| 173 |
+
let imageFile = null;
|
| 174 |
+
|
| 175 |
message.attachments.forEach(attachment => {
|
| 176 |
+
const type = attachment.contentType || '';
|
| 177 |
+
if (type.startsWith('image/')) {
|
| 178 |
+
if (!imageFile) imageFile = attachment;
|
| 179 |
+
} else {
|
| 180 |
+
if (!mainFile) mainFile = attachment;
|
| 181 |
+
}
|
| 182 |
+
});
|
| 183 |
+
|
| 184 |
+
// If there's NO main file, but there IS an image, treat the image AS the main file
|
| 185 |
+
if (!mainFile && imageFile) {
|
| 186 |
+
mainFile = imageFile;
|
| 187 |
+
imageFile = null;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
if (mainFile) {
|
| 191 |
session.files.push({
|
| 192 |
+
title: mainFile.name,
|
| 193 |
+
name: mainFile.name,
|
| 194 |
+
url: mainFile.url,
|
| 195 |
+
size: mainFile.size,
|
| 196 |
description: session.config.about,
|
| 197 |
status: session.config.status,
|
| 198 |
+
isExternal: false,
|
| 199 |
+
imageUrl: imageFile ? imageFile.url : null
|
| 200 |
});
|
| 201 |
+
}
|
| 202 |
|
| 203 |
// Brief confirmation logic
|
| 204 |
await message.react('β
').catch(() => { });
|
|
|
|
| 274 |
status: fileConf.status,
|
| 275 |
about: fileConf.description,
|
| 276 |
file: fileConf,
|
| 277 |
+
image: fileConf.imageUrl ? { url: fileConf.imageUrl } : null
|
| 278 |
});
|
| 279 |
|
| 280 |
const finalRow = new ActionRowBuilder().addComponents(
|
|
|
|
| 284 |
.setURL(permanentUrl)
|
| 285 |
);
|
| 286 |
|
| 287 |
+
const filesToUpload = [];
|
| 288 |
+
if (fileConf.imageUrl) {
|
| 289 |
+
try {
|
| 290 |
+
const { AttachmentBuilder } = require('discord.js');
|
| 291 |
+
const imageRes = await fetch(fileConf.imageUrl);
|
| 292 |
+
const imageBuffer = await imageRes.buffer();
|
| 293 |
+
// We name it something generic so Discord picks it up as a raw image to render
|
| 294 |
+
const previewImage = new AttachmentBuilder(imageBuffer, { name: 'preview.png' });
|
| 295 |
+
filesToUpload.push(previewImage);
|
| 296 |
+
|
| 297 |
+
// The embed builder expects the image URL to match the attachment protocol
|
| 298 |
+
finalEmbed.setImage('attachment://preview.png');
|
| 299 |
+
} catch (imgErr) {
|
| 300 |
+
console.error('Failed to attach preview image to mass drop:', imgErr);
|
| 301 |
+
}
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
const messagePayload = {
|
| 305 |
embeds: [finalEmbed],
|
| 306 |
components: [finalRow]
|
| 307 |
+
};
|
| 308 |
+
if (filesToUpload.length > 0) messagePayload.files = filesToUpload;
|
| 309 |
+
|
| 310 |
+
await channel.send(messagePayload);
|
| 311 |
|
| 312 |
successCount++;
|
| 313 |
stmts.logDrop.run(userId, fileConf.title, channelId);
|