Skip to content

Commit

Permalink
fixed ALL in watchdog mode, housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBoombastic committed Mar 22, 2023
1 parent 817648c commit 5fec919
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 67 deletions.
30 changes: 30 additions & 0 deletions src/events/members/ready.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const {art, saveAndExit} = require("../../utils");
const {perms, overlap, bruteforce} = require("../../steps");
module.exports = async (client) => {
console.log(art.replace("$MODE", process.env.MODE));
console.log(`Logged in as ${client.user.tag} (${client.user?.emailAddress || "NO EMAIL"})`);

// Getting target
const guild = await client.guilds.cache.get(process.env.GUILD_ID);
if (!guild?.available) {
console.error("ERROR: selected guild is not available!\nAvailable guilds:", client.guilds.cache.map(x => `${x.name} (${x.id})`).join(", "));
process.exit(1);
}
const channel = await guild.channels.cache.get(process.env.CHANNEL_ID);
if (!channel) {
console.warn("WARNING: selected channel is missing! 'Member list' method will be skipped\nAvailable channels: ", guild.channels.cache.map(x => `${x.name} (${x.id})`).join(", "));
}

console.log(`Target acquired: ${guild.name} (${channel?.name || "NO CHANNEL"})`);

// Fetching!
await perms(guild); // Method 1 - fetching with perms
if (channel) await overlap(guild, client); // Method 2 - overlap member list fetching
if ((guild.members.cache.size < guild.memberCount) && (guild.members.cache.size !== guild.memberCount)) await bruteforce(guild); // Method 3 - brute-force fetching

// Done!
console.log(`Fetching done! Found ${guild.members.cache.size}/${guild.memberCount} => ${guild.members.cache.size / guild.memberCount * 100}% members.`);

await saveAndExit(client, guild);

};
13 changes: 13 additions & 0 deletions src/events/watchdog/messageDelete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const {downloadFile} = require("../../utils");
module.exports = async (client, message) => {
if (message.guildId === process.env.GUILD_ID || process.env.GUILD_ID.toLowerCase() === "all") {
let info = `DELETED MESSAGE: Guild: ${message.guild.name} Channel: ${message.channel.name} Author: ${message.author?.tag} Bot: ${message.author?.bot}\nCONTENT: ${message.cleanContent}`;
if (message.attachments.size > 0) {
info += `\nMEDIA: ${message.attachments.map(x => x.proxyURL).join(", ")}`;
message.attachments.forEach(x => {
downloadFile(x.proxyURL);
});
}
client.logger.info(info);
}
};
10 changes: 10 additions & 0 deletions src/events/watchdog/messageUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = async (client, oldMsg, newMsg) => {
if ((oldMsg.guildId === process.env.GUILD_ID || process.env.GUILD_ID.toLowerCase() === "all") && oldMsg.content !== newMsg.content) {
let info = `EDITED MESSAGE: Guild: ${oldMsg.guild.name} Channel: ${oldMsg.channel.name} Author: ${oldMsg.author?.tag} Bot: ${oldMsg.author?.bot}
OLD: ${oldMsg.content}
NEW: ${newMsg.content}`;
if (oldMsg.attachments.size > 0) info += `\nOLD MEDIA: ${newMsg.attachments.map(x => x.url).join(", ")}`;
if (newMsg.attachments.size > 0) info += `\nNEW MEDIA: ${newMsg.attachments.map(x => x.url).join(", ")}`;
client.logger.info(info);
}
};
18 changes: 18 additions & 0 deletions src/events/watchdog/ready.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const log4js = require("log4js");
const {art} = require("../../utils");
module.exports = async (client) => {
console.log(art.replace("$MODE", process.env.MODE));
console.log(`Logged in as ${client.user.tag} (${client.user?.emailAddress || "NO EMAIL"})`);

// Getting target
const info = process.env.GUILD_ID.toLowerCase() === "all" ? "ALL GUILDS" : await client.guilds.cache.get(process.env.GUILD_ID).name;
console.log(`Target acquired: ${info}`);

// Set up message logging
log4js.configure({
appenders: {watchdog: {type: "file", filename: `${process.env.GUILD_ID}.log`}},
categories: {default: {appenders: ["watchdog"], level: "info"}},
});

client.logger = log4js.getLogger("watchdog");
};
76 changes: 9 additions & 67 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
const {Client} = require("discord.js-selfbot-v13");
global.dayjs = require("dayjs");
dayjs.extend(require("dayjs/plugin/localizedFormat"));
const {saveAndExit, checkConfig, art, downloadFile} = require("./utils.js");
const {bruteforce, perms, overlap} = require("./steps.js");
const log4js = require("log4js");
const {saveAndExit, checkConfig} = require("./utils.js");
require('dotenv').config();


Expand Down Expand Up @@ -37,71 +35,15 @@ client.on("rateLimit", async (data) => {
console.log(data);
});

// When bot is ready
client.on("ready", async () => {
console.log(art.replace("$MODE", process.env.MODE));
console.log(`Logged in as ${client.user.tag} (${client.user?.emailAddress || "NO EMAIL"})`);
if (process.env.MODE === "WATCHDOG") {
// Getting target
const info = await client.guilds.cache.get(process.env.GUILD_ID);
console.log(`Target acquired: ${info.name}`);

// Set up message logging
log4js.configure({
appenders: {watchdog: {type: "file", filename: `${process.env.GUILD_ID}.log`}},
categories: {default: {appenders: ["watchdog"], level: "info"}},
});

global.logger = log4js.getLogger("watchdog");
} else if (process.env.MODE === "MEMBERS") {
// Getting target
guild = await client.guilds.cache.get(process.env.GUILD_ID);
if (!guild?.available) {
console.error("ERROR: selected guild is not available!\nAvailable guilds:", client.guilds.cache.map(x => `${x.name} (${x.id})`).join(", "));
process.exit(1);
}
const channel = await guild.channels.cache.get(process.env.CHANNEL_ID);
if (!channel) {
console.warn("WARNING: selected channel is missing! 'Member list' method will be skipped\nAvailable channels: ", guild.channels.cache.map(x => `${x.name} (${x.id})`).join(", "));
}

console.log(`Target acquired: ${guild.name} (${channel?.name || "NO CHANNEL"})`);

// Fetching!
await perms(guild); // Method 1 - fetching with perms
if (channel) await overlap(guild, client); // Method 2 - overlap member list fetching
if ((guild.members.cache.size < guild.memberCount) && (guild.members.cache.size !== guild.memberCount)) await bruteforce(guild); // Method 3 - brute-force fetching

// Done!
console.log(`Fetching done! Found ${guild.members.cache.size}/${guild.memberCount} => ${guild.members.cache.size / guild.memberCount * 100}% members.`);

await saveAndExit(client, guild);
}
});

client.on("messageDelete", message => {
if (message.guildId === process.env.GUILD_ID || process.env.GUILD_ID === "ALL") {
let info = `DELETED MESSAGE: Guild: ${message.guild.name} Channel: ${message.channel.name} Author: ${message.author.tag} Bot: ${message.author.bot}\nCONTENT: ${message.cleanContent}`;
if (message.attachments.size > 0) {
info += `\nMEDIA: ${message.attachments.map(x => x.proxyURL).join(", ")}`;
message.attachments.forEach(x => {
downloadFile(x.proxyURL);
});
}
logger.info(info);
}
});
// For some reason, I can't get vercel/pkg to work. Using this workaround instead.
if (process.env.MODE === "WATCHDOG") {
client.on("messageDelete", require("./events/watchdog/messageDelete.js").bind(null, client));
client.on("messageUpdate", require("./events/watchdog/messageUpdate.js").bind(null, client));
client.on("ready", require("./events/watchdog/ready.js").bind(null, client));
} else if (process.env.MODE === "MEMBERS") {
client.on("ready", require("./events/members/ready.js").bind(null, client));
}

client.on("messageUpdate", (oldMsg, newMsg) => {
if ((oldMsg.guildId === process.env.GUILD_ID || process.env.GUILD_ID === "ALL") && oldMsg.content !== newMsg.content) {
let info = `EDITED MESSAGE: Guild: ${oldMsg.guild.name} Channel: ${oldMsg.channel.name} Author: ${oldMsg.author?.tag} Bot: ${oldMsg.author?.bot}
OLD: ${oldMsg.content}
NEW: ${newMsg.content}`;
if (oldMsg.attachments.size > 0) info += `\nOLD MEDIA: ${newMsg.attachments.map(x => x.url).join(", ")}`;
if (newMsg.attachments.size > 0) info += `\nNEW MEDIA: ${newMsg.attachments.map(x => x.url).join(", ")}`;
logger.info(info);
}
});

process.on("SIGINT", async () => {
console.log("\nStopped upon user's request!");
Expand Down

0 comments on commit 5fec919

Please sign in to comment.