diff --git a/src/events/client/ready.js b/src/events/client/ready.js index 0ea62f6..778e22f 100644 --- a/src/events/client/ready.js +++ b/src/events/client/ready.js @@ -9,10 +9,6 @@ module.exports = { // Register Commands const register = require("../../scripts/client-register"); await register(client); - - // Cleanup Database - const cleanDB = require("../../util/database/clean"); - await cleanDB(client, Discord); } catch(err) { client.logEventError(err); } diff --git a/src/util/database/clean.js b/src/util/database/clean.js deleted file mode 100644 index f4d108b..0000000 --- a/src/util/database/clean.js +++ /dev/null @@ -1,53 +0,0 @@ -module.exports = async function (client, Discord) { - const logsChannel = client.guilds.cache.get(client.config_channels.logs); - - // Banned Users - const cleanBannedUsers = require("./cleanBannedUsers"); - const bannedUsersRes = await cleanBannedUsers(client); - - const bannedUsersResult = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) - .setAuthor({ name: client.user.tag.endsWith("#0") ? client.user.username : client.user.tag, iconURL: client.user.displayAvatarURL({ format: "png", dynamic: true }), url: `https://discord.com/users/${client.user.id}` }) - .setTitle("๐Ÿงน Collection Cleanup") - .setDescription("`banned-users`") - .addFields ( - { name: "๐Ÿ—‘๏ธ Removed Documents", value: bannedUsersRes.removed.length ? `\`\`\`${bannedUsersRes.removed.join("\n")}\`\`\`` : "*None*" } - ) - .setTimestamp() - - if(bannedUsersRes.removed.length) logsChannel.send({ embeds: [bannedUsersResult] }); - - // Filter - const cleanFilter = require("./cleanFilter"); - const filterRes = await cleanFilter(); - - const filterResult = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) - .setAuthor({ name: client.user.tag.endsWith("#0") ? client.user.username : client.user.tag, iconURL: client.user.displayAvatarURL({ format: "png", dynamic: true }), url: `https://discord.com/users/${client.user.id}` }) - .setTitle("๐Ÿงน Collection Cleanup") - .setDescription("`filter`") - .addFields ( - { name: "๐Ÿ“ Modified Documents", value: filterRes.modified.length ? `\`\`\`${filterRes.modified.join("\n")}\`\`\`` : "*None*" }, - { name: "๐Ÿ—‘๏ธ Removed Documents", value: filterRes.removed.length ? `\`\`\`${filterRes.removed.join("\n")}\`\`\`` : "*None*" } - ) - .setTimestamp() - - if(filterRes.modified.length || filterRes.removed.length) logsChannel.send({ embeds: [filterResult] }); - - // Guilds - const cleanGuilds = require("./cleanGuilds"); - const guildsRes = await cleanGuilds(client); - - const guildsResult = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) - .setAuthor({ name: client.user.tag.endsWith("#0") ? client.user.username : client.user.tag, iconURL: client.user.displayAvatarURL({ format: "png", dynamic: true }), url: `https://discord.com/users/${client.user.id}` }) - .setTitle("๐Ÿงน Collection Cleanup") - .setDescription("`guilds`") - .addFields ( - { name: "๐Ÿ“ Modified Documents", value: guildsRes.modified.length ? `\`\`\`${guildsRes.modified.join("\n")}\`\`\`` : "*None*" }, - { name: "๐Ÿ—‘๏ธ Removed Documents", value: guildsRes.removed.length ? `\`\`\`${guildsRes.removed.join("\n")}\`\`\`` : "*None*" } - ) - .setTimestamp() - - if(guildsRes.modified.length || guildsRes.removed.length) logsChannel.send({ embeds: [guildsResult] }); -} diff --git a/src/util/database/cleanBannedUsers.js b/src/util/database/cleanBannedUsers.js deleted file mode 100644 index b457eba..0000000 --- a/src/util/database/cleanBannedUsers.js +++ /dev/null @@ -1,30 +0,0 @@ -module.exports = async function cleanChannels(client) { - const bannedUserSchema = require("../../models/bannedUserSchema"); - - const data = await bannedUserSchema.find(); - - const promises = []; - - const removedData = []; - - // Remove Invalid Users - for(const document of data) { - promises.push(new Promise(async resolve => { - try { - await client.users.fetch(document._id); - resolve(); - } catch { - await bannedUserSchema.findOneAndDelete({ _id: document._id }); - - removedData.push(document._id); - resolve(`Deleted: ${document._id}`); - } - })) - } - - await Promise.all(promises); - - return { - "removed": removedData - } -} diff --git a/src/util/database/cleanFilter.js b/src/util/database/cleanFilter.js deleted file mode 100644 index 51db0b7..0000000 --- a/src/util/database/cleanFilter.js +++ /dev/null @@ -1,44 +0,0 @@ -module.exports = async function cleanChannels() { - const filterSchema = require("../../models/filterSchema"); - - const autobanData = await filterSchema.findOne({ _id: "autoban" }) || { words: [] }; - const blacklistData = await filterSchema.findOne({ _id: "blacklist" }) || { words: [] }; - - const promises = []; - - let modifiedData = []; - const removedData = []; - - for(const word of autobanData.words) { - promises.push(new Promise(async resolve => { - if(blacklistData.words.includes(word)) { - blacklistData.words = blacklistData.words.filter(item => item !== word); - - await blacklistData.save(); - - if(!modifiedData.includes("blacklist")) modifiedData.push("blacklist"); - - resolve(`Modified: blacklist`); - } else { - resolve(); - } - })) - } - - await Promise.all(promises); - - if(!autobanData.words.length && autobanData._id) { - await autobanData.delete(); - removedData.push("autoban"); - } - - if(!blacklistData.words.length && blacklistData._id) { - await blacklistData.delete(); - removedData.push("blacklist"); - } - - return { - "modified": modifiedData.filter(item => !removedData.includes(item)), - "removed": removedData - } -} diff --git a/src/util/database/cleanGuilds.js b/src/util/database/cleanGuilds.js deleted file mode 100644 index 1117ede..0000000 --- a/src/util/database/cleanGuilds.js +++ /dev/null @@ -1,59 +0,0 @@ -module.exports = async function cleanChannels(client) { - const guildSchema = require("../../models/guildSchema"); - const checkWebhook = require("../checkWebhook"); - - const data = await guildSchema.find(); - - const promises = []; - - const validGuilds = []; - let modifiedData = []; - const removedData = []; - - // Valid Guilds - for(const [guildId, guild] of client.guilds.cache) { - promises.push(new Promise(async resolve => { - validGuilds.push(guildId); - resolve(); - })) - } - - // Remove Invalid Guilds - for(const document of data) { - promises.push(new Promise(async resolve => { - if(validGuilds.includes(document._id)) return resolve(); - - await guildSchema.findOneAndDelete({ _id: document._id }); - - removedData.push(document._id); - resolve(`Deleted: ${document._id}`); - })) - } - - // Check Webhooks - for(const document of data) { - promises.push(new Promise(async resolve => { - if(document.webhook) { - if(!(await checkWebhook(document.webhook))) { - await guildSchema.findOneAndUpdate({ _id: document._id }, { webhook: null }); - - modifiedData.push(document._id); - resolve(`Modified: ${document._id}`); - return; - } - - resolve(); - return; - } - - resolve(); - })) - } - - await Promise.all(promises); - - return { - "modified": modifiedData.filter(item => !removedData.includes(item)), - "removed": removedData - } -}