diff --git a/commands/honeypot/honey-pot-data.js b/commands/honeypot/honey-pot-data.js new file mode 100644 index 0000000..436ff5f --- /dev/null +++ b/commands/honeypot/honey-pot-data.js @@ -0,0 +1,38 @@ +const { SlashCommandBuilder, PermissionFlagsBits, Client, GatewayIntentBits } = require('discord.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('honeypot') + .setDescription('comandi per vedere i dati del honeypot, mostrera, una lista di bannati per il honeypot') + .addSubcommand(subcommand => + subcommand.setName('bannati') + .setDescription('mostra una lista di bannati per il honeypot') + ) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), + + + async execute(interaction) { + const subcommand = interaction.options.getSubcommand(); + + if (subcommand === 'bannati') { + + const guild = interaction.guild; + + try { + + const bannati = await guild.bans.fetch(); + const filteredBannati = bannati.filter(member => member.reason === 'Honeypot triggered - Suspected bot/malicious activity'); + + // TODO: to format with embed + const bannatiList = filteredBannati.map(member => member.user.tag).join('\n'); + await interaction.reply(`Lista dei bannati per il honeypot:\n${bannatiList}`); + + const channelLog = interaction.guild.channels.cache.get('1396529523058802838'); + channelLog.send(`Lista dei bannati per il honeypot:\n${bannatiList}, id: ${interaction.guild.id}, timestamp: ${new Date().toISOString()}`); + + } catch (error) { + console.error('Error fetching banned members:', error); + } + } + } +}; diff --git a/events/honeypot/honey-pot.js b/events/honeypot/honey-pot.js new file mode 100644 index 0000000..0d121c5 --- /dev/null +++ b/events/honeypot/honey-pot.js @@ -0,0 +1,104 @@ +// create a channel honeypot +// if someone write on it, ban instantly the one that write on it +const { EmbedBuilder } = require('discord.js'); + +const channelHoneypot = '1396509303380381816'; +const channelLog = '1396516358879055962'; + +// add emoticon for kill streak, and other things, to refactor because +// it just delete the infomessagehoneypot +const infoHoneypot = (message, channel, bannedNumber) => { + const channelMessage = message.client.channels.cache.get(channel); + + const embed = new EmbedBuilder() + .setColor('#ff0000') + .setTitle('⚠️ Honeypot Alert - Info ⚠️') + .setDescription(`Benvenuti nel canale Honeypot! Questo canale è progettato per rilevare e gestire attività sospette. Se qualcuno invia un messaggio qui, verrà automaticamente bannato. Si prega di non inviare messaggi in questo canale a meno che non si desideri essere bannati. \nkillstreak: ${bannedNumber}`) + .setTimestamp(); + + channelMessage.send({ embeds: [embed] }); +}; + +/** + * + * send a embeded message in the channel honeypot + * + */ +const embedTheMessage = (message, channel) => { + const channelMessage = message.guild.channels.cache.get(channel); + + const embed = new EmbedBuilder() + .setColor('#ff0000') + .setTitle('Honeypot Alert') + .setDescription(`**User:** ${message.author.tag} (${message.author.id})\n**Message:** ${message.content}`) + .setThumbnail(message.author.displayAvatarURL({ dynamic: true })) + .setTimestamp(); + + channelMessage.send({ embeds: [embed] }); +}; + +/** + * + * send a embeded message in the channel log + * we need this to track how sended the message this + * + */ +const embedTheLog = (message, channel) => { + const channelMessage = message.guild.channels.cache.get(channel); + + const embed = new EmbedBuilder() + .setColor('#ff0000') + .setTitle('Honeypot Alert - Log') + .setDescription(`**User:** ${message.author.tag} (${message.author.id})\n**Message:** ${message.content}`) + .setThumbnail(message.author.displayAvatarURL({ dynamic: true })) + .setTimestamp(); + + channelMessage.send({ embeds: [embed] }); +}; + + +module.exports = { + name: 'messageCreate', + async execute(message) { + + + if (message.channel.id === channelHoneypot) { + + // this perche' se il messaggio e' del bot, non faccio nulla + if (message.author.bot) return; + + try { + + + // send the message in the channel honeypot + embedTheMessage(message, channelHoneypot); + + // banna l'utente e assegna il ruolo + await message.member.ban({ + reason: 'Honeypot triggered - Suspected bot/malicious activity' + }); + + // send the message in the channel log + embedTheLog(message, channelLog); + + // delete the message + await message.delete(); + + // fetch bannati + const guild = message.guild; + const bannati = await guild.bans.fetch(); + const bannedNumber = bannati.size; + + // clear recent messages and show info + const honeypotChannel = message.guild.channels.cache.get(channelHoneypot); + + await honeypotChannel.bulkDelete(10).then(() => { + infoHoneypot(message, channelHoneypot, bannedNumber); + }); + + } catch (error) { + console.error('Error in honeypot ban:', error); + } + } + }, +}; diff --git a/index.js b/index.js index 45fe3e2..9467666 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,28 @@ const client = new Client({ client.commands = new Collection(); +// load events +const eventsPath = path.join(__dirname, 'events'); +const eventFolders = fs.readdirSync(eventsPath); + +for (const folder of eventFolders) { + console.log(`Loading events from ${folder}`); + const eventPath = path.join(eventsPath, folder); + const eventFiles = fs.readdirSync(eventPath); + + for (const file of eventFiles) { + console.log(`Loading event ${file}`); + const filePath = path.join(eventPath, file); + const event = require(filePath); + if (event.once) { + client.once(event.name, (...args) => event.execute(...args, client)); + } else { + client.on(event.name, (...args) => event.execute(...args, client)); + } + } +} + +// load commands const foldersPath = path.join(__dirname, 'commands'); const commandFolders = fs.readdirSync(foldersPath); diff --git a/package-lock.json b/package-lock.json index deb2114..de85ac6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -419,9 +419,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "24.0.14", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.0.14.tgz", - "integrity": "sha512-4zXMWD91vBLGRtHK3YbIoFMia+1nqEz72coM42C5ETjnNCa/heoj7NT1G67iAfOqMmcfhuCZ4uNpyz8EjlAejw==", + "version": "24.0.15", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.0.15.tgz", + "integrity": "sha512-oaeTSbCef7U/z7rDeJA138xpG3NuKc64/rZ2qmUFkFJmnMsAPaluIifqyWd8hSSMxyP9oie3dLAqYPblag9KgA==", "license": "MIT", "dependencies": { "undici-types": "~7.8.0"