mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-18 10:57: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
|
@ -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))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue