chore: Add initial configuration files and code structure

This commit is contained in:
Bildcraft1 2024-06-05 22:06:30 +02:00
commit 127a7dc87f
13 changed files with 1761 additions and 0 deletions

View file

@ -0,0 +1,26 @@
const { Events } = require('discord.js');
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
},
};

51
events/messageCreate.js Normal file
View file

@ -0,0 +1,51 @@
const { Events } = require('discord.js');
const fs = require('fs');
const { exec } = require('child_process');
const { logAction } = require('../logs/logger.js'); // Import logAction
module.exports = {
name: Events.MessageCreate,
async execute(message) {
// Ignore messages sent by the bot itself
if (message.author.bot) return;
const config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
// Check if the message is a DM or if the bot is mentioned in a guild message
const isDM = message.guild === null;
const isMentioned = message.mentions.has(message.client.user);
if (isDM || isMentioned) {
// Get the content of the message and remove the bot mention if in a guild
const botMention = isDM ? '' : `<@${message.client.user.id}>`;
const messageContent = message.content.replace(botMention, '').trim();
// Log the message
console.log(`[LOG] User ${message.author.tag} asked: ${messageContent}`);
logAction(`${message.author.tag}: ${messageContent}`, message.author.id, message.author.tag);
if (config.whitelist.includes(message.author.id)) {
exec(`python3 bot.py "${messageContent}"`, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing script: ${error.message}`);
logAction(`GPT: ${error.message}`, message.author.id, message.author.tag);
return message.reply("There was an error processing your request.");
}
if (stderr) {
console.error(`Script error: ${stderr}`);
logAction(`GPT: ${stderr}`, message.author.id, message.author.tag);
return message.reply("There was an error processing your request.");
}
// Log the output from the Python script
logAction(`GPT: ${stdout.trim()}`, message.author.id, message.author.tag);
// Reply with the output from the Python script
message.reply(stdout.trim());
});
} else {
message.reply("Not whitelisted");
}
}
},
};

9
events/ready.js Normal file
View file

@ -0,0 +1,9 @@
const { Events } = require('discord.js');
module.exports = {
name: Events.ClientReady,
once: true,
execute(client) {
console.log(`Ready! Logged in as ${client.user.tag}`);
},
};