commit
This commit is contained in:
parent
323d861852
commit
3a69d32510
3 changed files with 100 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
const discord = require('discord.js');
|
||||
|
||||
const { addToLogs } = require('../libs/botTools');
|
||||
const { generateImage, answerQuestion, sendConv } = require('../libs/openAi');
|
||||
const { generateImage, answerQuestion, sendConv, quickAnswer } = require('../libs/openAi');
|
||||
const { incrementQuota, addConv, delConv, getConvs, addMessage, getMessages, isNewUser } = require('../libs/mysql');
|
||||
|
||||
const { commands } = require('../commands/commands');
|
||||
|
@ -72,6 +72,72 @@ async function gptrequest(interaction, client) {
|
|||
}
|
||||
|
||||
|
||||
async function quickGptrequest(interaction, client) {
|
||||
await interaction.deferReply();
|
||||
|
||||
quota = isNewUser(interaction.member.user.id, interaction.member.user.username).catch((err) => {
|
||||
console.log(err);
|
||||
addToLogs(err);
|
||||
});
|
||||
|
||||
if (quota >= 200000) {
|
||||
const embed = new discord.EmbedBuilder()
|
||||
.setColor(0xFABBDE)
|
||||
.setAuthor({ name: "Quota exceeded", iconURL: client.user.displayAvatarURL() })
|
||||
.setDescription("You have a quota of " + quota + " tokens, please wait until reset (every months)")
|
||||
.setFooter({ text: "Powered by OpenAI https://www.openai.com/", iconURL: "https://seeklogo.com/images/O/open-ai-logo-8B9BFEDC26-seeklogo.com.png" });
|
||||
|
||||
interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
else {
|
||||
quickAnswer(interaction.options.get('question').value).then((res) => {
|
||||
incrementQuota(interaction.member.user.id, res.data.usage.total_tokens).catch((err) => {
|
||||
console.log(err);
|
||||
addToLogs(err);
|
||||
});
|
||||
|
||||
if (res.data.choices[0].message.content.length > 4096) {
|
||||
const embed = new discord.EmbedBuilder()
|
||||
.setColor(0xFABBDE)
|
||||
.setAuthor({ name: "Reply to : " + interaction.member.user.username, iconURL: "https://cdn.discordapp.com/avatars/" + interaction.member.user.id + "/" + interaction.member.user.avatar + ".jpeg" })
|
||||
.setTitle("Question : " + interaction.options.get('question').value)
|
||||
.setDescription("The answer is too long to be displayed, please try again with a shorter question.")
|
||||
.setFooter({ text: "Powered by OpenAI https://www.openai.com/", iconURL: "https://seeklogo.com/images/O/open-ai-logo-8B9BFEDC26-seeklogo.com.png" });
|
||||
|
||||
console.log('[Discord] Sent answer to : ' + interaction.options.get('question').value);
|
||||
addToLogs('[Discord] Sent answer to : ' + interaction.options.get('question').value);
|
||||
interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
else {
|
||||
title = "Question : " + interaction.options.get('question').value;
|
||||
|
||||
if (title.length > 256) {
|
||||
title = title.slice(0, 253) + "...";
|
||||
}
|
||||
|
||||
const embed = new discord.EmbedBuilder()
|
||||
.setColor(0xFABBDE)
|
||||
.setAuthor({ name: "Reply to : " + interaction.member.user.username, iconURL: "https://cdn.discordapp.com/avatars/" + interaction.member.user.id + "/" + interaction.member.user.avatar + ".jpeg" })
|
||||
.setTitle(title)
|
||||
.setDescription(res.data.choices[0].message.content)
|
||||
.setFooter({ text: "Powered by OpenAI https://www.openai.com/", iconURL: "https://seeklogo.com/images/O/open-ai-logo-8B9BFEDC26-seeklogo.com.png" });
|
||||
|
||||
console.log('[Discord] Sent answer to : ' + interaction.options.get('question').value);
|
||||
addToLogs('[Discord] Sent answer to : ' + interaction.options.get('question').value);
|
||||
interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
addToLogs(err);
|
||||
interaction.editReply("Something went wrong");
|
||||
})
|
||||
|
||||
console.log('[Discord] Generating answer to : ' + interaction.options.get('question').value);
|
||||
addToLogs('[Discord] Generating answer to : ' + interaction.options.get('question').value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function addconv(interaction, client) {
|
||||
await interaction.deferReply();
|
||||
convs = await getConvs().catch((err) => {
|
||||
|
@ -105,6 +171,7 @@ async function addconv(interaction, client) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
async function delconv(interaction, client) {
|
||||
await interaction.deferReply();
|
||||
|
||||
|
@ -355,6 +422,10 @@ module.exports = {
|
|||
gptrequest(interaction, client);
|
||||
}
|
||||
|
||||
else if (interaction.commandName === 'quickgpt') {
|
||||
quickGptrequest(interaction, client);
|
||||
}
|
||||
|
||||
else if (interaction.commandName === 'info') {
|
||||
console.log(interaction)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue