From 6123ac25823e942ff928ffd9a95490f5292ccfe7 Mon Sep 17 00:00:00 2001 From: sky Date: Fri, 12 Jan 2024 19:07:46 -0500 Subject: [PATCH] link leaker shit --- .gitignore | 4 +- commands/moderation/linkLeakerChecker.js | 60 ++++++++++++++++++++++++ events/guildMemberAdd.js | 35 ++++++++++++++ index.js | 2 +- 4 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 commands/moderation/linkLeakerChecker.js create mode 100644 events/guildMemberAdd.js diff --git a/.gitignore b/.gitignore index 332b98d..9ec72a7 100644 --- a/.gitignore +++ b/.gitignore @@ -131,4 +131,6 @@ dist .yarn/unplugged .yarn/build-state.yml .yarn/install-state.gz -.pnp.* \ No newline at end of file +.pnp.* + +leakers.json \ No newline at end of file diff --git a/commands/moderation/linkLeakerChecker.js b/commands/moderation/linkLeakerChecker.js new file mode 100644 index 0000000..ae83e45 --- /dev/null +++ b/commands/moderation/linkLeakerChecker.js @@ -0,0 +1,60 @@ +const { EmbedBuilder, SlashCommandBuilder, PermissionsBitField } = require("discord.js"); +const { logs_channel } = require("../../config.json"); +const fs = require("fs"); + +module.exports = { + data: new SlashCommandBuilder().setName("linkleakerchecker").setDescription("Checks if a user is a known link leaker"), + async execute(interaction) { + try { + if (!interaction.channel.permissionsFor(interaction.user).has(PermissionsBitField.Flags.ManageRoles)) { + await interaction.reply({ content: "You do not have the correct permissions.", ephemeral: true }); + return; + } + const client = interaction.client; + 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"; + + https.get(url, (res) => { + const path = "leakers.json"; + const writeStream = fs.createWriteStream(path); + + res.pipe(writeStream); + + writeStream.on("finish", () => { + writeStream.close(); + }); + }); + } + 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 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 new file mode 100644 index 0000000..437408a --- /dev/null +++ b/events/guildMemberAdd.js @@ -0,0 +1,35 @@ +const { Events } = require("discord.js"); +const https = require("https"); +const fs = require("fs"); +const { logs_channel } = require("../config.json"); + +module.exports = { + name: Events.GuildMemberAdd, + async execute(interaction) { + 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"; + + https.get(url, (res) => { + const path = "leakers.json"; + const writeStream = fs.createWriteStream(path); + + res.pipe(writeStream); + + writeStream.on("finish", () => { + writeStream.close(); + }); + }); + } + let leakers = fs.readFileSync("leakers.json", { encoding: "utf8", flag: "r" }); + leakers = JSON.parse(leakers); + if (leakers.includes(interaction.user.id)) { + const leak = interaction.guild.members.cache.get(interaction.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()); + await logsChannel.send(`Known link leaker ${interaction.user.tag} joined the server.`); + } + }, +}; diff --git a/index.js b/index.js index deacf63..9c04e86 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const fs = require("node:fs"); const path = require("node:path"); const { Client, Collection, GatewayIntentBits, Events } = require("discord.js"); const { token, widgets, logs_channel, links, dispenser_logs } = require("./config.json"); -const client = new Client({ intents: ["Guilds", "GuildMessages", "MessageContent"], allowedMentions: { everyone: [false], roles: [false] } }); +const client = new Client({ intents: ["Guilds", "GuildMessages", "GuildMembers", "MessageContent"], allowedMentions: { everyone: [false], roles: [false] } }); const Sequelize = require("sequelize"); const level = new Sequelize("database", "user", "password", { host: "localhost",