This repository has been archived on 2025-06-26. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
l1l1th-old/src/commands/accessibility/describe.js
Ashley Graves 2eaadf2208 booru
2024-10-10 08:34:00 +02:00

65 lines
No EOL
1.9 KiB
JavaScript

const { ContextMenuCommandBuilder, ApplicationCommandType, InteractionContextType, ApplicationIntegrationType, AttachmentBuilder, EmbedBuilder } = require("discord.js");
const data = new ContextMenuCommandBuilder()
.setName("Describe Image(s)")
.setType(ApplicationCommandType.Message)
.setContexts([
InteractionContextType.Guild,
InteractionContextType.BotDM,
InteractionContextType.PrivateChannel
])
.setIntegrationTypes([
ApplicationIntegrationType.GuildInstall,
ApplicationIntegrationType.UserInstall
]);
module.exports = {
data,
async execute(interaction) {
await interaction.deferReply();
const groq = interaction.client.groq;
const message = interaction.targetMessage;
const attachments = message.attachments;
const files = [];
const embeds = [];
for (const att of attachments) {
const attachment = att[1];
if (!attachment.contentType.startsWith("image/")) {
console.log(attachment.contentType);
continue;
}
const name = attachment.name.substr(0, attachment.name.lastIndexOf("."));
const description = (await groq.chat.completions.create({
messages: [{
"role": "user",
"content": [{
"type": "text",
"text": interaction.client.prompts.image
}, {
"type": "image_url",
"image_url": {
"url": attachment.attachment
}
}]
}],
"model": "llama-3.2-11b-vision-preview"
})).choices[0].message.content.trim();
if (description.length < 2000) {
const embed = new EmbedBuilder()
.setTitle(attachment.name)
.setDescription(description);
embeds.push(embed);
} else {
files.push(new AttachmentBuilder()
.setName(name + ".md")
.setFile(Buffer.from(description, "utf-8")));
}
}
await interaction.followUp({ embeds, files });
},
};