added version 2.0
This commit is contained in:
parent
0163d40b4e
commit
0f18925d1a
3231 changed files with 1449 additions and 374732 deletions
|
@ -1,151 +0,0 @@
|
|||
const { ApplicationCommandOptionType } = require('discord.js');
|
||||
|
||||
const commands = [
|
||||
{
|
||||
name: 'gptrequest',
|
||||
description: 'Make a request to the GPT-4 API',
|
||||
options: [
|
||||
{
|
||||
name: 'question',
|
||||
description: 'The question you want to ask to the API',
|
||||
type: ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
name: 'quickgpt',
|
||||
description: 'Make a quicker request to the GPT-3.5 API',
|
||||
options: [
|
||||
{
|
||||
name: 'question',
|
||||
description: 'The question you want to ask to the API',
|
||||
type: ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
name : 'info',
|
||||
description : 'utilise pas cette commande fdp',
|
||||
},
|
||||
|
||||
{
|
||||
name : 'addconv',
|
||||
description : 'Add a conversation to the database',
|
||||
options : [
|
||||
{
|
||||
name : 'name',
|
||||
description : 'The name of the conversation',
|
||||
type : ApplicationCommandOptionType.String,
|
||||
required : true,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
name : 'delconv',
|
||||
description : 'Delete a conversation from the database',
|
||||
options : [
|
||||
{
|
||||
name : 'name',
|
||||
description : 'The name of the conversation',
|
||||
type : ApplicationCommandOptionType.String,
|
||||
required : true,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
name : 'listconvs',
|
||||
description : 'List all the conversations in the database',
|
||||
},
|
||||
|
||||
{
|
||||
name : 'addmsg',
|
||||
description : 'Add a message to a conversation',
|
||||
options : [
|
||||
{
|
||||
name : 'name',
|
||||
description : 'The name of the conversation',
|
||||
type : ApplicationCommandOptionType.String,
|
||||
required : true,
|
||||
},
|
||||
{
|
||||
name : 'message',
|
||||
description : 'The message to add to the conversation',
|
||||
type : ApplicationCommandOptionType.String,
|
||||
required : true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name : 'displayconv',
|
||||
description : 'Display a conversation',
|
||||
options : [
|
||||
{
|
||||
name : 'name',
|
||||
description : 'The name of the conversation',
|
||||
type : ApplicationCommandOptionType.String,
|
||||
required : true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name : 'getmyguota',
|
||||
description : 'Get your quota',
|
||||
},
|
||||
|
||||
{
|
||||
name : 'github',
|
||||
description : 'Get the github link of the bot',
|
||||
},
|
||||
|
||||
{
|
||||
name : 'dalle',
|
||||
description : 'Make a request to the DALL-E API',
|
||||
options : [
|
||||
{
|
||||
name : 'query',
|
||||
description : 'The query you want to ask to the API',
|
||||
type : ApplicationCommandOptionType.String,
|
||||
required : true,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
name : 'addchannel',
|
||||
description : 'Add a channel to the conversation system',
|
||||
options : [
|
||||
{
|
||||
name : 'channel',
|
||||
description : 'The channel you want to add',
|
||||
type : ApplicationCommandOptionType.Channel,
|
||||
required : true,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
name : 'deletechannel',
|
||||
description : 'Delete a channel from the conversation system',
|
||||
options : [
|
||||
{
|
||||
name : 'channel',
|
||||
description : 'The channel you want to delete',
|
||||
type : ApplicationCommandOptionType.Channel,
|
||||
required : true,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
name : 'help',
|
||||
description : 'Get help',
|
||||
},
|
||||
];
|
||||
|
||||
module.exports = { commands };
|
11
commands/fun/ping.js
Normal file
11
commands/fun/ping.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const { SlashCommandBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("ping")
|
||||
.setDescription("Replies with Pong!"),
|
||||
async execute(interaction) {
|
||||
console.log("ping command executed");
|
||||
await interaction.reply("Pong!");
|
||||
},
|
||||
};
|
43
commands/hubs/addhub.js
Normal file
43
commands/hubs/addhub.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
const {
|
||||
SlashCommandBuilder,
|
||||
EmbedBuilder,
|
||||
ButtonBuilder,
|
||||
ActionRowBuilder,
|
||||
ButtonStyle,
|
||||
PermissionsBitField,
|
||||
} = require("discord.js");
|
||||
const { errorEmbed } = require("../../libs/embeds.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("addhub")
|
||||
.setDescription("Add a conversation hub to the database.")
|
||||
.setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
if (
|
||||
!interaction.member.permissions.has(
|
||||
PermissionsBitField.Flags.Administrator
|
||||
)
|
||||
) {
|
||||
const embed = errorEmbed(
|
||||
"You need the administrator permission to use this command."
|
||||
);
|
||||
return interaction.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Conversation hub")
|
||||
.setDescription("Click on the button below to create a conversation.")
|
||||
.setColor("#F6C6F9")
|
||||
.setFooter({ text: "Bot by @ninja_jambon" });
|
||||
|
||||
const button = new ButtonBuilder()
|
||||
.setCustomId("create_conversation")
|
||||
.setLabel("Create conversation")
|
||||
.setStyle(ButtonStyle.Success);
|
||||
|
||||
const actionRow = new ActionRowBuilder().addComponents(button);
|
||||
|
||||
await interaction.reply({ embeds: [embed], components: [actionRow] });
|
||||
},
|
||||
};
|
37
commands/hubs/closeconv.js
Normal file
37
commands/hubs/closeconv.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
const { SlashCommandBuilder } = require("discord.js");
|
||||
const { getConv, removeConv } = require("../../libs/mysql.js");
|
||||
const { errorEmbed } = require("../../libs/embeds.js");
|
||||
const { sendLog } = require("../../libs/logs.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("closeconv")
|
||||
.setDescription("Close the current conversation.")
|
||||
.setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
const conv = await getConv(interaction.channelId).catch((err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to get your conversation data."
|
||||
);
|
||||
|
||||
return interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
|
||||
if (!conv[0]) {
|
||||
const embed = errorEmbed("This channel is not a conversation.");
|
||||
return interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
if (conv[0].userid != interaction.user.id) {
|
||||
const embed = errorEmbed("You are not the owner of this conversation.");
|
||||
return interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
var channel = interaction.guild.channels.cache.get(interaction.channelId);
|
||||
|
||||
await removeConv(channel.id);
|
||||
await channel.delete();
|
||||
},
|
||||
};
|
32
commands/mistral/mistral.js
Normal file
32
commands/mistral/mistral.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const { SlashCommandBuilder } = require("discord.js");
|
||||
//const { sendConv } = require("../../libs/mistralAiFunctions");
|
||||
//const data = require("../../data.json");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("mistral")
|
||||
.setDescription("Talk to Mistral AI")
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName("medium")
|
||||
.setDescription("Talk to Mistral AI using the medium model")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("message")
|
||||
.setDescription("What do you want to say to Mistral AI?")
|
||||
.setRequired(true)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
/*if (interaction.options.getSubcommand() === "medium") {
|
||||
const message = interaction.options.getString("message");
|
||||
messages = [
|
||||
{ role: system, text: data.prompt },
|
||||
{ role: user, text: message },
|
||||
];
|
||||
const chatResponse = await sendConv(messages);
|
||||
console.log(chatResponse);
|
||||
await interaction.reply(chatResponse);
|
||||
}*/
|
||||
},
|
||||
};
|
31
commands/others/botinfo.js
Normal file
31
commands/others/botinfo.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
const { getQuotasSum } = require("../../libs/mysql.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("botinfo")
|
||||
.setDescription("Get information about the bot."),
|
||||
async execute(interaction) {
|
||||
const quotasSum = await getQuotasSum();
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor("#F6C6F9")
|
||||
.setTitle("Bot Info")
|
||||
.setDescription("Information about the bot.")
|
||||
.addFields(
|
||||
{
|
||||
name: "Guilds",
|
||||
value: interaction.client.guilds.cache.size.toString(),
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: "Total quota",
|
||||
value: `${quotasSum[0]["SUM(quota)"]}$`,
|
||||
inline: false,
|
||||
}
|
||||
)
|
||||
.setFooter({ text: "Bot by @ninja_jambon" });
|
||||
|
||||
interaction.reply({ embeds: [embed] });
|
||||
},
|
||||
};
|
36
commands/others/getquota.js
Normal file
36
commands/others/getquota.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
const { getUser } = require("../../libs/mysql.js");
|
||||
const { errorEmbed } = require("../../libs/embeds.js");
|
||||
const { sendLog } = require("../../libs/logs.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("getquota")
|
||||
.setDescription("Get your current quota.")
|
||||
.setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
const user = await getUser(interaction.user.id).catch((err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to get your user data."
|
||||
);
|
||||
|
||||
return interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
|
||||
if (!user[0]) {
|
||||
const embed = errorEmbed("You don't have any quota yet.");
|
||||
|
||||
return interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor("#F6C6F9")
|
||||
.setTitle("Quota")
|
||||
.setDescription(`You have ${0.4 - user[0].quota}$ of credits left.`)
|
||||
.setFooter({ text: "Bot by @ninja_jambon" });
|
||||
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
},
|
||||
};
|
34
commands/others/help.js
Normal file
34
commands/others/help.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("help")
|
||||
.setDescription("Get help about the bot."),
|
||||
async execute(interaction) {
|
||||
const helpMessage = `
|
||||
**Single requests:**
|
||||
- **/quickgpt**: Make a single request to the GPT-3.5 Turbo model.
|
||||
- **/gptrequest**: Make a single request to the GPT-4 model.
|
||||
|
||||
**Conversations:**
|
||||
- **/addhub**: Add a conversation hub to the channel, user needs to have the ADMINISTRATOR permission and the channel needs to be a forum channel or a normal text channel.
|
||||
- **/closeconv**: Close the conversation in your channel, user needs to be the creator of the conversation.
|
||||
|
||||
**Others:**
|
||||
- **/getquota**: Display your quota, you can use a total of 0.4$ of quota per month.
|
||||
- **/botinfo**: Display information about the bot.
|
||||
|
||||
**Links:**
|
||||
- [Invite the bot](https://discord.com/api/oauth2/authorize?client_id=1059559067846189067&permissions=326417632256&scope=bot)
|
||||
- [Support server](https://discord.gg/WcZPz3nm5p)
|
||||
`;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor("#F6C6F9")
|
||||
.setTitle("Help")
|
||||
.setDescription(helpMessage)
|
||||
.setFooter({ text: "Bot by @ninja_jambon" });
|
||||
|
||||
interaction.reply({ embeds: [embed] });
|
||||
},
|
||||
};
|
107
commands/single requests/gptrequest.js
Normal file
107
commands/single requests/gptrequest.js
Normal file
|
@ -0,0 +1,107 @@
|
|||
const { SlashCommandBuilder } = require("discord.js");
|
||||
const {
|
||||
getUser,
|
||||
registerUser,
|
||||
incrementQuota,
|
||||
} = require("../../libs/mysql.js");
|
||||
const { answerQuestion } = require("../../libs/openAi.js");
|
||||
const { checkLastResetDate } = require("../../libs/quotaReset.js");
|
||||
const { requestResponseEmbed, errorEmbed } = require("../../libs/embeds.js");
|
||||
const { sendLog } = require("../../libs/logs.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("gptrequest")
|
||||
.setDescription("Make a single request to the GPT-4 API.")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("prompt")
|
||||
.setDescription("The prompt to send to the API.")
|
||||
.setRequired(true)
|
||||
),
|
||||
async execute(interaction) {
|
||||
interaction.deferReply();
|
||||
await checkLastResetDate();
|
||||
user = await getUser(interaction.user.id).catch((err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to get your user data."
|
||||
);
|
||||
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
|
||||
if (!user[0]) {
|
||||
await registerUser(interaction.user.username, interaction.user.id).catch(
|
||||
(err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to register you in our database."
|
||||
);
|
||||
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
);
|
||||
|
||||
user = await getUser(interaction.user.id).catch((err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to get your user data."
|
||||
);
|
||||
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
}
|
||||
|
||||
if (user[0].quota >= 0.4) {
|
||||
const embed = errorEmbed(
|
||||
"You don't have enough quota to use this command."
|
||||
);
|
||||
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
response = await answerQuestion(
|
||||
interaction.options.getString("prompt")
|
||||
).catch((err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to send the request to the API."
|
||||
);
|
||||
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
|
||||
const prompt_usage = (response.data.usage.prompt_tokens * 0.01) / 1000;
|
||||
const completion_usage =
|
||||
(response.data.usage.completion_tokens * 0.03) / 1000;
|
||||
|
||||
await incrementQuota(
|
||||
interaction.user.id,
|
||||
prompt_usage + completion_usage
|
||||
).catch((err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to increment your quota."
|
||||
);
|
||||
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
|
||||
const embed = requestResponseEmbed(
|
||||
interaction.user,
|
||||
interaction.options.getString("prompt"),
|
||||
response.data.choices[0].message.content,
|
||||
user[0].quota,
|
||||
prompt_usage,
|
||||
completion_usage
|
||||
);
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
},
|
||||
};
|
107
commands/single requests/quickgpt.js
Normal file
107
commands/single requests/quickgpt.js
Normal file
|
@ -0,0 +1,107 @@
|
|||
const { SlashCommandBuilder } = require("discord.js");
|
||||
const {
|
||||
getUser,
|
||||
registerUser,
|
||||
incrementQuota,
|
||||
} = require("../../libs/mysql.js");
|
||||
const { quickAnswer } = require("../../libs/openAi.js");
|
||||
const { checkLastResetDate } = require("../../libs/quotaReset.js");
|
||||
const { requestResponseEmbed, errorEmbed } = require("../../libs/embeds.js");
|
||||
const { sendLog } = require("../../libs/logs.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("quickgpt")
|
||||
.setDescription("Make a single request to the GPT-3.5-turbo API.")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("prompt")
|
||||
.setDescription("The prompt to send to the API.")
|
||||
.setRequired(true)
|
||||
),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply();
|
||||
await checkLastResetDate();
|
||||
user = await getUser(interaction.user.id).catch((err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to get your user data."
|
||||
);
|
||||
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
|
||||
if (!user[0]) {
|
||||
await registerUser(interaction.user.username, interaction.user.id).catch(
|
||||
(err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to register you in our database."
|
||||
);
|
||||
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
);
|
||||
|
||||
user = await getUser(interaction.user.id).catch((err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to get your user data."
|
||||
);
|
||||
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
}
|
||||
|
||||
if (user[0].quota >= 0.4) {
|
||||
const embed = errorEmbed(
|
||||
"You don't have enough quota to use this command."
|
||||
);
|
||||
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
response = await quickAnswer(interaction.options.getString("prompt")).catch(
|
||||
(err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to send the request to the API."
|
||||
);
|
||||
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
);
|
||||
|
||||
const prompt_usage = (response.data.usage.prompt_tokens * 0.001) / 1000;
|
||||
const completion_usage =
|
||||
(response.data.usage.completion_tokens * 0.002) / 1000;
|
||||
|
||||
await incrementQuota(
|
||||
interaction.user.id,
|
||||
prompt_usage + completion_usage
|
||||
).catch((err) => {
|
||||
sendLog(err);
|
||||
|
||||
const embed = errorEmbed(
|
||||
"An error occured while trying to increment your quota."
|
||||
);
|
||||
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
|
||||
const embed = requestResponseEmbed(
|
||||
interaction.user,
|
||||
interaction.options.getString("prompt"),
|
||||
response.data.choices[0].message.content,
|
||||
user[0].quota,
|
||||
prompt_usage,
|
||||
completion_usage
|
||||
);
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue