From 6e73e504a53f9b2f3829b5f6afbdd2995ffb43d9 Mon Sep 17 00:00:00 2001 From: "Jonny_Bro (Nikita)" Date: Fri, 24 May 2024 23:11:03 +0500 Subject: [PATCH] rename findOrCreate*Something* functions to get*Something*Data --- base/Client.js | 14 ++--- commands/!DISABLED/memes.js | 2 +- commands/Administration/selectroles.js | 2 +- commands/Administration/set.js | 2 +- commands/Economy/achievements.js | 2 +- commands/Economy/divorce.js | 2 +- commands/Economy/marry.js | 2 +- commands/Economy/money.js | 4 +- commands/Economy/pay.js | 2 +- commands/Economy/profile.js | 6 +- commands/Economy/rep.js | 2 +- commands/Economy/rob.js | 2 +- commands/Fun/number.js | 2 +- commands/Fun/tictactoe.js | 2 +- commands/General/boosters.js | 2 +- commands/General/help.js | 2 +- commands/General/reminds.js | 4 +- commands/Moderation/clearwarns.js | 2 +- commands/Moderation/warn.c.js | 2 +- commands/Moderation/warns.js | 2 +- commands/Music/nowplaying.js | 2 +- commands/Music/queue.js | 2 +- commands/NSFW/nsfw.js | 2 +- commands/Owner/debug.js | 8 +-- commands/Tickets/createticketembed.js | 2 +- dashboard/settings.js | 76 +++++++++++++------------- events/CommandHandler.js | 6 +- events/Guild/guildCreate.js | 2 +- events/Guild/guildMemberAdd.js | 2 +- events/Guild/guildMemberRemove.js | 2 +- events/Guild/guildMemberUpdate.js | 2 +- events/MessageHandler.js | 8 +-- helpers/birthdays.js | 4 +- 33 files changed, 89 insertions(+), 89 deletions(-) diff --git a/base/Client.js b/base/Client.js index 6884973b..e3c0750f 100644 --- a/base/Client.js +++ b/base/Client.js @@ -304,11 +304,11 @@ class JaBaClient extends Client { } /** - * Finds or creates a user in the database based on the provided user ID. + * Returns a User data from the database. * @param {string} userID - The ID of the user to find or create. * @returns {Promise} The user data object, either retrieved from the database or newly created. */ - async findOrCreateUser(userID) { + async getUserData(userID) { let userData = await this.usersData.findOne({ id: userID }); if (userData) { @@ -327,12 +327,12 @@ class JaBaClient extends Client { } /** - * Finds or creates a member in the database based on the provided member ID and guild ID. + * Returns a Member data from the database. * @param {string} memberId - The ID of the member to find or create. * @param {string} guildId - The ID of the guild the member belongs to. * @returns {Promise} The member data object, either retrieved from the database or newly created. */ - async findOrCreateMember(memberId, guildId) { + async getMemberData(memberId, guildId) { let memberData = await this.membersData.findOne({ guildID: guildId, id: memberId }); if (memberData) { @@ -344,7 +344,7 @@ class JaBaClient extends Client { await memberData.save(); - const guildData = await this.findOrCreateGuild(guildId); + const guildData = await this.getGuildData(guildId); if (guildData) { guildData.members.push(memberData._id); @@ -359,11 +359,11 @@ class JaBaClient extends Client { } /** - * Finds or creates a guild in the database based on the provided guild ID. + * Returns a Guild data from the database. * @param {string} guildId - The ID of the guild to find or create. * @returns {Promise} The guild data object, either retrieved from the database or newly created. */ - async findOrCreateGuild(guildId) { + async getGuildData(guildId) { let guildData = await this.guildsData.findOne({ id: guildId }).populate("members"); if (guildData) { diff --git a/commands/!DISABLED/memes.js b/commands/!DISABLED/memes.js index f2caf243..4090cc59 100644 --- a/commands/!DISABLED/memes.js +++ b/commands/!DISABLED/memes.js @@ -33,7 +33,7 @@ class Memes extends BaseCommand { if (interaction.customId === "memes_select") { interaction.deferUpdate(); - interaction.guild.data = await client.findOrCreateGuild(interaction.guildId); + interaction.guild.data = await client.getGuildData(interaction.guildId); const tag = interaction.values[0]; const res = await fetch(`https://meme-api.com/gimme/${tag}`).then(response => response.json()); diff --git a/commands/Administration/selectroles.js b/commands/Administration/selectroles.js index a7c9939d..de1363e0 100644 --- a/commands/Administration/selectroles.js +++ b/commands/Administration/selectroles.js @@ -90,7 +90,7 @@ class Selectroles extends BaseCommand { if (interaction.customId === "auto_roles") { interaction.data = []; - interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); + interaction.data.guild = await client.getGuildData(interaction.guildId); const removed = interaction.component.options.filter(option => { return !interaction.values.includes(option.value); diff --git a/commands/Administration/set.js b/commands/Administration/set.js index 29a42b99..9fff34b4 100644 --- a/commands/Administration/set.js +++ b/commands/Administration/set.js @@ -68,7 +68,7 @@ class Set extends BaseCommand { member = interaction.options.getMember("user"); if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true }); - const memberData = await client.findOrCreateMember(member.id, interaction.guildId); + const memberData = await client.getMemberData(member.id, interaction.guildId); const int = interaction.options.getInteger("int"); if (int < 0) return interaction.error("administration/set:INVALID_NUMBER", null, { ephemeral: true }); diff --git a/commands/Economy/achievements.js b/commands/Economy/achievements.js index 482d630c..0c9dc8d3 100644 --- a/commands/Economy/achievements.js +++ b/commands/Economy/achievements.js @@ -39,7 +39,7 @@ class Achievements extends BaseCommand { const user = interaction.options.getUser("user") || interaction.member; if (user.bot) return interaction.error("economy/profile:BOT_USER"); - const userData = user.id === interaction.user.id ? interaction.data.user : await client.findOrCreateUser(user.id); + const userData = user.id === interaction.user.id ? interaction.data.user : await client.getUserData(user.id); const embed = client.embed({ author: { diff --git a/commands/Economy/divorce.js b/commands/Economy/divorce.js index 18ec69d9..317b6f46 100644 --- a/commands/Economy/divorce.js +++ b/commands/Economy/divorce.js @@ -36,7 +36,7 @@ class Divorce extends BaseCommand { await userData.save(); - const oldLover = await client.findOrCreateUser(user.id); + const oldLover = await client.getUserData(user.id); oldLover.lover = null; await oldLover.save(); diff --git a/commands/Economy/marry.js b/commands/Economy/marry.js index 46724b1f..a03a6673 100644 --- a/commands/Economy/marry.js +++ b/commands/Economy/marry.js @@ -46,7 +46,7 @@ class Marry extends BaseCommand { if (member.user.bot) return interaction.error("economy/marry:BOT_USER"); if (member.id === interaction.member.id) return interaction.error("economy/marry:YOURSELF"); - const otherUserData = await client.findOrCreateUser(member.id); + const otherUserData = await client.getUserData(member.id); if (otherUserData.lover) return interaction.error("economy/marry:ALREADY_MARRIED_USER", { user: member.toString() }); for (const requester in pendings) { diff --git a/commands/Economy/money.js b/commands/Economy/money.js index 92ff26ae..6d96e105 100644 --- a/commands/Economy/money.js +++ b/commands/Economy/money.js @@ -41,13 +41,13 @@ class Money extends BaseCommand { const member = interaction.options.getMember("user") || interaction.member; if (member.user.bot) return interaction.error("economy/money:BOT_USER"); - const memberData = member.id === interaction.user.id ? interaction.data.member : await client.findOrCreateMember(member.id, interaction.guildId); + const memberData = member.id === interaction.user.id ? interaction.data.member : await client.getMemberData(member.id, interaction.guildId); const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id)); let globalMoney = 0; await client.functions.asyncForEach(guilds, async guild => { - const data = await client.findOrCreateMember(member.id, guild.id); + const data = await client.getMemberData(member.id, guild.id); globalMoney += data.money + data.bankSold; }); diff --git a/commands/Economy/pay.js b/commands/Economy/pay.js index de016276..d79b127a 100644 --- a/commands/Economy/pay.js +++ b/commands/Economy/pay.js @@ -59,7 +59,7 @@ class Pay extends BaseCommand { amount: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDITS:1"), interaction.translate("misc:NOUNS:CREDITS:2"), interaction.translate("misc:NOUNS:CREDITS:5"))}`, }); - const otherMemberData = await client.findOrCreateMember(otherMember.id, interaction.guildId); + const otherMemberData = await client.getMemberData(otherMember.id, interaction.guildId); memberData.money -= amount; otherMemberData.money += amount; diff --git a/commands/Economy/profile.js b/commands/Economy/profile.js index 5ad81bf9..996778bc 100644 --- a/commands/Economy/profile.js +++ b/commands/Economy/profile.js @@ -41,14 +41,14 @@ class Profile extends BaseCommand { const member = interaction.options.getMember("user") || interaction.member; if (member.user.bot) return interaction.error("economy/profile:BOT_USER"); - const memberData = member.id === interaction.user.id ? interaction.data.member : await client.findOrCreateMember(member.id, interaction.guildId); - const userData = member.id === interaction.user.id ? interaction.data.user : await client.findOrCreateUser(member.id); + const memberData = member.id === interaction.user.id ? interaction.data.member : await client.getMemberData(member.id, interaction.guildId); + const userData = member.id === interaction.user.id ? interaction.data.user : await client.getUserData(member.id); if (userData.lover && !client.users.cache.find(u => u.id === userData.lover)) await client.users.fetch(userData.lover, true); const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id)); let globalMoney = 0; await client.functions.asyncForEach(guilds, async guild => { - const data = await client.findOrCreateMember(member.id, guild.id); + const data = await client.getMemberData(member.id, guild.id); globalMoney += data.money + data.bankSold; }); diff --git a/commands/Economy/rep.js b/commands/Economy/rep.js index 4d6c5c61..760304c0 100644 --- a/commands/Economy/rep.js +++ b/commands/Economy/rep.js @@ -56,7 +56,7 @@ class Rep extends BaseCommand { userData.cooldowns.rep = toWait; - const otherUserData = await client.findOrCreateUser(user.id); + const otherUserData = await client.getUserData(user.id); otherUserData.rep++; diff --git a/commands/Economy/rob.js b/commands/Economy/rob.js index 9a6946ba..7890c431 100644 --- a/commands/Economy/rob.js +++ b/commands/Economy/rob.js @@ -55,7 +55,7 @@ class Rob extends BaseCommand { const amount = interaction.options.getInteger("amount"); if (amount <= 0) return interaction.error("misc:MORE_THAN_ZERO"); - const otherMemberData = await client.findOrCreateMember(otherMember.id, interaction.guildId); + const otherMemberData = await client.getMemberData(otherMember.id, interaction.guildId); if (amount > otherMemberData.money) return interaction.error("economy/rob:NOT_ENOUGH_MEMBER", { user: otherMember.toString() }); const isInCooldown = otherMemberData.cooldowns.rob || 0; diff --git a/commands/Fun/number.js b/commands/Fun/number.js index d9108ee0..d751b26b 100644 --- a/commands/Fun/number.js +++ b/commands/Fun/number.js @@ -80,7 +80,7 @@ class Number extends BaseCommand { }), }); - const memberData = await client.findOrCreateMember(msg.author.id, interaction.guildId); + const memberData = await client.getMemberData(msg.author.id, interaction.guildId); memberData.money += won; diff --git a/commands/Fun/tictactoe.js b/commands/Fun/tictactoe.js index 7584bdf6..32c20dcd 100644 --- a/commands/Fun/tictactoe.js +++ b/commands/Fun/tictactoe.js @@ -43,7 +43,7 @@ class TicTacToe extends BaseCommand { embedColor: client.config.embed.color, embedFoot: client.config.embed.footer, }).then(async winner => { - const memberData = await client.findOrCreateMember(winner.id, interaction.guildId); + const memberData = await client.getMemberData(winner.id, interaction.guildId); memberData.money += 100; diff --git a/commands/General/boosters.js b/commands/General/boosters.js index d4f8ea19..10112cdc 100644 --- a/commands/General/boosters.js +++ b/commands/General/boosters.js @@ -31,7 +31,7 @@ class Boosters extends BaseCommand { if (interaction.customId.startsWith("boosters_")) { interaction.data = []; - interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); + interaction.data.guild = await client.getGuildData(interaction.guildId); const boosters = (await interaction.guild.members.fetch()).filter(m => m.premiumSince), embeds = generateBoostersEmbeds(interaction, boosters); diff --git a/commands/General/help.js b/commands/General/help.js index edc26808..b4844991 100644 --- a/commands/General/help.js +++ b/commands/General/help.js @@ -43,7 +43,7 @@ class Help extends BaseCommand { await interaction.deferUpdate(); interaction.data = []; - interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); + interaction.data.guild = await client.getGuildData(interaction.guildId); const arg = interaction?.values[0]; const categoryCommands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()] diff --git a/commands/General/reminds.js b/commands/General/reminds.js index 648cc7f7..49dd7875 100644 --- a/commands/General/reminds.js +++ b/commands/General/reminds.js @@ -31,8 +31,8 @@ class Reminds extends BaseCommand { if (interaction.customId.startsWith("reminds_")) { interaction.data = []; - interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); - interaction.data.user = await client.findOrCreateUser(interaction.user.id); + interaction.data.guild = await client.getGuildData(interaction.guildId); + interaction.data.user = await client.getUserData(interaction.user.id); const reminds = interaction.data.user.reminds, embeds = generateRemindsEmbeds(interaction, reminds); diff --git a/commands/Moderation/clearwarns.js b/commands/Moderation/clearwarns.js index 416b8c1f..cc7e3c2c 100644 --- a/commands/Moderation/clearwarns.js +++ b/commands/Moderation/clearwarns.js @@ -40,7 +40,7 @@ class Clearwarns extends BaseCommand { async execute(client, interaction) { const member = interaction.options.getMember("user"); - const memberData = await client.findOrCreateMember(member.id, interaction.guildId); + const memberData = await client.getMemberData(member.id, interaction.guildId); memberData.sanctions = []; diff --git a/commands/Moderation/warn.c.js b/commands/Moderation/warn.c.js index de0c3ee9..85998c40 100644 --- a/commands/Moderation/warn.c.js +++ b/commands/Moderation/warn.c.js @@ -32,7 +32,7 @@ class WarnContext extends BaseCommand { if (member.id === interaction.member.id) return interaction.error("moderation/warn:YOURSELF", null, { ephemeral: true }); if (interaction.guild.ownerId !== interaction.member.id && !(moderationPosition > memberPosition)) return interaction.error("moderation/warn:SUPERIOR", null, { ephemeral: true }); - const memberData = await client.findOrCreateMember(member.id, interaction.guildId); + const memberData = await client.getMemberData(member.id, interaction.guildId); const modal = new ModalBuilder() .setCustomId("warn_modal") diff --git a/commands/Moderation/warns.js b/commands/Moderation/warns.js index bed50cde..2f96602c 100644 --- a/commands/Moderation/warns.js +++ b/commands/Moderation/warns.js @@ -41,7 +41,7 @@ class Warns extends BaseCommand { const member = interaction.options.getMember("user"); if (member.user.bot) return interaction.error("misc:BOT_USER"); - const memberData = await client.findOrCreateMember(member.id, interaction.guildId); + const memberData = await client.getMemberData(member.id, interaction.guildId); const embed = client.embed({ author: { diff --git a/commands/Music/nowplaying.js b/commands/Music/nowplaying.js index 29c66939..fca9fee0 100644 --- a/commands/Music/nowplaying.js +++ b/commands/Music/nowplaying.js @@ -31,7 +31,7 @@ class Nowplaying extends BaseCommand { if (!interaction.isButton()) return; if (interaction.customId.startsWith("nowp_")) { - const locale = (await client.findOrCreateGuild(interaction.guildId)).language; + const locale = (await client.getGuildData(interaction.guildId)).language; const voice = interaction.member.voice.channel; if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL", null, { locale }); diff --git a/commands/Music/queue.js b/commands/Music/queue.js index 37dad4e1..097269cc 100644 --- a/commands/Music/queue.js +++ b/commands/Music/queue.js @@ -30,7 +30,7 @@ class Queue extends BaseCommand { if (!interaction.isButton()) return; if (interaction.customId.startsWith("queue_")) { - const locale = (await client.findOrCreateGuild(interaction.guildId)).language; + const locale = (await client.getGuildData(interaction.guildId)).language; const queue = client.player.nodes.get(interaction.guildId); if (!queue) return interaction.error("music/play:NOT_PLAYING", null, locale); diff --git a/commands/NSFW/nsfw.js b/commands/NSFW/nsfw.js index 6acd544c..10f359b7 100644 --- a/commands/NSFW/nsfw.js +++ b/commands/NSFW/nsfw.js @@ -34,7 +34,7 @@ class NSFW extends BaseCommand { await interaction.deferUpdate(); interaction.data = []; - interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); + interaction.data.guild = await client.getGuildData(interaction.guildId); const tag = interaction?.values[0], splitted = tag.split("_"), diff --git a/commands/Owner/debug.js b/commands/Owner/debug.js index 0a63387d..fdbd67c3 100644 --- a/commands/Owner/debug.js +++ b/commands/Owner/debug.js @@ -128,8 +128,8 @@ class Debug extends BaseCommand { const member = interaction.options.getMember("user"); if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true }); - const userData = await client.findOrCreateUser(member.id), - memberData = await client.findOrCreateMember(member.id, interaction.guildId); + const userData = await client.getUserData(member.id), + memberData = await client.getMemberData(member.id, interaction.guildId); switch (type) { case "level": { @@ -194,8 +194,8 @@ class Debug extends BaseCommand { const member = interaction.options.getMember("target"); if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true }); - const userData = await client.findOrCreateUser(member.id), - memberData = await client.findOrCreateMember(member.id, interaction.guildId); + const userData = await client.getUserData(member.id), + memberData = await client.getMemberData(member.id, interaction.guildId); switch (type) { case "level": { diff --git a/commands/Tickets/createticketembed.js b/commands/Tickets/createticketembed.js index 98b70251..b062c023 100644 --- a/commands/Tickets/createticketembed.js +++ b/commands/Tickets/createticketembed.js @@ -31,7 +31,7 @@ class CreateTicketEmbed extends BaseCommand { if (!interaction.isButton()) return; interaction.data = []; - interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); + interaction.data.guild = await client.getGuildData(interaction.guildId); const guildData = interaction.data.guild, ticketsCategory = guildData.plugins?.tickets?.ticketsCategory, diff --git a/dashboard/settings.js b/dashboard/settings.js index c60518c0..7110aba0 100644 --- a/dashboard/settings.js +++ b/dashboard/settings.js @@ -20,12 +20,12 @@ module.exports = client => [ Ukrainian: "uk-UA", }), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.language; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.language = newData; @@ -45,12 +45,12 @@ module.exports = client => [ optionDescription: "Toggle welcome messages sending", optionType: DBD.formTypes.switch(), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.welcome.enabled; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.welcome.enabled = newData; @@ -65,12 +65,12 @@ module.exports = client => [ optionDescription: "Toggle sending an image with welcome message", optionType: DBD.formTypes.switch(), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.welcome.withImage; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.welcome.withImage = newData; @@ -85,12 +85,12 @@ module.exports = client => [ optionDescription: "Change welcome message (You can use {user}, {server} and {membercount} wildcards)", optionType: DBD.formTypes.input("Welcome, {user}!", 2, 100, false, false), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.welcome.message; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.welcome.message = newData !== "" ? newData : null; @@ -105,12 +105,12 @@ module.exports = client => [ optionDescription: "Select a channel for welcome messages", optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.welcome.channel; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.welcome.channel = newData !== "" ? newData : null; @@ -132,12 +132,12 @@ module.exports = client => [ optionDescription: "Toggle goodbye messages sending", optionType: DBD.formTypes.switch(), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.goodbye.enabled; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.goodbye.enabled = newData; @@ -152,12 +152,12 @@ module.exports = client => [ optionDescription: "Toggle sending an image with goodbye message", optionType: DBD.formTypes.switch(), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.goodbye.withImage; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.goodbye.withImage = newData; @@ -172,12 +172,12 @@ module.exports = client => [ optionDescription: "Change goodbye message (You can use {user}, {server} and {membercount} wildcards)", optionType: DBD.formTypes.input("goodbye, {user}!", 2, 100, false, false), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.goodbye.message; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.goodbye.message = newData !== "" ? newData : null; @@ -192,12 +192,12 @@ module.exports = client => [ optionDescription: "Select a channel for goodbye messages", optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.goodbye.channel; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.goodbye.channel = newData !== "" ? newData : null; @@ -219,12 +219,12 @@ module.exports = client => [ optionDescription: "Toggle auto role granting for new members", optionType: DBD.formTypes.switch(), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.autorole.enabled; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.autorole.enabled = newData; @@ -239,12 +239,12 @@ module.exports = client => [ optionDescription: "Select a role for auto role. Select \"-\" to disable", optionType: DBD.formTypes.rolesSelect(false, false, true), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.autorole.role; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.autorole.role = newData !== "" ? newData : null; @@ -266,12 +266,12 @@ module.exports = client => [ optionDescription: "Toggle auto mod. It will remove invite links from non-moderators", optionType: DBD.formTypes.switch(), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.automod.enabled; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.automod.enabled = newData; @@ -286,12 +286,12 @@ module.exports = client => [ optionDescription: "Select a channels for auto mod to ignore", optionType: DBD.formTypes.channelsMultiSelect(false, false, [ChannelType.GuildText]), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.automod.ignored; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.automod.ignored = newData; @@ -313,12 +313,12 @@ module.exports = client => [ optionDescription: "Select a channel for messages update logs to go to. Select \"-\" to disable", optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins?.monitoring?.messageUpdate; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); if (guildData.plugins.monitoring === undefined) guildData.plugins.monitoring = {}; @@ -335,12 +335,12 @@ module.exports = client => [ optionDescription: "Select a channel for messages deletion logs to go to. Select \"-\" to disable", optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins?.monitoring?.messageDelete; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); if (guildData.plugins.monitoring === undefined) guildData.plugins.monitoring = {}; @@ -364,12 +364,12 @@ module.exports = client => [ optionDescription: "Select a channel for suggestions to go to", optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.suggestions; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.suggestions = newData !== "" ? newData : null; @@ -384,12 +384,12 @@ module.exports = client => [ optionDescription: "Select a channel for reports to go to. Select \"-\" to disable", optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.reports; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.reports = newData !== "" ? newData : null; @@ -404,12 +404,12 @@ module.exports = client => [ optionDescription: "Select a channel for birthdays message to go to. Select \"-\" to disable", optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.birthdays; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.birthdays = newData !== "" ? newData : null; @@ -424,12 +424,12 @@ module.exports = client => [ optionDescription: "Select a channel for moderation logs to go to (warns). Select \"-\" to disable", optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), getActualSet: async ({ guild }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); return guildData.plugins.modlogs; }, setNew: async ({ guild, newData }) => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); guildData.plugins.modlogs = newData !== "" ? newData : null; diff --git a/events/CommandHandler.js b/events/CommandHandler.js index 2f51f625..190d9d79 100644 --- a/events/CommandHandler.js +++ b/events/CommandHandler.js @@ -19,11 +19,11 @@ class CommandHandler extends BaseEvent { const data = []; - data.user = await client.findOrCreateUser(interaction.user.id); + data.user = await client.getUserData(interaction.user.id); if (interaction.inGuild()) { - data.guild = await client.findOrCreateGuild(interaction.guildId); - data.member = await client.findOrCreateMember(interaction.member.id, interaction.guildId); + data.guild = await client.getGuildData(interaction.guildId); + data.member = await client.getMemberData(interaction.member.id, interaction.guildId); } interaction.data = data; diff --git a/events/Guild/guildCreate.js b/events/Guild/guildCreate.js index 7c832dc3..1981bfb2 100644 --- a/events/Guild/guildCreate.js +++ b/events/Guild/guildCreate.js @@ -14,7 +14,7 @@ class GuildCreate extends BaseEvent { * @param {import("discord.js").Guild} guild */ async execute(client, guild) { - const userData = await client.findOrCreateUser(guild.ownerId); + const userData = await client.getUserData(guild.ownerId); if (!userData.achievements.invite.achieved) { userData.achievements.invite.progress.now = 1; diff --git a/events/Guild/guildMemberAdd.js b/events/Guild/guildMemberAdd.js index b5458cb7..b84a32f9 100644 --- a/events/Guild/guildMemberAdd.js +++ b/events/Guild/guildMemberAdd.js @@ -32,7 +32,7 @@ class GuildMemberAdd extends BaseEvent { await member.guild.members.fetch(); - const guildData = await client.findOrCreateGuild(member.guild.id); + const guildData = await client.getGuildData(member.guild.id); if (guildData.plugins.autorole.enabled) member.roles.add(guildData.plugins.autorole.role); diff --git a/events/Guild/guildMemberRemove.js b/events/Guild/guildMemberRemove.js index 63cb9f56..41a8d761 100644 --- a/events/Guild/guildMemberRemove.js +++ b/events/Guild/guildMemberRemove.js @@ -32,7 +32,7 @@ class GuildMemberRemove extends BaseEvent { await member.guild.members.fetch(); - const guildData = await client.findOrCreateGuild(member.guild.id); + const guildData = await client.getGuildData(member.guild.id); if (guildData.plugins.goodbye.enabled) { const channel = member.guild.channels.cache.get(guildData.plugins.goodbye.channel); diff --git a/events/Guild/guildMemberUpdate.js b/events/Guild/guildMemberUpdate.js index 9eadcbbb..d522050a 100644 --- a/events/Guild/guildMemberUpdate.js +++ b/events/Guild/guildMemberUpdate.js @@ -20,7 +20,7 @@ class GuildMemberUpdate extends BaseEvent { if (oldMember.roles.cache.some(r => r.id === "940149470975365191")) return; if (newMember?.roles.cache.some(r => r.id === "940149470975365191")) { - const userData = await client.findOrCreateUser(newMember.id); + const userData = await client.getUserData(newMember.id); userData.achievements.tip.progress.now = 1; userData.achievements.tip.achieved = true; diff --git a/events/MessageHandler.js b/events/MessageHandler.js index e8069407..2659d402 100644 --- a/events/MessageHandler.js +++ b/events/MessageHandler.js @@ -24,13 +24,13 @@ class MessageCreate extends BaseEvent { if (message.author.bot) return; if (message.content.match(new RegExp(`^<@!?${client.user.id}>( |)$`))) return message.replyT("misc:HELLO_SERVER", null, { mention: true }); - data.user = await client.findOrCreateUser(message.author.id); + data.user = await client.getUserData(message.author.id); if (message.guild) { if (!message.member) await message.guild.members.fetch(message.author.id); - data.guild = await client.findOrCreateGuild(message.guildId); - data.member = await client.findOrCreateMember(message.author.id, message.guildId); + data.guild = await client.getGuildData(message.guildId); + data.member = await client.getMemberData(message.author.id, message.guildId); } message.data = data; @@ -106,7 +106,7 @@ class MessageCreate extends BaseEvent { } message.mentions.users.forEach(async u => { - const userData = await client.findOrCreateUser(u.id); + const userData = await client.getUserData(u.id); if (userData.afk) message.replyT("general/afk:IS_AFK", { user: u.getUsername(), reason: userData.afk }, { ephemeral: true }); }); diff --git a/helpers/birthdays.js b/helpers/birthdays.js index 13706599..9f395e57 100644 --- a/helpers/birthdays.js +++ b/helpers/birthdays.js @@ -7,7 +7,7 @@ const { CronJob } = require("cron"); module.exports.init = async client => { const cronjob = new CronJob("0 5 * * *", async function () { client.guilds.cache.forEach(async guild => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); const channel = guildData.plugins.birthdays ? client.channels.cache.get(guildData.plugins.birthdays) || (await client.channels.fetch(guildData.plugins.birthdays)) : null; if (guildData.plugins.birthdays && client.channels.cache.get(guildData.plugins.birthdays)) { @@ -69,7 +69,7 @@ module.exports.init = async client => { */ module.exports.run = async client => { client.guilds.cache.forEach(async guild => { - const guildData = await client.findOrCreateGuild(guild.id); + const guildData = await client.getGuildData(guild.id); const channel = guildData.plugins.birthdays ? client.channels.cache.get(guildData.plugins.birthdays) || (await client.channels.fetch(guildData.plugins.birthdays)) : null; if (guildData.plugins.birthdays) {