mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 06:33:05 -04:00
show different drafts on bard
This commit is contained in:
parent
b19f753ae0
commit
a0a0e2d492
8 changed files with 103 additions and 12 deletions
|
@ -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`,
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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)]
|
||||
})]
|
||||
|
|
|
@ -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]'
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -29,7 +29,8 @@ module.exports.timestamp = function(time, flag = "t"){
|
|||
return `<t:${Math.floor(time/1000)}:${flag}>`
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue