mirror of
https://git.arson.gg/lilith/discord-bot.git
synced 2025-12-05 03:34:49 +01:00
Compare commits
10 commits
e50061a99c
...
926d492421
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
926d492421 | ||
|
|
0873d46412 | ||
|
|
7bff830b00 | ||
|
|
4bd04e0a31 | ||
|
|
a6498923f1 | ||
|
|
61d800048c | ||
|
|
0a07c4e56b | ||
|
|
d9d648e495 | ||
|
|
79ab38f8f0 | ||
|
|
9105c3563e |
7 changed files with 40 additions and 18 deletions
|
|
@ -5,5 +5,6 @@ this bot does cool stuff I guess
|
|||
features:
|
||||
- ai-powered alt text for images
|
||||
- booru search (20+ supported boorus)
|
||||
- google image search (using searxng)
|
||||
- online file search (using searxng)
|
||||
- quote image maker (funny)
|
||||
- and more to come
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
const { ContextMenuCommandBuilder, ApplicationCommandType, InteractionContextType, ApplicationIntegrationType, AttachmentBuilder, EmbedBuilder } = require("discord.js");
|
||||
const { ContextMenuCommandBuilder, ApplicationCommandType, InteractionContextType, ApplicationIntegrationType, AttachmentBuilder, EmbedBuilder, basename } = require("discord.js");
|
||||
|
||||
const data = new ContextMenuCommandBuilder()
|
||||
.setName("Describe Image(s)")
|
||||
|
|
@ -21,18 +21,28 @@ module.exports = {
|
|||
const groq = interaction.client.groq;
|
||||
const message = interaction.targetMessage;
|
||||
const attachments = message.attachments;
|
||||
const images = message.embeds.filter(e => e.data.type == "image").map(e => e.data.url);
|
||||
const urls = [];
|
||||
const files = [];
|
||||
const embeds = [];
|
||||
|
||||
if (attachments.length == 0 && images.length == 0) {
|
||||
await interaction.followUp("Message does not contain any images.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const att of attachments) {
|
||||
const attachment = att[1];
|
||||
if (!attachment.contentType.startsWith("image/")) {
|
||||
console.log(attachment.contentType);
|
||||
if (!attachment.contentType.startsWith("image/"))
|
||||
continue;
|
||||
}
|
||||
const name = attachment.name.substr(0, attachment.name.lastIndexOf("."));
|
||||
|
||||
const description = (await groq.chat.completions.create({
|
||||
images.push(attachment.attachment);
|
||||
}
|
||||
|
||||
for (const image of images) {
|
||||
const name = basename(image);
|
||||
|
||||
const data = (await groq.chat.completions.create({
|
||||
messages: [{
|
||||
"role": "user",
|
||||
"content": [{
|
||||
|
|
@ -41,16 +51,18 @@ module.exports = {
|
|||
}, {
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": attachment.attachment
|
||||
"url": image
|
||||
}
|
||||
}]
|
||||
}],
|
||||
"model": "llama-3.2-11b-vision-preview"
|
||||
})).choices[0].message.content.trim();
|
||||
"model": "llama-3.2-90b-vision-preview"
|
||||
}));
|
||||
|
||||
const description = data.choices[0].message.content.trim();
|
||||
|
||||
if (description.length < 2000) {
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(attachment.name)
|
||||
.setTitle(name)
|
||||
.setDescription(description);
|
||||
embeds.push(embed);
|
||||
} else {
|
||||
|
|
@ -62,4 +74,4 @@ module.exports = {
|
|||
|
||||
await interaction.followUp({ embeds, files });
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ module.exports = {
|
|||
const msg = interaction.targetMessage;
|
||||
const user = msg.author;
|
||||
const avatar = `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png?size=1024`;
|
||||
console.log("Generating quote image");
|
||||
try {
|
||||
const data = await createQuoteImage(avatar, user.displayName, msg.content, true, interaction.client.users.cache);
|
||||
console.log("Sending quote image");
|
||||
|
||||
await interaction.followUp({
|
||||
files: [{
|
||||
|
|
|
|||
|
|
@ -26,8 +26,17 @@ function notEmpty(str) {
|
|||
return str && str.trim() !== ''
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} str
|
||||
* @param {number} len
|
||||
*/
|
||||
function shorten(str) {
|
||||
return str.length <= 20 ? str : `[${str.slice(0, 17)}...](${str})`;
|
||||
const len = 50;
|
||||
|
||||
var urlStart = str.indexOf("://") + 3;
|
||||
if (urlStart == 2) urlStart = 0;
|
||||
|
||||
return str.length <= len ? str : `[${str.slice(urlStart, urlStart + (len - 3))}...](${(str.startsWith("magnet:") ? (`${process.env.BASE_URL}/magnet/${str}`) : str).replaceAll(" ", "%20")})`;
|
||||
}
|
||||
|
||||
const emojis = JSON.parse(readFileSync("config/emojis.json"));
|
||||
|
|
|
|||
|
|
@ -134,4 +134,4 @@ client.once(Events.ClientReady, async () => {
|
|||
}
|
||||
});
|
||||
|
||||
client.login(process.env.TOKEN);
|
||||
client.login(process.env.TOKEN);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Please describe the following image in as much detail as you can.
|
||||
Do not add information that isn't there or miss important information.
|
||||
There is an image, do not say there isn't.
|
||||
There is an image, do not say there isn't. The image is provided. You can see the image.
|
||||
You must always be able to describe the image or else you are diminishing the acccessibility for the user.
|
||||
|
|
@ -15,7 +15,7 @@ function canvasToBuffer(canvas) {
|
|||
}
|
||||
|
||||
function wrapText(context, text, x, y, maxWidth, lineHeight, preparingSentence, lines) {
|
||||
const words = text.split(" ");
|
||||
const words = text.split(/\s/g);
|
||||
for (let i = 0; i < words.length; i++) {
|
||||
const workSentence = preparingSentence.join(" ") + " " + words[i];
|
||||
|
||||
|
|
@ -29,6 +29,8 @@ function wrapText(context, text, x, y, maxWidth, lineHeight, preparingSentence,
|
|||
|
||||
lines.push(preparingSentence.join(" "));
|
||||
|
||||
y -= (lines.length * lineHeight) / 2;
|
||||
|
||||
lines.forEach(element => {
|
||||
const lineWidth = context.measureText(element).width;
|
||||
const xOffset = (maxWidth - lineWidth) / 2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue