From 9105c3563e0333ecc6d05632351c41139946da00 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Wed, 16 Oct 2024 01:42:04 +0200 Subject: [PATCH 01/10] guh --- src/commands/utility/file.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/commands/utility/file.js b/src/commands/utility/file.js index 66092d0..5d5ef25 100644 --- a/src/commands/utility/file.js +++ b/src/commands/utility/file.js @@ -26,8 +26,16 @@ 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})`; } const emojis = JSON.parse(readFileSync("config/emojis.json")); @@ -89,4 +97,4 @@ module.exports = { }); pagination.render(); } -} +} \ No newline at end of file From 79ab38f8f0a79aaf752a15521f47404ed202d0c6 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Wed, 16 Oct 2024 20:44:17 +0200 Subject: [PATCH 02/10] guh --- src/commands/utility/file.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/utility/file.js b/src/commands/utility/file.js index 5d5ef25..3e5cfe2 100644 --- a/src/commands/utility/file.js +++ b/src/commands/utility/file.js @@ -35,7 +35,8 @@ function shorten(str) { 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})`; + + 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")); @@ -97,4 +98,4 @@ module.exports = { }); pagination.render(); } -} \ No newline at end of file +} From d9d648e4956b55f4f908c58df4b51e11a248ada9 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Wed, 16 Oct 2024 23:02:46 +0200 Subject: [PATCH 03/10] quoter new line brokey --- src/utils/quoter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/quoter.js b/src/utils/quoter.js index 854c5c8..dec7b99 100644 --- a/src/utils/quoter.js +++ b/src/utils/quoter.js @@ -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]; @@ -89,6 +89,8 @@ module.exports = { const quoteY = cardHeight / 2 - 10; wrapText(ctx, `"${quote}"`, quoteX, quoteY, quoteWidth, 20, preparingSentence, lines); + console.log("lines: " + lines.length); + const wrappedTextHeight = lines.length * 25; ctx.font = "bold 16px Twitter Color Emoji"; From 0a07c4e56bb927d172ddb113a9d2140e791809f4 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Wed, 16 Oct 2024 23:04:25 +0200 Subject: [PATCH 04/10] oops that's a debug output --- src/utils/quoter.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/utils/quoter.js b/src/utils/quoter.js index dec7b99..5156c50 100644 --- a/src/utils/quoter.js +++ b/src/utils/quoter.js @@ -89,8 +89,6 @@ module.exports = { const quoteY = cardHeight / 2 - 10; wrapText(ctx, `"${quote}"`, quoteX, quoteY, quoteWidth, 20, preparingSentence, lines); - console.log("lines: " + lines.length); - const wrappedTextHeight = lines.length * 25; ctx.font = "bold 16px Twitter Color Emoji"; From 61d800048ca05fd38d72801731fd5944d6bad544 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Sun, 20 Oct 2024 16:26:35 +0200 Subject: [PATCH 05/10] better quote --- src/commands/fun/quote.js | 2 -- src/utils/quoter.js | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/fun/quote.js b/src/commands/fun/quote.js index a7a97c8..81d79b5 100644 --- a/src/commands/fun/quote.js +++ b/src/commands/fun/quote.js @@ -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: [{ diff --git a/src/utils/quoter.js b/src/utils/quoter.js index 5156c50..a41e499 100644 --- a/src/utils/quoter.js +++ b/src/utils/quoter.js @@ -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; From a6498923f1fadf34e53269aa899bfe1e4634e920 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Mon, 21 Oct 2024 09:15:00 +0000 Subject: [PATCH 06/10] update readme --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 272730d..e5aef3a 100644 --- a/readme.md +++ b/readme.md @@ -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 \ No newline at end of file From 4bd04e0a31fa6c9de4bba962b90a0682c5b0deec Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Mon, 28 Oct 2024 19:06:22 +0100 Subject: [PATCH 07/10] Update vision model --- src/commands/accessibility/describe.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/accessibility/describe.js b/src/commands/accessibility/describe.js index 38b9348..37b0235 100644 --- a/src/commands/accessibility/describe.js +++ b/src/commands/accessibility/describe.js @@ -45,7 +45,7 @@ module.exports = { } }] }], - "model": "llama-3.2-11b-vision-preview" + "model": "llama-3.2-90b-vision-preview" })).choices[0].message.content.trim(); if (description.length < 2000) { @@ -62,4 +62,4 @@ module.exports = { await interaction.followUp({ embeds, files }); }, -}; \ No newline at end of file +}; From 7bff830b008b2f1c3f4821bd5a7908bb9cce9c1e Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Mon, 28 Oct 2024 19:22:44 +0100 Subject: [PATCH 08/10] guh --- src/commands/accessibility/describe.js | 30 ++++++++++++++++++-------- src/prompts/image.txt | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/commands/accessibility/describe.js b/src/commands/accessibility/describe.js index 37b0235..64cc5c3 100644 --- a/src/commands/accessibility/describe.js +++ b/src/commands/accessibility/describe.js @@ -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-90b-vision-preview" - })).choices[0].message.content.trim(); + })); + + 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 { diff --git a/src/prompts/image.txt b/src/prompts/image.txt index 395cfa8..d88fdf2 100644 --- a/src/prompts/image.txt +++ b/src/prompts/image.txt @@ -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. \ No newline at end of file From 0873d4641285e59ab8e2e0ee67a30a8587a4a684 Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Mon, 28 Oct 2024 20:35:33 +0100 Subject: [PATCH 09/10] upgrade prompt ai model --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 5328bcc..88fcc96 100644 --- a/src/index.js +++ b/src/index.js @@ -55,7 +55,7 @@ client.on(Events.InteractionCreate, async interaction => { console.log(`${interaction.user.username} ran ${(interaction.isChatInputCommand() ? "/" : '') + interaction.commandName}`); try { - interaction.defaultModel = "llama-3.1-70b-versatile"; + interaction.defaultModel = "llama-3.2-90b-text-preview"; await command.execute(interaction); } catch (err) { console.error(err); @@ -134,4 +134,4 @@ client.once(Events.ClientReady, async () => { } }); -client.login(process.env.TOKEN); \ No newline at end of file +client.login(process.env.TOKEN); From 926d49242198d6bcea4981be1b18961d52ca44be Mon Sep 17 00:00:00 2001 From: Lilith Ashley Nyx Arson Date: Mon, 2 Dec 2024 11:24:01 +0100 Subject: [PATCH 10/10] model deprecat --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 88fcc96..dd9718e 100644 --- a/src/index.js +++ b/src/index.js @@ -55,7 +55,7 @@ client.on(Events.InteractionCreate, async interaction => { console.log(`${interaction.user.username} ran ${(interaction.isChatInputCommand() ? "/" : '') + interaction.commandName}`); try { - interaction.defaultModel = "llama-3.2-90b-text-preview"; + interaction.defaultModel = "llama-3.1-70b-versatile"; await command.execute(interaction); } catch (err) { console.error(err);