From 4dcd4c90726c07448931471f6506d7cd4a64afbc Mon Sep 17 00:00:00 2001 From: Lukian Date: Thu, 6 Jul 2023 19:56:53 +0200 Subject: [PATCH] commit --- app.js | 1 - events/discordEvents.js | 40 +++++++++++++--------------- functions/discord/addmsg.js | 2 +- functions/discord/dalle.js | 4 +-- functions/discord/gptrequest.js | 4 +-- functions/discord/quickGptrequest.js | 4 +-- 6 files changed, 26 insertions(+), 29 deletions(-) diff --git a/app.js b/app.js index 79e3a6a..d0634fc 100644 --- a/app.js +++ b/app.js @@ -11,7 +11,6 @@ const client = new discord.Client({intents: 33297}); discordEvents.ready(client); discordEvents.newMessage(client); discordEvents.newInteraction(client); -discordEvents.guildCreate(client); //bot launch client.login(process.env.DISCORD); \ No newline at end of file diff --git a/events/discordEvents.js b/events/discordEvents.js index 484e8b3..b838fb2 100644 --- a/events/discordEvents.js +++ b/events/discordEvents.js @@ -15,7 +15,7 @@ const dalle = require('../functions/discord/dalle'); const addchannel = require('../functions/discord/addchannel'); const deletechannel = require('../functions/discord/deletechannel'); -const { listchannels, incrementQuota } = require('../libs/mysql'); +const { listchannels, incrementQuota, isNewUser } = require('../libs/mysql'); const { sendQuickConv } = require('../libs/openAi') module.exports = { @@ -24,9 +24,23 @@ module.exports = { const channels = await listchannels(); channelId = msg.channel.id; + quota = await isNewUser(msg.author.id, msg.author.username).catch((err) => { + console.log(err); + addToLogs(err); + }); + if (!channels.includes(channelId) || msg.author.bot == true) {} - else { - discordMessages = await msg.channel.messages.fetch({ limit: 15 }) + + else if (quota.quota >= 200000) { + const embed = new discord.EmbedBuilder() + .setColor(0xFABBDE) + .setAuthor({ name: "Quota exceeded", iconURL: client.user.displayAvatarURL() }) + .setDescription("Quota exceeded, please wait untill reset (every month)") + .setFooter({ text: "Powered by OpenAI https://www.openai.com/", iconURL: "https://seeklogo.com/images/O/open-ai-logo-8B9BFEDC26-seeklogo.com.png" }); + + msg.reply({ embeds: [embed] }); + } else { + discordMessages = await msg.channel.messages.fetch({ limit: 8 }) discordMessages.reverse(); @@ -111,7 +125,8 @@ module.exports = { ready: (client) => { client.on('ready', async () => { console.log(`[Discord] Logged in as ${client.user.tag} !`); - client.user.setPresence({ activities: [{ name: 'la belle chaise', type: 3 }] }); + + client.user.setPresence({ activities: [{ name: client.guilds.cache.size + ' servers !', type: 3 }] }); const rest = new discord.REST({ version: '10' }).setToken(process.env.DISCORD); @@ -123,21 +138,4 @@ module.exports = { console.log('[Discord] Successfully reloaded application (/) commands globally.'); }); }, - - guildCreate: (client) => { - client.on('guildCreate', async (guild) => { - const rest = new discord.REST({ version: '10' }).setToken(process.env.DISCORD); - - try { - await rest.put( - discord.Routes.applicationGuildCommands('1059559067846189067', guild.id), - { body: commands }, - ); - - console.log('[Discord] Successfully reloaded application (/) commands for ' + guild.name + '.'); - } catch (error) { - console.error(error); - } - }); - }, } \ No newline at end of file diff --git a/functions/discord/addmsg.js b/functions/discord/addmsg.js index 75fe163..d07cd78 100644 --- a/functions/discord/addmsg.js +++ b/functions/discord/addmsg.js @@ -12,7 +12,7 @@ async function addmsg(interaction, client) { addToLogs(err); }); - if (quota >= 200000) { + if (quota.quota >= 200000) { const embed = new discord.EmbedBuilder() .setColor(0xFABBDE) .setAuthor({ name: "Quota exceeded", iconURL: client.user.displayAvatarURL() }) diff --git a/functions/discord/dalle.js b/functions/discord/dalle.js index 3fe8255..7b6429e 100644 --- a/functions/discord/dalle.js +++ b/functions/discord/dalle.js @@ -12,11 +12,11 @@ async function dalle (interaction, client) { addToLogs(err); }); - if (quota >= 200000) { + if (quota.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)") + .setDescription("You have a quota of " + quota.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] }); diff --git a/functions/discord/gptrequest.js b/functions/discord/gptrequest.js index 092f871..78b75fe 100644 --- a/functions/discord/gptrequest.js +++ b/functions/discord/gptrequest.js @@ -12,11 +12,11 @@ async function gptrequest(interaction, client) { addToLogs(err); }); - if (quota >= 200000) { + if (quota.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)") + .setDescription("You have a quota of " + quota.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] }); diff --git a/functions/discord/quickGptrequest.js b/functions/discord/quickGptrequest.js index 6e03c3d..f898026 100644 --- a/functions/discord/quickGptrequest.js +++ b/functions/discord/quickGptrequest.js @@ -12,11 +12,11 @@ async function quickGptrequest(interaction, client) { addToLogs(err); }); - if (quota >= 200000) { + if (quota.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)") + .setDescription("You have a quota of " + quota.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] });