Skip to content

Commit

Permalink
use new leakers database
Browse files Browse the repository at this point in the history
  • Loading branch information
skysthelimitt committed Jan 19, 2024
1 parent 4f21e68 commit 2b2581d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 34 deletions.
66 changes: 38 additions & 28 deletions commands/moderation/linkLeakerChecker.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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 });
Expand Down
21 changes: 15 additions & 6 deletions events/guildMemberAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
}
Expand Down

0 comments on commit 2b2581d

Please sign in to comment.