commit
This commit is contained in:
parent
81df8879c2
commit
20292262d6
4 changed files with 47 additions and 25 deletions
61
app.js
61
app.js
|
@ -167,13 +167,12 @@ client.on('interactionCreate', async interaction => {
|
||||||
|
|
||||||
quota = await getQuota(interaction.member.user.id);
|
quota = await getQuota(interaction.member.user.id);
|
||||||
|
|
||||||
if (quota >= 999) {
|
if (quota >= 200000) {
|
||||||
interaction.editReply('Quota exceeded, please wait');
|
interaction.editReply('Quota exceeded, please wait untill reset (every month)');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
incrementQuota(interaction.member.user.id);
|
|
||||||
|
|
||||||
answerQuestion(interaction.options.get('question').value).then((res) => {
|
answerQuestion(interaction.options.get('question').value).then((res) => {
|
||||||
|
incrementQuota(interaction.member.user.id, res.data.usage.total_tokens);
|
||||||
if (res.data.choices[0].message.content.length > 4096) {
|
if (res.data.choices[0].message.content.length > 4096) {
|
||||||
interaction.editReply(res.data.choices[0].message.content);
|
interaction.editReply(res.data.choices[0].message.content);
|
||||||
addToLogs('[Discord] Sent answer to : ' +interaction.options.get('question').value);
|
addToLogs('[Discord] Sent answer to : ' +interaction.options.get('question').value);
|
||||||
|
@ -244,28 +243,35 @@ client.on('interactionCreate', async interaction => {
|
||||||
|
|
||||||
else if (interaction.commandName === 'addmsg') {
|
else if (interaction.commandName === 'addmsg') {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
await addMessage(interaction.options.get('name').value,"user" ,interaction.options.get('message').value, interaction.member.user.username);
|
|
||||||
|
|
||||||
messages = await getMessages(interaction.options.get('name').value, "role");
|
quota = await getQuota(interaction.member.user.id);
|
||||||
|
|
||||||
|
if (quota >= 200000) {
|
||||||
|
interaction.editReply('Quota exceeded, please wait untill reset (every month)');
|
||||||
|
} else {
|
||||||
|
await addMessage(interaction.options.get('name').value,"user" ,interaction.options.get('message').value, interaction.member.user.username);
|
||||||
|
|
||||||
sendConv(messages).then((res) => {
|
messages = await getMessages(interaction.options.get('name').value, "role");
|
||||||
addMessage(interaction.options.get('name').value,"assistant",res.data.choices[0].message.content , "Chaise bot");
|
|
||||||
|
|
||||||
const embed_user = new discord.EmbedBuilder()
|
sendConv(messages).then((res) => {
|
||||||
.setColor(0xBBFAF4)
|
addMessage(interaction.options.get('name').value,"assistant",res.data.choices[0].message.content , "Chaise bot");
|
||||||
.setAuthor({ name : interaction.member.user.username, iconURL : "https://cdn.discordapp.com/avatars/"+interaction.member.user.id+"/"+interaction.member.user.avatar+".jpeg"})
|
|
||||||
.setDescription(interaction.options.get('message').value);
|
|
||||||
|
|
||||||
const embed_bot = new discord.EmbedBuilder()
|
const embed_user = new discord.EmbedBuilder()
|
||||||
.setColor(0xFABBDE)
|
.setColor(0xBBFAF4)
|
||||||
.setAuthor({ name : "Chaise bot", iconURL : client.user.displayAvatarURL()})
|
.setAuthor({ name : interaction.member.user.username, iconURL : "https://cdn.discordapp.com/avatars/"+interaction.member.user.id+"/"+interaction.member.user.avatar+".jpeg"})
|
||||||
.setDescription(res.data.choices[0].message.content)
|
.setDescription(interaction.options.get('message').value);
|
||||||
.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_user, embed_bot] });
|
const embed_bot = new discord.EmbedBuilder()
|
||||||
}).catch((err) => {
|
.setColor(0xFABBDE)
|
||||||
console.log(err);
|
.setAuthor({ name : "Chaise bot", iconURL : client.user.displayAvatarURL()})
|
||||||
});
|
.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" });
|
||||||
|
|
||||||
|
interaction.editReply({ embeds : [embed_user, embed_bot] });
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (interaction.commandName === 'displayconv') {
|
else if (interaction.commandName === 'displayconv') {
|
||||||
|
@ -289,6 +295,19 @@ client.on('interactionCreate', async interaction => {
|
||||||
|
|
||||||
interaction.editReply({ embeds : [embed] });
|
interaction.editReply({ embeds : [embed] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (interaction.commandName === 'getmyguota') {
|
||||||
|
await interaction.deferReply();
|
||||||
|
quota = await getQuota(interaction.member.user.id);
|
||||||
|
|
||||||
|
const embed = new discord.EmbedBuilder()
|
||||||
|
.setColor(0xFABBDE)
|
||||||
|
.setAuthor({ name : "Quota : " + interaction.member.user.username, iconURL : "https://cdn.discordapp.com/avatars/"+interaction.member.user.id+"/"+interaction.member.user.avatar+".jpeg"})
|
||||||
|
.setDescription("You have a quota of " + quota + "/200k tokens")
|
||||||
|
.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] });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//bot launch
|
//bot launch
|
||||||
|
|
|
@ -19,9 +19,9 @@ function addUserToDb(id, user) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function incrementQuota(id) {
|
function incrementQuota(id, value) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
connection.query('UPDATE users SET quota = quota + 1 WHERE userid = ' + id, (error, results, fields) => {
|
connection.query('UPDATE users SET quota = quota + '+ value + ' WHERE userid = ' + id, (error, results, fields) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -24,14 +24,13 @@ async function generateImage(query, ctx, bot) {
|
||||||
async function answerQuestion(query) {
|
async function answerQuestion(query) {
|
||||||
response = await openai.createChatCompletion({
|
response = await openai.createChatCompletion({
|
||||||
model: "gpt-3.5-turbo",
|
model: "gpt-3.5-turbo",
|
||||||
messages: [{"role":"system", "content" : "You are a helpful assistant."},{ "role" : "user", "content" : "who is the president of the united states?" }, { "role" : "assistant", "content" : "Joe Biden"}],
|
messages: [{ "role" : "user", "content" : query}],
|
||||||
temperature: 0.9,
|
temperature: 0.9,
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
addToLogs("--> error : " + err);
|
addToLogs("--> error : " + err);
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(response);
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,10 @@ const commands = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name : 'getmyguota',
|
||||||
|
description : 'Get your quota',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD);
|
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue