fix saving data (i hope)

This commit is contained in:
Jonny_Bro (Nikita) 2024-05-24 23:02:12 +05:00
parent 1896d3e41a
commit f296eca51a
Signed by: jonny_bro
GPG key ID: 3F1ECC04147E9BD8
38 changed files with 45 additions and 205 deletions

View file

@ -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<import("./Member")>} 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;
}

View file

@ -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({

View file

@ -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", {

View file

@ -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");

View file

@ -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({

View file

@ -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", {

View file

@ -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()}`, {

View file

@ -45,7 +45,6 @@ class Setlang extends BaseCommand {
guildData.language = language.name;
guildData.markModified("language");
await guildData.save();
return interaction.success("administration/setlang:SUCCESS", {

View file

@ -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", {

View file

@ -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", {

View file

@ -87,7 +87,6 @@ class Birthdate extends BaseCommand {
userData.birthdate = d;
userData.markModified("birthdate");
await userData.save();
interaction.success("economy/birthdate:SUCCESS", {

View file

@ -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", {

View file

@ -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(),

View file

@ -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;
});

View file

@ -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"))}`,

View file

@ -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;
});

View file

@ -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", {

View file

@ -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();
}

View file

@ -43,7 +43,6 @@ class Setbio extends BaseCommand {
userData.bio = newBio;
userData.markModified("bio");
await userData.save();
interaction.success("economy/setbio:SUCCESS");

View file

@ -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;

View file

@ -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 });

View file

@ -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: `<t:${Math.floor(isInCooldown / 1000)}:R>`,
});
}
if (isInCooldown && isInCooldown > 0 && isInCooldown > Math.floor(Date.now() / 1000))
return interaction.error("economy/work:COOLDOWN", {
time: `<t:${Math.floor(isInCooldown)}:R>`,
});
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);
}
}

View file

@ -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();
}

View file

@ -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();
});
}

View file

@ -44,7 +44,6 @@ class Afk extends BaseCommand {
userData.afk = reason;
userData.markModified("afk");
await userData.save();
interaction.success("general/afk:SUCCESS", {

View file

@ -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);

View file

@ -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", {

View file

@ -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;

View file

@ -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: {

View file

@ -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()}`, {

View file

@ -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({

View file

@ -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;

View file

@ -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 {

View file

@ -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();
}

View file

@ -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({

View file

@ -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();
}

View file

@ -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);

View file

@ -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();
}
});
}