🚑 Forgot to filter by guildId in creditSchema
This commit is contained in:
parent
1613191472
commit
1a650618ad
10 changed files with 19 additions and 13 deletions
|
@ -9,7 +9,7 @@ module.exports = async (interaction) => {
|
|||
const user = await interaction.options.getUser('user');
|
||||
|
||||
await credits
|
||||
.findOne({ userId: user ? user.id : interaction.user.id })
|
||||
.findOne({ userId: user ? user.id : interaction.user.id, guildId: interaction.member.guild.id })
|
||||
.then(async (data) => {
|
||||
if (!data) {
|
||||
const embed = {
|
||||
|
|
|
@ -9,7 +9,7 @@ module.exports = async (interaction) => {
|
|||
try {
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
const data = await credits.findOne({ userId: interaction.user.id });
|
||||
const data = await credits.findOne({ userId: interaction.user.id, guildId: interaction.member.guild.id });
|
||||
|
||||
if (user.id === interaction.user.id) {
|
||||
const embed = {
|
||||
|
@ -41,8 +41,8 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const fromUser = await credits.findOne({ userId: interaction.user.id });
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
const fromUser = await credits.findOne({ userId: interaction.user.id, guildId: interaction.member.guild.id });
|
||||
const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id });
|
||||
|
||||
fromUser.balance -= amount;
|
||||
toUser.balance += amount;
|
||||
|
|
|
@ -28,7 +28,7 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id });
|
||||
toUser.balance += amount;
|
||||
await toUser.save();
|
||||
const embed = {
|
||||
|
|
|
@ -23,7 +23,7 @@ module.exports = async (interaction) => {
|
|||
}
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
const user = await credits.findOne({ userId: interaction.user.id });
|
||||
const user = await credits.findOne({ userId: interaction.user.id, guildId: interaction.member.guild.id });
|
||||
const dmUser = interaction.client.users.cache.get(interaction.member.user.id);
|
||||
|
||||
if ((amount || user.balance) < 100) {
|
||||
|
|
|
@ -20,7 +20,7 @@ module.exports = async (interaction) => {
|
|||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id });
|
||||
toUser.balance = amount;
|
||||
await toUser.save();
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id });
|
||||
toUser.balance -= amount;
|
||||
await toUser.save();
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ const credits = require('../../../helpers/database/models/creditSchema');
|
|||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
await credits.find().then(async (data) => {
|
||||
await credits.find({ guildId: interaction.member.guild.id }).then(async (data) => {
|
||||
const topTen = data.sort((a, b) => (a.balance > b.balance ? -1 : 1)).slice(0, 10);
|
||||
|
||||
const item = (x, index) => `**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.balance)}`;
|
||||
|
|
|
@ -20,7 +20,7 @@ module.exports = async (interaction) => {
|
|||
const from = await interaction.options.getUser('from');
|
||||
const to = await interaction.options.getUser('to');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
const data = await credits.findOne({ userId: from.id });
|
||||
const data = await credits.findOne({ userId: from.id, guildId: interaction.member.guild.id });
|
||||
|
||||
if (amount <= 0) {
|
||||
const embed = {
|
||||
|
@ -42,8 +42,8 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const fromUser = await credits.findOne({ userId: from.id });
|
||||
const toUser = await credits.findOne({ userId: to.id });
|
||||
const fromUser = await credits.findOne({ userId: from.id, guildId: interaction.member.guild.id });
|
||||
const toUser = await credits.findOne({ userId: to.id, guildId: interaction.member.guild.id });
|
||||
|
||||
fromUser.balance -= amount;
|
||||
toUser.balance += amount;
|
||||
|
|
|
@ -17,7 +17,7 @@ module.exports = {
|
|||
if (!talkedRecently.has(message.author.id)) {
|
||||
await credits
|
||||
.findOneAndUpdate(
|
||||
{ userId: message.author.id },
|
||||
{ userId: message.author.id, guildId: message.guild.id },
|
||||
{ $inc: { balance: guild.credits.rate } },
|
||||
{ new: true, upsert: true },
|
||||
)
|
||||
|
|
|
@ -8,6 +8,12 @@ const creditSchema = new mongoose.Schema(
|
|||
unique: true,
|
||||
index: true,
|
||||
},
|
||||
guildId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
required: true,
|
||||
unique: true,
|
||||
index: true,
|
||||
},
|
||||
balance: {
|
||||
type: mongoose.SchemaTypes.Number,
|
||||
required: true,
|
||||
|
|
Loading…
Add table
Reference in a new issue