diff --git a/base/Client.js b/base/Client.js index 517ddab8..6884973b 100644 --- a/base/Client.js +++ b/base/Client.js @@ -328,20 +328,19 @@ class JaBaClient extends Client { /** * Finds or creates a member in the database based on the provided member ID and guild ID. - * @param {Object} options - The options for finding or creating the member. - * @param {string} options.id - The ID of the member to find or create. - * @param {string} options.guildId - The ID of the guild the member belongs to. + * @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({ id: memberID, guildId }) { - let memberData = await this.membersData.findOne({ guildID: guildId, id: memberID }); + async findOrCreateMember(memberId, guildId) { + let memberData = await this.membersData.findOne({ guildID: guildId, id: memberId }); if (memberData) { - this.databaseCache.members.set(`${memberID}${guildId}`, memberData); + this.databaseCache.members.set(`${memberId}${guildId}`, memberData); return memberData; } else { - memberData = new this.membersData({ id: memberID, guildID: guildId }); + memberData = new this.membersData({ id: memberId, guildID: guildId }); await memberData.save(); @@ -353,7 +352,7 @@ class JaBaClient extends Client { await guildData.save(); } - this.databaseCache.members.set(`${memberID}${guildId}`, memberData); + this.databaseCache.members.set(`${memberId}/${guildId}`, memberData); return memberData; } diff --git a/commands/!DISABLED/importmee6.js b/commands/!DISABLED/importmee6.js index f4467149..dcbb30c8 100644 --- a/commands/!DISABLED/importmee6.js +++ b/commands/!DISABLED/importmee6.js @@ -35,8 +35,6 @@ class ImportMee6 extends BaseCommand { interaction.data.member.level = level; interaction.data.member.exp = 0; - interaction.data.member.markModified("level"); - interaction.data.member.markModified("exp"); await interaction.data.member.save(); interaction.editReply({ diff --git a/commands/Administration/automod.js b/commands/Administration/automod.js index cadff970..e51e7841 100644 --- a/commands/Administration/automod.js +++ b/commands/Administration/automod.js @@ -78,14 +78,12 @@ class Automod extends BaseCommand { ignored: [], }; - data.guild.markModified("plugins.automod"); await data.guild.save(); interaction.success(`administration/automod:${state ? "ENABLED" : "DISABLED"}`); } else if (command === "ignore") { data.guild.plugins.automod.ignored.push(channel.id); - data.guild.markModified("plugins.automod"); await data.guild.save(); interaction.success("administration/automod:DISABLED_CHANNEL", { diff --git a/commands/Administration/autorole.js b/commands/Administration/autorole.js index dbf86c63..a66a80d2 100644 --- a/commands/Administration/autorole.js +++ b/commands/Administration/autorole.js @@ -57,7 +57,6 @@ class Autorole extends BaseCommand { }; if (state && role) { - guildData.markModified("plugins.autorole"); await guildData.save(); interaction.success("administration/autorole:ENABLED", { @@ -66,7 +65,6 @@ class Autorole extends BaseCommand { } else { guildData.plugins.autorole.enabled = false; - guildData.markModified("plugins.autorole"); await guildData.save(); interaction.success("administration/autorole:DISABLED"); diff --git a/commands/Administration/config.js b/commands/Administration/config.js index 5e5c9a72..bb760b66 100644 --- a/commands/Administration/config.js +++ b/commands/Administration/config.js @@ -194,7 +194,6 @@ async function changeSetting(interaction, setting, state, channel) { if (!state) { data.plugins[settingSplitted[0]][settingSplitted[1]] = null; - data.markModified(`plugins.${settingSplitted[0]}`); await data.save(); return interaction.reply({ @@ -207,7 +206,6 @@ async function changeSetting(interaction, setting, state, channel) { if (channel) { data.plugins[settingSplitted[0]][settingSplitted[1]] = channel.id; - data.markModified(`plugins.${settingSplitted[0]}`); await data.save(); return interaction.reply({ @@ -226,7 +224,6 @@ async function changeSetting(interaction, setting, state, channel) { if (!state) { data.plugins[setting] = null; - data.markModified(`plugins.${setting}`); await data.save(); return interaction.reply({ @@ -237,7 +234,6 @@ async function changeSetting(interaction, setting, state, channel) { if (channel) { data.plugins[setting] = channel.id; - data.markModified(`plugins.${setting}`); await data.save(); return interaction.reply({ diff --git a/commands/Administration/goodbye.js b/commands/Administration/goodbye.js index d0a8604c..da763d46 100644 --- a/commands/Administration/goodbye.js +++ b/commands/Administration/goodbye.js @@ -101,7 +101,6 @@ class Goodbye extends BaseCommand { withImage: null, }; - guildData.markModified("plugins.goodbye"); await guildData.save(); interaction.success("administration/goodbye:DISABLED", null, { ephemeral: true }); @@ -117,7 +116,6 @@ class Goodbye extends BaseCommand { withImage: image, }; - guildData.markModified("plugins.goodbye"); await guildData.save(); interaction.success("administration/goodbye:ENABLED", { diff --git a/commands/Administration/set.js b/commands/Administration/set.js index e008b5df..29a42b99 100644 --- a/commands/Administration/set.js +++ b/commands/Administration/set.js @@ -68,10 +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({ - id: member.id, - guildId: interaction.guildId, - }); + const memberData = await client.findOrCreateMember(member.id, interaction.guildId); const int = interaction.options.getInteger("int"); if (int < 0) return interaction.error("administration/set:INVALID_NUMBER", null, { ephemeral: true }); @@ -80,7 +77,6 @@ class Set extends BaseCommand { case "level": { memberData.level = int; - memberData.markModified("level"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -92,7 +88,6 @@ class Set extends BaseCommand { case "xp": { memberData.exp = int; - memberData.markModified("exp"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -104,7 +99,6 @@ class Set extends BaseCommand { case "credits": { memberData.money = int; - memberData.markModified("money"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -116,7 +110,6 @@ class Set extends BaseCommand { case "bank": { memberData.bankSold = int; - memberData.markModified("bankSold"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { diff --git a/commands/Administration/setlang.js b/commands/Administration/setlang.js index 986718f0..ebba9353 100644 --- a/commands/Administration/setlang.js +++ b/commands/Administration/setlang.js @@ -45,7 +45,6 @@ class Setlang extends BaseCommand { guildData.language = language.name; - guildData.markModified("language"); await guildData.save(); return interaction.success("administration/setlang:SUCCESS", { diff --git a/commands/Administration/welcome.js b/commands/Administration/welcome.js index 3c48f00a..1fb2f7a1 100644 --- a/commands/Administration/welcome.js +++ b/commands/Administration/welcome.js @@ -101,7 +101,6 @@ class Welcome extends BaseCommand { withImage: null, }; - guildData.markModified("plugins.welcome"); await guildData.save(); interaction.success("administration/welcome:DISABLED", null, { ephemeral: true }); @@ -117,7 +116,6 @@ class Welcome extends BaseCommand { withImage: image, }; - guildData.markModified("plugins.welcome"); await guildData.save(); interaction.success("administration/welcome:ENABLED", { diff --git a/commands/Economy/bank.js b/commands/Economy/bank.js index 3d20db98..e163b9ec 100644 --- a/commands/Economy/bank.js +++ b/commands/Economy/bank.js @@ -63,8 +63,6 @@ class Bank extends BaseCommand { memberData.money -= credits; memberData.bankSold += credits; - memberData.markModified("money"); - memberData.markModified("bankSold"); await memberData.save(); const info = { @@ -99,8 +97,6 @@ class Bank extends BaseCommand { memberData.money += credits; memberData.bankSold -= credits; - memberData.markModified("money"); - memberData.markModified("bankSold"); await memberData.save(); interaction.success("economy/bank:SUCCESS_WD", { diff --git a/commands/Economy/birthdate.js b/commands/Economy/birthdate.js index 7f20647a..216dc55f 100644 --- a/commands/Economy/birthdate.js +++ b/commands/Economy/birthdate.js @@ -87,7 +87,6 @@ class Birthdate extends BaseCommand { userData.birthdate = d; - userData.markModified("birthdate"); await userData.save(); interaction.success("economy/birthdate:SUCCESS", { diff --git a/commands/Economy/divorce.js b/commands/Economy/divorce.js index a8aeb5ef..18ec69d9 100644 --- a/commands/Economy/divorce.js +++ b/commands/Economy/divorce.js @@ -34,13 +34,11 @@ class Divorce extends BaseCommand { userData.lover = null; - userData.markModified("lover"); await userData.save(); const oldLover = await client.findOrCreateUser(user.id); oldLover.lover = null; - oldLover.markModified("lover"); await oldLover.save(); interaction.success("economy/divorce:DIVORCED", { diff --git a/commands/Economy/marry.js b/commands/Economy/marry.js index 2df4131c..46724b1f 100644 --- a/commands/Economy/marry.js +++ b/commands/Economy/marry.js @@ -122,11 +122,6 @@ class Marry extends BaseCommand { userData.lover = member.id; otherUserData.lover = interaction.member.id; - userData.markModified("lover"); - otherUserData.markModified("lover"); - await userData.save(); - await otherUserData.save(); - const messageOptions = { content: `${member.toString()} :heart: ${interaction.member.toString()}`, files: [ @@ -143,20 +138,17 @@ class Marry extends BaseCommand { sent = true; otherUserData.achievements.married.achieved = true; otherUserData.achievements.married.progress.now = 1; - - otherUserData.markModified("achievements"); - await otherUserData.save(); } if (!userData.achievements.married.achieved) { if (!sent) interaction.followUp(messageOptions); userData.achievements.married.achieved = true; userData.achievements.married.progress.now = 1; - - userData.markModified("achievements"); - await userData.save(); } + await userData.save(); + await otherUserData.save(); + return interaction.editReply({ content: interaction.translate("economy/marry:SUCCESS", { creator: interaction.member.toString(), diff --git a/commands/Economy/money.js b/commands/Economy/money.js index b15f7b56..92ff26ae 100644 --- a/commands/Economy/money.js +++ b/commands/Economy/money.js @@ -41,16 +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({ id: member.id, guildId: interaction.guildId }); + const memberData = member.id === interaction.user.id ? interaction.data.member : await client.findOrCreateMember(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({ - id: member.id, - guildId: guild.id, - }); + const data = await client.findOrCreateMember(member.id, guild.id); globalMoney += data.money + data.bankSold; }); diff --git a/commands/Economy/pay.js b/commands/Economy/pay.js index f31e1188..de016276 100644 --- a/commands/Economy/pay.js +++ b/commands/Economy/pay.js @@ -59,21 +59,11 @@ 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({ - id: otherMember.id, - guildId: interaction.guildId, - }); + const otherMemberData = await client.findOrCreateMember(otherMember.id, interaction.guildId); memberData.money -= amount; - - memberData.markModified("money"); - await memberData.save(); - otherMemberData.money += amount; - otherMemberData.markModified("money"); - await otherMemberData.save(); - const info1 = { user: otherMember.user.getUsername(), amount: amount, @@ -90,6 +80,9 @@ class Pay extends BaseCommand { }; otherMemberData.transactions.push(info2); + await memberData.save(); + await otherMemberData.save(); + interaction.success("economy/pay:SUCCESS", { user: otherMember.toString(), amount: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, diff --git a/commands/Economy/profile.js b/commands/Economy/profile.js index 2abf5b93..5ad81bf9 100644 --- a/commands/Economy/profile.js +++ b/commands/Economy/profile.js @@ -41,17 +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({ id: member.id, guildId: interaction.guildId }); + 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); 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({ - id: member.id, - guildId: guild.id, - }); + const data = await client.findOrCreateMember(member.id, guild.id); globalMoney += data.money + data.bankSold; }); diff --git a/commands/Economy/rep.js b/commands/Economy/rep.js index 083660e4..4d6c5c61 100644 --- a/commands/Economy/rep.js +++ b/commands/Economy/rep.js @@ -56,9 +56,6 @@ class Rep extends BaseCommand { userData.cooldowns.rep = toWait; - userData.markModified("cooldowns"); - await userData.save(); - const otherUserData = await client.findOrCreateUser(user.id); otherUserData.rep++; @@ -79,7 +76,7 @@ class Rep extends BaseCommand { } } - otherUserData.markModified("rep"); + await userData.save(); await otherUserData.save(); interaction.success("economy/rep:SUCCESS", { diff --git a/commands/Economy/rob.js b/commands/Economy/rob.js index 77437e36..9a6946ba 100644 --- a/commands/Economy/rob.js +++ b/commands/Economy/rob.js @@ -55,10 +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({ - id: otherMember.id, - guildId: interaction.guildId, - }); + const otherMemberData = await client.findOrCreateMember(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; @@ -81,9 +78,6 @@ class Rob extends BaseCommand { otherMemberData.cooldowns.rob = toWait; - otherMemberData.markModified("cooldowns"); - await otherMemberData.save(); - interaction.replyT("economy/rob:ROB_WON_" + randomNum, { money: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, user: otherMember.toString(), @@ -92,8 +86,6 @@ class Rob extends BaseCommand { memberData.money += amount; otherMemberData.money -= amount; - memberData.markModified("money"); - otherMemberData.markModified("money"); await memberData.save(); await otherMemberData.save(); } else { @@ -109,8 +101,6 @@ class Rob extends BaseCommand { memberData.money -= potentiallyLose; otherMemberData.money += won; - memberData.markModified("money"); - otherMemberData.markModified("money"); await memberData.save(); await otherMemberData.save(); } diff --git a/commands/Economy/setbio.js b/commands/Economy/setbio.js index 6b3eeb6f..0886f1da 100644 --- a/commands/Economy/setbio.js +++ b/commands/Economy/setbio.js @@ -43,7 +43,6 @@ class Setbio extends BaseCommand { userData.bio = newBio; - userData.markModified("bio"); await userData.save(); interaction.success("economy/setbio:SUCCESS"); diff --git a/commands/Economy/slots.js b/commands/Economy/slots.js index f94a5a82..c06a75ab 100644 --- a/commands/Economy/slots.js +++ b/commands/Economy/slots.js @@ -135,13 +135,8 @@ class Slots extends BaseCommand { ], }); } - - userData.markModified("achievements"); - await userData.save(); } - memberData.markModified("money"); - memberData.markModified("transactions"); await memberData.save(); return; @@ -186,13 +181,8 @@ class Slots extends BaseCommand { ], }); } - - userData.markModified("achievements"); - await userData.save(); } - memberData.markModified("money"); - memberData.markModified("transactions"); await memberData.save(); return; @@ -216,15 +206,8 @@ class Slots extends BaseCommand { memberData.money -= amount; memberData.transactions.push(info); - if (!userData.achievements.slots.achieved) { - userData.achievements.slots.progress.now = 0; + if (!userData.achievements.slots.achieved) userData.achievements.slots.progress.now = 0; - userData.markModified("achievements"); - await userData.save(); - } - - memberData.markModified("money"); - memberData.markModified("transactions"); await memberData.save(); return; diff --git a/commands/Economy/transactions.js b/commands/Economy/transactions.js index 9af4932b..a2716fa8 100644 --- a/commands/Economy/transactions.js +++ b/commands/Economy/transactions.js @@ -41,7 +41,6 @@ class Transactions extends BaseCommand { if (interaction.options.getBoolean("clear")) { memberData.transactions = []; - memberData.markModified("transactions"); await memberData.save(); return interaction.success("economy/transactions:CLEARED", null, { ephemeral: true }); diff --git a/commands/Economy/work.js b/commands/Economy/work.js index 6ae16297..82f53482 100644 --- a/commands/Economy/work.js +++ b/commands/Economy/work.js @@ -30,23 +30,16 @@ class Work extends BaseCommand { const { member: memberData, user: userData } = interaction.data, isInCooldown = memberData.cooldowns?.work; - if (isInCooldown) { - if (isInCooldown > Date.now()) - return interaction.error("economy/work:COOLDOWN", { - time: ``, - }); - } + if (isInCooldown && isInCooldown > 0 && isInCooldown > Math.floor(Date.now() / 1000)) + return interaction.error("economy/work:COOLDOWN", { + time: ``, + }); - if (Date.now() > Math.floor(memberData.cooldowns.work + 24 * 60 * 60 * 1000) / 1000) memberData.workStreak = 0; + if (Math.floor(Date.now() / 1000) > Math.floor(memberData.cooldowns.work + 24 * 60 * 60)) memberData.workStreak = 0; - const toWait = Math.floor((Date.now() + 24 * 60 * 60 * 1000) / 1000); // 24 hours - memberData.cooldowns.work = toWait; + memberData.cooldowns.work = Math.floor(Date.now() / 1000) + 24 * 60 * 60; // 24 hours memberData.workStreak = (memberData.workStreak || 0) + 1; - memberData.markModified("cooldowns"); - memberData.markModified("workStreak"); - await memberData.save(); - const embed = client.embed({ footer: { text: interaction.translate("economy/work:AWARD"), @@ -96,9 +89,6 @@ class Work extends BaseCommand { memberData.money += won; - memberData.markModified("money"); - await memberData.save(); - const info = { user: interaction.translate("economy/work:SALARY"), amount: won, @@ -123,10 +113,11 @@ class Work extends BaseCommand { userData.achievements.work.achieved = true; } - userData.markModified("achievements"); await userData.save(); } + await memberData.save(); + interaction.reply(messageOptions); } } diff --git a/commands/Fun/number.js b/commands/Fun/number.js index e13c5e35..d9108ee0 100644 --- a/commands/Fun/number.js +++ b/commands/Fun/number.js @@ -80,10 +80,7 @@ class Number extends BaseCommand { }), }); - const memberData = await client.findOrCreateMember({ - id: msg.author.id, - guildId: interaction.guildId, - }); + const memberData = await client.findOrCreateMember(msg.author.id, interaction.guildId); memberData.money += won; @@ -95,7 +92,6 @@ class Number extends BaseCommand { }; data.memberData.transactions.push(info); - memberData.markModified("transactions"); await memberData.save(); } diff --git a/commands/Fun/tictactoe.js b/commands/Fun/tictactoe.js index 282e6af5..7584bdf6 100644 --- a/commands/Fun/tictactoe.js +++ b/commands/Fun/tictactoe.js @@ -43,10 +43,7 @@ class TicTacToe extends BaseCommand { embedColor: client.config.embed.color, embedFoot: client.config.embed.footer, }).then(async winner => { - const memberData = await client.findOrCreateMember({ - id: winner.id, - guildId: interaction.guildId, - }); + const memberData = await client.findOrCreateMember(winner.id, interaction.guildId); memberData.money += 100; @@ -59,8 +56,6 @@ class TicTacToe extends BaseCommand { memberData.transactions.push(info); - memberData.markModified("money"); - memberData.markModified("transactions"); await memberData.save(); }); } diff --git a/commands/General/afk.js b/commands/General/afk.js index 8801dec7..b04b257c 100644 --- a/commands/General/afk.js +++ b/commands/General/afk.js @@ -44,7 +44,6 @@ class Afk extends BaseCommand { userData.afk = reason; - userData.markModified("afk"); await userData.save(); interaction.success("general/afk:SUCCESS", { diff --git a/commands/General/remindme.js b/commands/General/remindme.js index 68efa439..c99cafcf 100644 --- a/commands/General/remindme.js +++ b/commands/General/remindme.js @@ -64,7 +64,6 @@ class Remindme extends BaseCommand { userData.reminds.push(reminder); - userData.markModified("reminds"); await userData.save(); client.databaseCache.usersReminds.set(interaction.user.id, userData); diff --git a/commands/Moderation/clearwarns.js b/commands/Moderation/clearwarns.js index a5de0e82..416b8c1f 100644 --- a/commands/Moderation/clearwarns.js +++ b/commands/Moderation/clearwarns.js @@ -40,14 +40,10 @@ class Clearwarns extends BaseCommand { async execute(client, interaction) { const member = interaction.options.getMember("user"); - const memberData = await client.findOrCreateMember({ - id: member.id, - guildId: interaction.guildId, - }); + const memberData = await client.findOrCreateMember(member.id, interaction.guildId); memberData.sanctions = []; - memberData.markModified("sanctions"); await memberData.save(); interaction.success("moderation/clearwarns:SUCCESS", { diff --git a/commands/Moderation/warn.c.js b/commands/Moderation/warn.c.js index e226c4ea..de0c3ee9 100644 --- a/commands/Moderation/warn.c.js +++ b/commands/Moderation/warn.c.js @@ -32,10 +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({ - id: member.id, - guildId: interaction.guildId, - }); + const memberData = await client.findOrCreateMember(member.id, interaction.guildId); const modal = new ModalBuilder() .setCustomId("warn_modal") @@ -176,7 +173,6 @@ class WarnContext extends BaseCommand { memberData.sanctions.push(caseInfo); - memberData.markModified("sanctions"); await memberData.save(); const guildData = interaction.data.guild; diff --git a/commands/Moderation/warns.js b/commands/Moderation/warns.js index 3a121e48..bed50cde 100644 --- a/commands/Moderation/warns.js +++ b/commands/Moderation/warns.js @@ -41,10 +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({ - id: member.id, - guildId: interaction.guildId, - }); + const memberData = await client.findOrCreateMember(member.id, interaction.guildId); const embed = client.embed({ author: { diff --git a/commands/Owner/debug.js b/commands/Owner/debug.js index f21042ab..0a63387d 100644 --- a/commands/Owner/debug.js +++ b/commands/Owner/debug.js @@ -129,16 +129,12 @@ class Debug extends BaseCommand { if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true }); const userData = await client.findOrCreateUser(member.id), - memberData = await client.findOrCreateMember({ - id: member.id, - guildId: interaction.guildId, - }); + memberData = await client.findOrCreateMember(member.id, interaction.guildId); switch (type) { case "level": { memberData.level = int; - memberData.markModified("level"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -150,7 +146,6 @@ class Debug extends BaseCommand { case "xp": { memberData.exp = int; - memberData.markModified("exp"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -162,7 +157,6 @@ class Debug extends BaseCommand { case "credits": { memberData.money = int; - memberData.markModified("money"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -174,7 +168,6 @@ class Debug extends BaseCommand { case "bank": { memberData.bankSold = int; - memberData.markModified("bankSold"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -186,7 +179,6 @@ class Debug extends BaseCommand { case "rep": { userData.rep = int; - userData.markModified("rep"); await userData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -203,16 +195,12 @@ class Debug extends BaseCommand { if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true }); const userData = await client.findOrCreateUser(member.id), - memberData = await client.findOrCreateMember({ - id: member.id, - guildId: interaction.guildId, - }); + memberData = await client.findOrCreateMember(member.id, interaction.guildId); switch (type) { case "level": { memberData.level += int; - memberData.markModified("level"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -224,7 +212,6 @@ class Debug extends BaseCommand { case "xp": { memberData.exp += int; - memberData.markModified("exp"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -236,7 +223,6 @@ class Debug extends BaseCommand { case "credits": { memberData.money += int; - memberData.markModified("money"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -248,7 +234,6 @@ class Debug extends BaseCommand { case "bank": { memberData.bankSold += int; - memberData.markModified("bankSold"); await memberData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { @@ -260,7 +245,6 @@ class Debug extends BaseCommand { case "rep": { userData.rep += int; - userData.markModified("rep"); await userData.save(); return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, { diff --git a/commands/Tickets/createticketembed.js b/commands/Tickets/createticketembed.js index f459bb2c..98b70251 100644 --- a/commands/Tickets/createticketembed.js +++ b/commands/Tickets/createticketembed.js @@ -51,9 +51,6 @@ class CreateTicketEmbed extends BaseCommand { guildData.plugins.tickets.count++; - guildData.markModified("plugins.tickets"); - await guildData.save(); - const channel = await interaction.guild.channels.create({ name: `${interaction.user.username}-support-${guildData.plugins.tickets.count}`, topic: interaction.user.id, @@ -103,6 +100,8 @@ class CreateTicketEmbed extends BaseCommand { .setStyle(ButtonStyle.Secondary); const row = new ActionRowBuilder().addComponents(closeButton, transcriptButton); + await guildData.save(); + await channel.send({ embeds: [embed], components: [row] }); } else if (button.customId === "close_ticket") { const embed = client.embed({ diff --git a/dashboard/settings.js b/dashboard/settings.js index 082b2492..c60518c0 100644 --- a/dashboard/settings.js +++ b/dashboard/settings.js @@ -29,7 +29,6 @@ module.exports = client => [ guildData.language = newData; - guildData.markModified("language"); await guildData.save(); return; @@ -55,7 +54,6 @@ module.exports = client => [ guildData.plugins.welcome.enabled = newData; - guildData.markModified("plugins"); await guildData.save(); return; @@ -76,7 +74,6 @@ module.exports = client => [ guildData.plugins.welcome.withImage = newData; - guildData.markModified("plugins"); await guildData.save(); return; @@ -97,7 +94,6 @@ module.exports = client => [ guildData.plugins.welcome.message = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; @@ -118,7 +114,6 @@ module.exports = client => [ guildData.plugins.welcome.channel = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; @@ -146,7 +141,6 @@ module.exports = client => [ guildData.plugins.goodbye.enabled = newData; - guildData.markModified("plugins"); await guildData.save(); return; @@ -167,7 +161,6 @@ module.exports = client => [ guildData.plugins.goodbye.withImage = newData; - guildData.markModified("plugins"); await guildData.save(); return; @@ -188,7 +181,6 @@ module.exports = client => [ guildData.plugins.goodbye.message = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; @@ -209,7 +201,6 @@ module.exports = client => [ guildData.plugins.goodbye.channel = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; @@ -237,7 +228,6 @@ module.exports = client => [ guildData.plugins.autorole.enabled = newData; - guildData.markModified("plugins"); await guildData.save(); return; @@ -258,7 +248,6 @@ module.exports = client => [ guildData.plugins.autorole.role = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; @@ -286,7 +275,6 @@ module.exports = client => [ guildData.plugins.automod.enabled = newData; - guildData.markModified("plugins"); await guildData.save(); return; @@ -307,7 +295,6 @@ module.exports = client => [ guildData.plugins.automod.ignored = newData; - guildData.markModified("plugins"); await guildData.save(); return; @@ -337,7 +324,6 @@ module.exports = client => [ guildData.plugins.monitoring.messageUpdate = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; @@ -360,7 +346,6 @@ module.exports = client => [ guildData.plugins.monitoring.messageDelete = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; @@ -388,7 +373,6 @@ module.exports = client => [ guildData.plugins.suggestions = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; @@ -409,7 +393,6 @@ module.exports = client => [ guildData.plugins.reports = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; @@ -430,7 +413,6 @@ module.exports = client => [ guildData.plugins.birthdays = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; @@ -451,7 +433,6 @@ module.exports = client => [ guildData.plugins.modlogs = newData !== "" ? newData : null; - guildData.markModified("plugins"); await guildData.save(); return; diff --git a/events/CommandHandler.js b/events/CommandHandler.js index d3ff6ad3..2f51f625 100644 --- a/events/CommandHandler.js +++ b/events/CommandHandler.js @@ -23,7 +23,7 @@ class CommandHandler extends BaseEvent { if (interaction.inGuild()) { data.guild = await client.findOrCreateGuild(interaction.guildId); - data.member = await client.findOrCreateMember({ id: interaction.member.id, guildId: interaction.guildId }); + data.member = await client.findOrCreateMember(interaction.member.id, interaction.guildId); } interaction.data = data; @@ -50,7 +50,6 @@ class CommandHandler extends BaseEvent { interaction.data.user.achievements.firstCommand.progress.now = 1; interaction.data.user.achievements.firstCommand.achieved = true; - interaction.data.user.markModified("achievements"); await interaction.data.user.save(); try { diff --git a/events/Guild/guildCreate.js b/events/Guild/guildCreate.js index ff44c101..7c832dc3 100644 --- a/events/Guild/guildCreate.js +++ b/events/Guild/guildCreate.js @@ -20,7 +20,6 @@ class GuildCreate extends BaseEvent { userData.achievements.invite.progress.now = 1; userData.achievements.invite.achieved = true; - userData.markModified("achievements"); await userData.save(); } diff --git a/events/Guild/guildMemberUpdate.js b/events/Guild/guildMemberUpdate.js index 83b4c3eb..9eadcbbb 100644 --- a/events/Guild/guildMemberUpdate.js +++ b/events/Guild/guildMemberUpdate.js @@ -25,7 +25,6 @@ class GuildMemberUpdate extends BaseEvent { userData.achievements.tip.progress.now = 1; userData.achievements.tip.achieved = true; - userData.markModified("achievements"); await userData.save(); newMember.send({ diff --git a/events/MessageHandler.js b/events/MessageHandler.js index 36f8e2c4..e8069407 100644 --- a/events/MessageHandler.js +++ b/events/MessageHandler.js @@ -30,7 +30,7 @@ class MessageCreate extends BaseEvent { if (!message.member) await message.guild.members.fetch(message.author.id); data.guild = await client.findOrCreateGuild(message.guildId); - data.member = await client.findOrCreateMember({ id: message.author.id, guildId: message.guildId }); + data.member = await client.findOrCreateMember(message.author.id, message.guildId); } message.data = data; @@ -98,7 +98,6 @@ class MessageCreate extends BaseEvent { if (message.data.user.afk) { message.data.user.afk = null; - message.data.user.markModified("afk"); await message.data.user.save(); message.replyT("general/afk:DELETED", { @@ -146,8 +145,6 @@ async function updateXp(message) { }, { mention: false }); } else memberData.exp = parseInt(newXp, 10); - memberData.markModified("level"); - memberData.markModified("exp"); await memberData.save(); } diff --git a/helpers/checkReminds.js b/helpers/checkReminds.js index c96b741f..66c92f53 100644 --- a/helpers/checkReminds.js +++ b/helpers/checkReminds.js @@ -49,7 +49,6 @@ module.exports.init = function (client) { user.reminds = user.reminds.filter(r => r.sendAt >= dateNow); - user.markModified("reminds"); await user.save(); if (user.reminds.length === 0) client.databaseCache.usersReminds.delete(user.id); diff --git a/helpers/cleanup.js b/helpers/cleanup.js index 4b012c61..dc35d613 100644 --- a/helpers/cleanup.js +++ b/helpers/cleanup.js @@ -30,7 +30,6 @@ module.exports.init = async function (client) { const index = transactions.indexOf(transaction); transactions.splice(index, 1); - member.markModified("transactions"); await member.save(); } } @@ -40,14 +39,13 @@ module.exports.init = async function (client) { setDaysTimeout(async () => { client.usersData.find({}, function (err, res) { for (const user of res) { - client.users.fetch(user.id).then(u => { + client.users.fetch(user.id).then(async u => { if (u.username.match(/.*Deleted User.* [A-z0-9]+/g)) { client.databaseCache.users.delete(u.id); client.usersData.deleteOne({ id: u.id }); client.logger.log(`Removed from database deleted user - ID: ${u.id} Username: ${u.username}`); - client.usersData.markModified(); - client.usersData.save(); + await client.usersData.save(); } }); } @@ -55,14 +53,13 @@ module.exports.init = async function (client) { client.membersData.find({}, function (err, res) { for (const user of res) { - client.users.fetch(user.id).then(u => { + client.users.fetch(user.id).then(async u => { if (u.username.match(/.*Deleted User.* [A-z0-9]+/g)) { client.databaseCache.members.delete(u.id); client.membersData.deleteOne({ id: u.id }); client.logger.log(`Removed from database deleted user - ID: ${u.id} Username: ${u.username}`); - client.membersData.markModified(); - client.membersData.save(); + await client.membersData.save(); } }); }