commit
This commit is contained in:
parent
9965a9ba6d
commit
51e6f97c5f
1 changed files with 42 additions and 39 deletions
81
app.js
81
app.js
|
@ -30,6 +30,7 @@ function addUserToDb(id, user) {
|
||||||
console.error('Erreur dans la requête : ', error);
|
console.error('Erreur dans la requête : ', error);
|
||||||
} else {
|
} else {
|
||||||
console.log('Les résultats de la requête : ', results);
|
console.log('Les résultats de la requête : ', results);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -198,52 +199,54 @@ client.on('interactionCreate', async interaction => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!(users.includes(interaction.member.user.id))) {
|
if (!(users.includes(interaction.member.user.id))) {
|
||||||
addUserToDb(interaction.member.user.id, interaction.member.user.username)
|
addUserToDb(interaction.member.user.id, interaction.member.user.username);
|
||||||
addToLogs('[Discord] Added user to the database : ' + interaction.member.user.username);
|
addToLogs('[Discord] Added user to the database : ' + interaction.member.user.username);
|
||||||
console.log('[Discord] Added user to the database : ' + interaction.member.user.username);
|
console.log('[Discord] Added user to the database : ' + interaction.member.user.username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.query('SELECT quota FROM users WHERE userid = '+ interaction.member.user.id, (error, results, fields) => {
|
setTimeout(() => {
|
||||||
if (error) {
|
connection.query('SELECT quota FROM users WHERE userid = '+ interaction.member.user.id, (error, results, fields) => {
|
||||||
console.error('Erreur dans la requête : ', error);
|
if (error) {
|
||||||
} else {
|
console.error('Erreur dans la requête : ', error);
|
||||||
if (results[0].quota >= 999) {
|
} else {
|
||||||
interaction.editReply('Quota exceeded, please wait');
|
if (results[0].quota >= 999) {
|
||||||
|
interaction.editReply('Quota exceeded, please wait');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
incrementQuota(interaction.member.user.id);
|
||||||
|
|
||||||
|
answerQuestion(interaction.options.get('question').value).then((res) => {
|
||||||
|
if (res.data.choices[0].message.content.length > 4096) {
|
||||||
|
interaction.editReply(res.data.choices[0].message.content.lenght);
|
||||||
|
addToLogs('[Discord] Sent answer to : ' +interaction.options.get('question').value);
|
||||||
|
console.log('[Discord] Sent answer to : ' + interaction.options.get('question').value);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
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(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
});
|
||||||
incrementQuota(interaction.member.user.id);
|
}, 100);
|
||||||
|
|
||||||
answerQuestion(interaction.options.get('question').value).then((res) => {
|
|
||||||
if (res.data.choices[0].message.content.length > 4096) {
|
|
||||||
interaction.editReply(res.data.choices[0].message.content.lenght);
|
|
||||||
addToLogs('[Discord] Sent answer to : ' +interaction.options.get('question').value);
|
|
||||||
console.log('[Discord] Sent answer to : ' + interaction.options.get('question').value);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
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(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (interaction.commandName === 'info') {
|
else if (interaction.commandName === 'info') {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue