Update commands to slash commands
This commit is contained in:
@@ -1,21 +1,47 @@
|
||||
var libCore = require("../libCore.js");
|
||||
const libCore = require("../libCore.js");
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "chat");
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: 'chat',
|
||||
description: 'Chat',
|
||||
async execute(message, args) {
|
||||
if (args.length < 1) {
|
||||
message.reply(`Please use in !chat [chat query]`);
|
||||
return;
|
||||
}
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('chat')
|
||||
.setDescription('Send a text prompt to ChatGPT')
|
||||
.addStringOption(option =>
|
||||
option.setName('prompt')
|
||||
.setDescription('The prompt to be sent to ChatGPT')
|
||||
.setRequired(true))
|
||||
.addNumberOption(option =>
|
||||
option.setName('temperature')
|
||||
.setDescription('Set the temperature, 0 = repetitive, 1 = random')
|
||||
.setRequired(false))
|
||||
.addNumberOption(option =>
|
||||
option.setName('maxTokens')
|
||||
.setDescription('The max amount of tokens to be spent')
|
||||
.setRequired(false)),
|
||||
example: "chat [tell me a story] [0.07] []", // Need to figure out the tokens
|
||||
isPrivileged: false,
|
||||
requiresTokens: true,
|
||||
async execute(interaction) {
|
||||
// Needs middleware for payment
|
||||
|
||||
try {
|
||||
var question = encodeURIComponent(args.join(" "));
|
||||
var params = {};
|
||||
var prompt = encodeURIComponent(interaction.options.getString('prompt').join(" "));
|
||||
var temperature = interaction.options.getNumber('temperature');
|
||||
var maxTokens = interaction.options.getNumber('maxTokens');
|
||||
|
||||
if (temperature) params._temperature = temperature;
|
||||
if (maxTokens) params._max_tokens = maxTokens;
|
||||
|
||||
var response = await libCore.getChat(question);
|
||||
message.reply(`${message.author.username} ${response}`);
|
||||
|
||||
} catch (err) {
|
||||
//message.reply(err.toString());
|
||||
}
|
||||
}
|
||||
var gptResponse = await prompt.libCore.getChat(prompt, params);
|
||||
await interaction.reply(`${interaction.author.username} ${gptResponse}`);
|
||||
|
||||
// Needs reply code to reply to the generation
|
||||
}catch(err){
|
||||
log.ERROR(err)
|
||||
//await interaction.reply(err.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user