mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
chat command
This commit is contained in:
parent
760e1167c3
commit
f1a64a25d9
2 changed files with 40 additions and 0 deletions
37
commands/message/fun/chat.js
Normal file
37
commands/message/fun/chat.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||
const { format } = require('../../../labscore/utils/ansi')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
|
||||
const superagent = require('superagent')
|
||||
const { codeblock } = require('../../../labscore/utils/markdown')
|
||||
|
||||
module.exports = {
|
||||
name: 'chat',
|
||||
label: 'text',
|
||||
metadata: {
|
||||
description: 'Chat with an AI language model.',
|
||||
description_short: 'AI Language Model',
|
||||
examples: ['chat How many otter species are there?'],
|
||||
category: 'fun',
|
||||
usage: 'chat <prompt>'
|
||||
},
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||
try{
|
||||
let res = await superagent.get(`${process.env.AI_SERVER}/chat`)
|
||||
.query({
|
||||
prompt: args.text
|
||||
})
|
||||
return editOrReply(context, {embeds:[createEmbed("default", context, {
|
||||
description: codeblock("ansi", ["👤 " + format(args.text, "cyan") + "\n🤖 " + res.body.text]),
|
||||
footer: {
|
||||
text: `This information may be inaccurate or biased • ${context.application.name}`
|
||||
}
|
||||
})]})
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate text.`)]})
|
||||
}
|
||||
}
|
||||
};
|
|
@ -83,6 +83,8 @@ module.exports.createEmbed = function(type, context, content){
|
|||
return emb
|
||||
}
|
||||
|
||||
if(content.footer && !content.footer.iconUrl) content.footer.iconUrl = `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`
|
||||
|
||||
if(["image"].includes(type)){
|
||||
if(content.url.includes('://')){
|
||||
emb.image = { url: content.url }
|
||||
|
@ -99,6 +101,7 @@ module.exports.createEmbed = function(type, context, content){
|
|||
|
||||
return emb
|
||||
}
|
||||
|
||||
return Object.assign(emb, content)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue