diff --git a/commands/message/info/appinfo.js b/commands/message/info/appinfo.js index 5782cfe..6881e89 100644 --- a/commands/message/info/appinfo.js +++ b/commands/message/info/appinfo.js @@ -137,7 +137,7 @@ module.exports = { } if(assets.length){ - let asset = assets.map(a => link(`https://cdn.discordapp.com/app-assets/${application.id}/${a.id}.png?size=4096`, stringwrap(a.name, 23))) + let asset = assets.map(a => link(`https://cdn.discordapp.com/app-assets/${application.id}/${a.id}.png?size=4096`, stringwrap(a.name, 23, false))) if(asset.length >= 6) asset[5] = link(`https://canary.discord.com/api/oauth2/applications/${application.id}/assets`, `View ${asset.length - 6} remaining assets`) embed.fields.push({ name: `${icon("image")} Assets`, diff --git a/commands/message/limited/bard.js b/commands/message/limited/bard.js index a77daa5..b82c438 100644 --- a/commands/message/limited/bard.js +++ b/commands/message/limited/bard.js @@ -8,6 +8,7 @@ const superagent = require('superagent') const { iconPill, stringwrap } = require('../../../labscore/utils/markdown') const { Permissions } = require("detritus-client/lib/constants"); +const { Components } = require('detritus-client/lib/utils'); module.exports = { name: 'bard', @@ -36,6 +37,9 @@ module.exports = { .set({ Authorization: process.env.AI_SERVER_KEY }) + .query({ + with_drafts: true + }) .send({ input }) @@ -53,7 +57,7 @@ module.exports = { }) } - return editOrReply(context, { + if(!res.body.drafts || res.body.drafts?.length <= 1) return editOrReply(context, { embeds:[createEmbed("defaultNoFooter", context, { author: { name: stringwrap(args.text, 50), @@ -66,6 +70,92 @@ module.exports = { })], files }) + // Draft support + else { + + let currentView; + + const components = new Components({ + timeout: 100000, + run: async (ctx) => { + if (ctx.userId !== context.userId) return await ctx.respond(InteractionCallbackTypes.DEFERRED_UPDATE_MESSAGE); + + // this sucks but works, ensures the newly selected option stays selected + for (let i = 0; i < components.components[0].components[0].options.length; i++) { + components.components[0].components[0].options[i].default = (components.components[0].components[0].options[i].value == ctx.data.values[0]) + } + + draft = res.body.drafts[parseInt(ctx.data.values[0].replace('draft-', ''))] + + description = [] + files = []; + + if(draft.length <= 4000) description.push(draft) + else { + files.push({ + filename: `chat.${Date.now().toString(36)}.txt`, + value: Buffer.from(draft) + }) + } + + currentView = createEmbed("defaultNoFooter", context, { + author: { + name: stringwrap(args.text, 50, false), + iconUrl: STATIC_ICONS.ai_bard_idle + }, + description: description.join('\n'), + footer: { + text: `Bard • This information may be inaccurate or biased` + } + }) + + await ctx.editOrRespond({ + embeds:[currentView], + files, + components + }) + } + }) + + let draftOptions = []; + for (let i = 1; i < res.body.drafts.length; i++) { + draftOptions.push({ + label: `Draft ${i}: ​ ${stringwrap(res.body.drafts[i], 50, false)}`, + value: "draft-" + (i - 1), + default: false + }) + } + + components.addSelectMenu({ + placeholder: "View other drafts", + customId: "bard-drafts", + options: draftOptions + }) + + setTimeout(()=>{ + editOrReply(context, { + embeds:[currentView], + components:[] + }) + }, 100000) + + currentView = createEmbed("defaultNoFooter", context, { + author: { + name: stringwrap(args.text, 50, false), + iconUrl: STATIC_ICONS.ai_bard_idle + }, + description: description.join('\n'), + footer: { + text: `Bard • This information may be inaccurate or biased` + } + }) + + return editOrReply(context, { + embeds:[currentView], + files, + components + }) + } }catch(e){ if(e.response?.body?.message) return editOrReply(context, createEmbed("warning", context, e.response.body.message)) diff --git a/commands/message/limited/chat.js b/commands/message/limited/chat.js index 3cfa46e..efff603 100644 --- a/commands/message/limited/chat.js +++ b/commands/message/limited/chat.js @@ -106,7 +106,7 @@ module.exports = { embeds:[createEmbed("defaultNoFooter", context, { author: { iconUrl: MODELS[model.toLowerCase()].icon, - name: stringwrap(args.text, 50) + name: stringwrap(args.text, 50, false) }, description: description.join('\n'), footer: { diff --git a/commands/message/limited/clyde.js b/commands/message/limited/clyde.js index 8e7cacc..5bc2b0d 100644 --- a/commands/message/limited/clyde.js +++ b/commands/message/limited/clyde.js @@ -114,7 +114,7 @@ Current time: ${new Date().toLocaleDateString('en-us', { weekday:"long", year:"n embeds:[createEmbed("defaultNoFooter", context, { author: { iconUrl: STATIC_ICONS.ai_clyde_idle, - name: stringwrap(args.text, 50) + name: stringwrap(args.text, 50, false) }, description: description.join('\n') })], @@ -127,7 +127,7 @@ Current time: ${new Date().toLocaleDateString('en-us', { weekday:"long", year:"n embeds:[createEmbed("defaultNoFooter", context, { author: { iconUrl: STATIC_ICONS.ai_clyde_idle, - name: stringwrap(args.text, 50) + name: stringwrap(args.text, 50, false) }, description: ERROR_QUIPS[Math.floor(Math.random()*ERROR_QUIPS.length)] })] diff --git a/commands/message/limited/dalle.js b/commands/message/limited/dalle.js index 58d1ad6..2eb547f 100644 --- a/commands/message/limited/dalle.js +++ b/commands/message/limited/dalle.js @@ -41,7 +41,7 @@ module.exports = { // Fetch the image let img = await superagent.get(res.body.output) - let description = [smallIconPill("generative_ai", stringwrap(args.text, 50)), ''] + let description = [smallIconPill("generative_ai", stringwrap(args.text, 50, false)), ''] let files = []; if(!res.body.output) res.body.output = '[Empty Response]' diff --git a/commands/message/limited/palm.js b/commands/message/limited/palm.js index 410da6a..651c592 100644 --- a/commands/message/limited/palm.js +++ b/commands/message/limited/palm.js @@ -83,7 +83,7 @@ module.exports = { return editOrReply(context, { embeds:[createEmbed("defaultNoFooter", context, { author: { - name: stringwrap(prompt, 50), + name: stringwrap(prompt, 50, false), iconUrl: STATIC_ICONS.ai_palm_idle }, description: description.join('\n'), diff --git a/commands/message/utils/translate.js b/commands/message/utils/translate.js index 2b013d6..6e75bbb 100644 --- a/commands/message/utils/translate.js +++ b/commands/message/utils/translate.js @@ -41,14 +41,14 @@ module.exports = { if(!content.length) return editOrReply(context, createEmbed("warning", context, "No text supplied.")) - if(!isSupported(args.to)) return editOrReply(context, createEmbed("warning", context, `Invalid target language (${stringwrap(args.to, 10)}).`)) - if(!isSupported(args.from)) return editOrReply(context, createEmbed("warning", context, `Invalid source language (${stringwrap(args.from, 10)}).`)) + if(!isSupported(args.to)) return editOrReply(context, createEmbed("warning", context, `Invalid target language (${stringwrap(args.to, 10, false)}).`)) + if(!isSupported(args.from)) return editOrReply(context, createEmbed("warning", context, `Invalid source language (${stringwrap(args.from, 10, false)}).`)) let targetLanguage = getCodeFromAny(args.to) let sourceLanguage = getCodeFromAny(args.from) - if(!targetLanguage) return editOrReply(context, createEmbed("warning", context, `Invalid target language (${stringwrap(args.to, 10)}).`)) - if(!sourceLanguage) return editOrReply(context, createEmbed("warning", context, `Invalid source language (${stringwrap(args.from, 10)}).`)) + if(!targetLanguage) return editOrReply(context, createEmbed("warning", context, `Invalid target language (${stringwrap(args.to, 10, false)}).`)) + if(!sourceLanguage) return editOrReply(context, createEmbed("warning", context, `Invalid source language (${stringwrap(args.from, 10, false)}).`)) try{ let translate = await googleTranslate(context, content, targetLanguage, sourceLanguage) diff --git a/labscore/utils/markdown.js b/labscore/utils/markdown.js index b19c5a1..bc79563 100644 --- a/labscore/utils/markdown.js +++ b/labscore/utils/markdown.js @@ -29,7 +29,8 @@ module.exports.timestamp = function(time, flag = "t"){ return `` } -module.exports.stringwrap = function(content = "", length){ +module.exports.stringwrap = function(content = "", length, newlines = true){ + if(!newlines) content = content.replace(/\n/, '') if(content.length > length) return content.substr(0, length) + '...'; return content; }