🗃️ /credits give is now on mongodb

This commit is contained in:
Axel Olausson Holtenäs 2022-02-27 21:38:03 +01:00
parent 9ca99874fc
commit d492f0d506
No known key found for this signature in database
GPG key ID: E3AE7E194AE017ED

View file

@ -1,8 +1,8 @@
const { Permissions } = require('discord.js'); const { Permissions } = require('discord.js');
const db = require('quick.db'); const credits = require('../../../helpers/database/models/creditSchema');
const debug = require('../../../handlers/debug');
const credits = new db.table('credits');
module.exports = async (interaction) => { module.exports = async (interaction) => {
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
const embed = { const embed = {
@ -24,15 +24,20 @@ module.exports = async (interaction) => {
}; };
return await interaction.editReply({ embeds: [embed], ephemeral: true }); return await interaction.editReply({ embeds: [embed], ephemeral: true });
} else { } else {
await credits.add(user.id, amount); await credits
.findOneAndUpdate({ userId: user.id }, { $inc: { balance: amount } }, { new: true })
const embed = { .then(async () => {
title: 'Give', const embed = {
description: `Gave ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`, title: 'Give',
color: 0x22bb33, description: `Gave ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`,
timestamp: new Date(), color: 0x22bb33,
footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT }, timestamp: new Date(),
}; footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT },
return await interaction.editReply({ embeds: [embed], ephemeral: true }); };
return await interaction.editReply({ embeds: [embed], ephemeral: true });
})
.catch(async (err) => {
debug(err);
});
} }
}; };