tdoss: Pull the latest image in chat if none are provided
All checks were successful
CI / CI (push) Successful in 1m27s

limited to 20 last messages for now
This commit is contained in:
SileNce5k 2025-04-12 03:20:18 +02:00
parent 7dc9be5598
commit 6f8dd7ebf6
Signed by: SileNce
GPG key ID: B0A142BB4291B204

View file

@ -32,10 +32,16 @@ module.exports = {
} }
} }
else { else {
message.channel.send("You have to provide an image to use this command.\nEither through an attachment, a link, or you can reply to a message with an image attachment.") let lastMessages = await message.channel.messages.fetch({limit: 20, cache: false});
let lastMessageWithAttachment = lastMessages.find(m => m.attachments.size > 0);
if(!lastMessageWithAttachment){
message.channel.send("Couldn't find an image to use this command on.")
fs.rmSync(`${directory}`, {recursive: true}) fs.rmSync(`${directory}`, {recursive: true})
return return
} }
url = lastMessageWithAttachment.attachments.first().url;
}
// TODO: Download with correct extension. // TODO: Download with correct extension.
message.channel.sendTyping(); message.channel.sendTyping();
if(await this.downloadImage(url, path.resolve(directory, "input.png")) != 0){ if(await this.downloadImage(url, path.resolve(directory, "input.png")) != 0){