From 2b2581de351cf5734ed5b2bf0ee30a95066e2919 Mon Sep 17 00:00:00 2001 From: sky Date: Fri, 19 Jan 2024 11:45:23 -0500 Subject: [PATCH] use new leakers database --- commands/moderation/linkLeakerChecker.js | 66 ++++++++++++++---------- events/guildMemberAdd.js | 21 +++++--- 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/commands/moderation/linkLeakerChecker.js b/commands/moderation/linkLeakerChecker.js index 2438ad8..b63fbe3 100644 --- a/commands/moderation/linkLeakerChecker.js +++ b/commands/moderation/linkLeakerChecker.js @@ -1,5 +1,6 @@ const { EmbedBuilder, SlashCommandBuilder, PermissionsBitField } = require("discord.js"); const { logs_channel } = require("../../config.json"); +const https = require("https"); const fs = require("fs"); module.exports = { @@ -14,44 +15,53 @@ module.exports = { let members = await interaction.guild.members.fetch(); const { mtimeMs } = fs.statSync("leakers.json"); if (Date.now() - mtimeMs > 43200000) { - const url = "https://leakersapi.rare1k.dev/ids"; + const url = "https://raw.githubusercontent.com/fidind3211/LinkGuard/master/Leakers.md"; https.get(url, (res) => { - const path = "leakers.json"; - const writeStream = fs.createWriteStream(path); + let data = ""; // Collect the response data + res.on("data", (chunk) => { + data += chunk; + }); - res.pipe(writeStream); + res.on("end", () => { + leakers = []; + data + .split("\n") + .filter((e) => e.startsWith("<@!")) + .forEach((line) => { + leakers.push(line.split(" | ")[0].substring(3).slice(0, -1)); + }); - writeStream.on("finish", () => { - writeStream.close(); + const path = "leakers.json"; + fs.writeFileSync(path, JSON.stringify(leakers)); }); }); } let leakers = fs.readFileSync("leakers.json", { encoding: "utf8", flag: "r" }); leakers = JSON.parse(leakers); - let foundLeakers = []; - for (let i = 0; i < leakers.length; i++) { - foundLeakers.push([leakers[i], false, false]); - } - members.forEach((member) => { - if (leakers.includes(member.user.id)) { - foundLeakers[leakers.indexOf(member.user.id)][1] = true; - if(!member.roles.cache.some(role => role.name === 'link leakers')) { - foundLeakers[leakers.indexOf(member.user.id)][2] = true; - const leak = interaction.guild.members.cache.get(member.user.id); - let leakerRole = interaction.guild.roles.cache.find((role) => role.name === "link leakers"); - leak.roles.add(leakerRole); - const logsChannel = interaction.client.channels.cache.get(logs_channel.toString()); - logsChannel.send(`${member.user.tag} was detected as a link leaker.`); - } - } + let foundLeakers = []; + for (let i = 0; i < leakers.length; i++) { + foundLeakers.push([leakers[i], false, false]); + } + members.forEach((member) => { + if (leakers.includes(member.user.id)) { + foundLeakers[leakers.indexOf(member.user.id)][1] = true; + if (!member.roles.cache.some((role) => role.name === "link leakers")) { + foundLeakers[leakers.indexOf(member.user.id)][2] = true; + const leak = interaction.guild.members.cache.get(member.user.id); + let leakerRole = interaction.guild.roles.cache.find((role) => role.name === "link leakers"); + leak.roles.add(leakerRole); + const logsChannel = interaction.client.channels.cache.get(logs_channel.toString()); + logsChannel.send(`${member.user.tag} was detected as a link leaker.`); + } + } }); - let embedDesc = "Results:\nUser - Found - Role Added\n"; - for(let i = 0; i < foundLeakers.length; i++) { - embedDesc += `<@${foundLeakers[i][0]}> - ${foundLeakers[i][1]} - ${foundLeakers[i][2]}\n`; - } - let leakEmbed = new EmbedBuilder().setTitle("Link Leakers").setDescription(embedDesc); - await interaction.reply({ embeds: [leakEmbed] }); + let embedDesc = "Results:\nUser - Found - Role Added\n"; + for (let i = 0; i < foundLeakers.length; i++) { + embedDesc += `<@${foundLeakers[i][0]}> - ${foundLeakers[i][1]} - ${foundLeakers[i][2]}\n`; + } + let leakEmbed = new EmbedBuilder().setTitle("Link Leakers").setDescription(embedDesc); + await interaction.reply({ embeds: [leakEmbed] }); } catch (error) { console.error(error); await interaction.reply({ content: "There was an error", ephemeral: true }); diff --git a/events/guildMemberAdd.js b/events/guildMemberAdd.js index 437408a..fa14d4b 100644 --- a/events/guildMemberAdd.js +++ b/events/guildMemberAdd.js @@ -9,16 +9,25 @@ module.exports = { console.log(interaction.user.id + " joined the server."); const { mtimeMs } = fs.statSync("leakers.json"); if (Date.now() - mtimeMs > 43200000) { - const url = "https://leakersapi.rare1k.dev/ids"; + const url = "https://raw.githubusercontent.com/fidind3211/LinkGuard/master/Leakers.md"; https.get(url, (res) => { - const path = "leakers.json"; - const writeStream = fs.createWriteStream(path); + let data = ""; // Collect the response data + res.on("data", (chunk) => { + data += chunk; + }); - res.pipe(writeStream); + res.on("end", () => { + leakers = []; + data + .split("\n") + .filter((e) => e.startsWith("<@!")) + .forEach((line) => { + leakers.push(line.split(" | ")[0].substring(3).slice(0, -1)); + }); - writeStream.on("finish", () => { - writeStream.close(); + const path = "leakers.json"; + fs.writeFileSync(path, JSON.stringify(leakers)); }); }); }