diff --git a/src/commands/credits/addons/balance.js b/src/commands/credits/addons/balance.js index bbe2548..75c3c5b 100644 --- a/src/commands/credits/addons/balance.js +++ b/src/commands/credits/addons/balance.js @@ -9,32 +9,38 @@ module.exports = async (interaction) => { const user = await interaction.options.getUser('user'); await credits - // eslint-disable-next-line max-len - .findOne({ userId: user ? user.id : interaction.user.id, guildId: interaction.member.guild.id }) - .then(async (data) => { - if (!data) { + // eslint-disable-next-line max-len + .findOne({ + userId : user ? user.id : interaction.user.id, + guildId : interaction.member.guild.id + }) + .then(async (data) => { + if (!data) { + const embed = { + title : 'Balance', + description : `${user} has no credits.`, + color : config.colors.success, + timestamp : new Date(), + footer : + {iconURL : config.footer.icon, text : config.footer.text}, + }; + + return interaction.editReply( + {embeds : [ embed ], ephemeral : true}); + } + const {balance} = data; + const embed = { - title: 'Balance', - description: `${user} has no credits.`, - color: config.colors.success, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Balance', + description : + `${user ? `${user} has` : 'You have'} ${creditNoun(balance)}.`, + color : config.colors.success, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - - return interaction.editReply({ embeds: [embed], ephemeral: true }); - } - const { balance } = data; - - const embed = { - title: 'Balance', - description: `${user ? `${user} has` : 'You have'} ${creditNoun(balance)}.`, - color: config.colors.success, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); - }) - .catch(async (err) => logger.error(err)); + return interaction.editReply({embeds : [ embed ], ephemeral : true}); + }) + .catch(async (err) => logger.error(err)); } catch { await logger.error(); } diff --git a/src/commands/credits/addons/gift.js b/src/commands/credits/addons/gift.js index 8dc35f8..837d6cb 100644 --- a/src/commands/credits/addons/gift.js +++ b/src/commands/credits/addons/gift.js @@ -11,51 +11,59 @@ module.exports = async (interaction) => { const amount = await interaction.options.getInteger('amount'); const reason = await interaction.options.getString('reason'); // eslint-disable-next-line max-len - const data = await credits.findOne({ userId: interaction.user.id, guildId: interaction.member.guild.id }); + const data = await credits.findOne( + {userId : interaction.user.id, guildId : interaction.member.guild.id}); if (user.id === interaction.user.id) { const embed = { - title: 'Gift failed', - description: "You can't pay yourself.", - color: 0xbb2124, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Gift failed', + description : "You can't pay yourself.", + color : 0xbb2124, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } if (amount <= 0) { const embed = { - title: 'Gift failed', - description: "You can't pay zero or below.", - color: 0xbb2124, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Gift failed', + description : "You can't pay zero or below.", + color : 0xbb2124, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } if (data.balance < amount) { const embed = { - title: 'Gift', - description: `You have insufficient credits. Your balance is ${data.balance}`, - color: 0xbb2124, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Gift', + description : + `You have insufficient credits. Your balance is ${data.balance}`, + color : 0xbb2124, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } // eslint-disable-next-line max-len - 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 }); + 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}); if (!toUser) { const embed = { - title: 'Gift', - description: 'That user has no credits, I can not gift credits to the user', - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Gift', + description : + 'That user has no credits, I can not gift credits to the user', + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({embeds : [ embed ], ephemeral : true}); } fromUser.balance -= amount; toUser.balance += amount; @@ -63,27 +71,34 @@ module.exports = async (interaction) => { await saveUser(fromUser, toUser); const interactionEmbed = { - title: 'Gift', - description: `You sent ${creditNoun(amount)} to ${user}${reason ? ` with reason: ${reason}` : ''}. Your new balance is ${creditNoun( - fromUser.balance, - )}.`, - color: 0x22bb33, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Gift', + description : `You sent ${creditNoun(amount)} to ${user}${ + reason ? ` with reason: ${reason}` : ''}. Your new balance is ${ + creditNoun( + fromUser.balance, + )}.`, + color : 0x22bb33, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; const dmEmbed = { - title: 'Gift', - description: `You received ${creditNoun(amount)} from ${interaction.user}${reason ? ` with reason: ${reason}` : ''}. Your new balance is ${creditNoun( - toUser.balance, - )}.`, - color: 0x22bb33, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Gift', + description : + `You received ${creditNoun(amount)} from ${interaction.user}${ + reason ? ` with reason: ${reason}` : ''}. Your new balance is ${ + creditNoun( + toUser.balance, + )}.`, + color : 0x22bb33, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; const dmUser = await interaction.client.users.cache.get(user.id); - await dmUser.send({ embeds: [dmEmbed] }); - await logger.debug(`Gift sent from: ${interaction.user.username} to: ${user.username}`); - return await interaction.editReply({ embeds: [interactionEmbed], ephemeral: true }); + await dmUser.send({embeds : [ dmEmbed ]}); + await logger.debug( + `Gift sent from: ${interaction.user.username} to: ${user.username}`); + return await interaction.editReply( + {embeds : [ interactionEmbed ], ephemeral : true}); } catch (e) { await logger.error(e); } diff --git a/src/commands/credits/addons/give.js b/src/commands/credits/addons/give.js index 8398089..28214c3 100644 --- a/src/commands/credits/addons/give.js +++ b/src/commands/credits/addons/give.js @@ -1,4 +1,4 @@ -const { Permissions } = require('discord.js'); +const {Permissions} = require('discord.js'); const config = require('../../../../config.json'); const logger = require('../../../handlers/logger'); @@ -10,51 +10,56 @@ module.exports = async (interaction) => { try { if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { const embed = { - title: 'Give failed', - description: 'You need to have permission to manage this guild (MANAGE_GUILD)', + title : 'Give failed', + description : + 'You need to have permission to manage this guild (MANAGE_GUILD)', }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } const user = await interaction.options.getUser('user'); const amount = await interaction.options.getInteger('amount'); if (amount <= 0) { const embed = { - title: 'Give', - description: "You can't give zero or below.", - color: 0xbb2124, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Give', + description : "You can't give zero or below.", + color : 0xbb2124, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } - const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id }); + const toUser = await credits.findOne( + {userId : user.id, guildId : interaction.member.guild.id}); if (!toUser) { const embed = { - title: 'Give', - description: 'That user has no credits, I can not give credits to the user', - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Give', + description : + 'That user has no credits, I can not give credits to the user', + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({embeds : [ embed ], ephemeral : true}); } toUser.balance += amount; await toUser.save(); const embed = { - title: 'Give', - description: `Gave ${creditNoun(amount)} to ${user}.`, - color: 0x22bb33, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Give', + description : `Gave ${creditNoun(amount)} to ${user}.`, + color : 0x22bb33, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; await logger.debug( - `Administrator: ${interaction.user.username} gave ${ - amount <= 1 ? `${amount} credit` : `${amount} credits` - } to ${user.username}`, + `Administrator: ${interaction.user.username} gave ${ + amount <= 1 ? `${amount} credit` + : `${amount} credits`} to ${user.username}`, ); - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply({embeds : [ embed ], ephemeral : true}); } catch (e) { await logger.error(e); } diff --git a/src/commands/credits/addons/redeem.js b/src/commands/credits/addons/redeem.js index f6c9f2a..e0acbff 100644 --- a/src/commands/credits/addons/redeem.js +++ b/src/commands/credits/addons/redeem.js @@ -1,4 +1,4 @@ -const { v4: uuidv4 } = require('uuid'); +const {v4 : uuidv4} = require('uuid'); const axios = require('axios'); const config = require('../../../../config.json'); const logger = require('../../../handlers/logger'); @@ -13,108 +13,120 @@ module.exports = async (interaction) => { try { if (config.disable.redeem) { const embed = { - title: 'Redeem failed', - description: 'Redeem is disabled until further.', - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Redeem failed', + description : 'Redeem is disabled until further.', + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } const amount = await interaction.options.getInteger('amount'); // eslint-disable-next-line max-len - 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); + 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) { const embed = { - title: 'Redeem', - description: `You can't redeem below 100. Your balance is ${user.balance}.`, - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Redeem', + description : + `You can't redeem below 100. Your balance is ${user.balance}.`, + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } if ((amount || user.balance) > 1000000) { const embed = { - title: 'Redeem', - description: `You can't redeem over 1,000,000. Your balance is ${user.balance}.`, - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Redeem', + description : + `You can't redeem over 1,000,000. Your balance is ${user.balance}.`, + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } if (user.balance < amount) { const embed = { - title: 'Redeem', - description: `You have insufficient credits. Your balance is ${user.balance}.`, - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Redeem', + description : + `You have insufficient credits. Your balance is ${user.balance}.`, + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } const code = uuidv4(); - const guild = await guilds.findOne({ guildId: interaction.member.guild.id }); + const guild = await guilds.findOne({guildId : interaction.member.guild.id}); const api = axios.create({ - baseURL: guild.credits.url, - headers: { Authorization: `Bearer ${guild.credits.token}` }, + baseURL : guild.credits.url, + headers : {Authorization : `Bearer ${guild.credits.token}`}, }); await api - .post('vouchers', { - uses: 1, - code, - credits: amount || user.balance, - memo: `${interaction.createdTimestamp} - ${interaction.user.id}`, - }) - .then(async () => { - const dmEmbed = { - title: 'Redeem', - description: `Your new balance is ${user.balance - (amount || user.balance)}.`, - fields: [ - { name: 'Code', value: `${code}`, inline: true }, - { - name: 'Credits', - value: `${amount || user.balance}`, - inline: true, - }, - ], - color: config.colors.success, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; - const interactionEmbed = { - title: 'Redeem', - description: 'Code is sent in DM!', - color: config.colors.success, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; - user.balance -= amount || user.balance; + .post('vouchers', { + uses : 1, + code, + credits : amount || user.balance, + memo : `${interaction.createdTimestamp} - ${interaction.user.id}`, + }) + .then(async () => { + const dmEmbed = { + title : 'Redeem', + description : `Your new balance is ${ + user.balance - (amount || user.balance)}.`, + fields : [ + {name : 'Code', value : `${code}`, inline : true}, + { + name : 'Credits', + value : `${amount || user.balance}`, + inline : true, + }, + ], + color : config.colors.success, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, + }; + const interactionEmbed = { + title : 'Redeem', + description : 'Code is sent in DM!', + color : config.colors.success, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, + }; + user.balance -= amount || user.balance; - await user.save(); + await user.save(); - await logger.debug(`User: ${user.username} redeemed: ${creditNoun(amount)}`); - await dmUser.send({ embeds: [dmEmbed] }); - await interaction.editReply({ embeds: [interactionEmbed], ephemeral: true }); - }) - .catch(async (e) => { - await logger.error(e); - const embed = { - title: 'Redeem', - description: 'Something went wrong.', - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); - }); + await logger.debug( + `User: ${user.username} redeemed: ${creditNoun(amount)}`); + await dmUser.send({embeds : [ dmEmbed ]}); + await interaction.editReply( + {embeds : [ interactionEmbed ], ephemeral : true}); + }) + .catch(async (e) => { + await logger.error(e); + const embed = { + title : 'Redeem', + description : 'Something went wrong.', + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, + }; + return interaction.editReply({embeds : [ embed ], ephemeral : true}); + }); } catch (e) { await logger.error(e); } diff --git a/src/commands/credits/addons/settings.js b/src/commands/credits/addons/settings.js index 496c97d..55cfcaa 100644 --- a/src/commands/credits/addons/settings.js +++ b/src/commands/credits/addons/settings.js @@ -15,36 +15,51 @@ module.exports = async (interaction) => { const workRate = await interaction.options.getNumber('work-rate'); const workTimeout = await interaction.options.getNumber('work-timeout'); - const guild = await guilds.findOne({ guildId: interaction.member.guild.id }); + const guild = await guilds.findOne({guildId : interaction.member.guild.id}); guild.credits.status = status !== null ? status : guild.credits.status; guild.credits.url = url !== null ? url : guild.credits.url; guild.credits.token = token !== null ? token : guild.credits.token; guild.credits.rate = rate !== null ? rate : guild.credits.rate; guild.credits.timeout = timeout !== null ? timeout : guild.credits.timeout; - guild.credits.workRate = workRate !== null ? workRate : guild.credits.workRate; + guild.credits.workRate = + workRate !== null ? workRate : guild.credits.workRate; // eslint-disable-next-line max-len - guild.credits.workTimeout = workTimeout !== null ? workTimeout : guild.credits.workTimeout; + guild.credits.workTimeout = + workTimeout !== null ? workTimeout : guild.credits.workTimeout; // eslint-disable-next-line max-len - guild.credits.minimumLength = minimumLength !== null ? minimumLength : guild.credits.minimumLength; + guild.credits.minimumLength = + minimumLength !== null ? minimumLength : guild.credits.minimumLength; await guild.save(); const embed = { - title: 'Credits', - description: 'Following settings is set', - color: config.colors.success, - fields: [{ name: 'Status', value: `${guild.credits.status}`, inline: true }, - { name: 'URL', value: `${guild.credits.url}`, inline: true }, - { name: 'Token', value: `${guild.credits.token}` }, - { name: 'Rate', value: `${guild.credits.rate}`, inline: true }, - { name: 'Minimum Length', value: `${guild.credits.minimumLength}`, inline: true }, - { name: 'Timeout', value: `${guild.credits.timeout}`, inline: true }, - { name: 'Work Rate', value: `${guild.credits.workRate}`, inline: true }, - { name: 'Work Timeout', value: `${guild.credits.workTimeout}`, inline: true }], - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Credits', + description : 'Following settings is set', + color : config.colors.success, + fields : [ + {name : 'Status', value : `${guild.credits.status}`, inline : true}, + {name : 'URL', value : `${guild.credits.url}`, inline : true}, + {name : 'Token', value : `${guild.credits.token}`}, + {name : 'Rate', value : `${guild.credits.rate}`, inline : true}, { + name : 'Minimum Length', + value : `${guild.credits.minimumLength}`, + inline : true + }, + {name : 'Timeout', value : `${guild.credits.timeout}`, inline : true}, { + name : 'Work Rate', + value : `${guild.credits.workRate}`, + inline : true + }, + { + name : 'Work Timeout', + value : `${guild.credits.workTimeout}`, + inline : true + } + ], + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({embeds : [ embed ], ephemeral : true}); } catch (e) { logger.error(e); } diff --git a/src/commands/credits/addons/transfer.js b/src/commands/credits/addons/transfer.js index 55a29ee..37bce57 100644 --- a/src/commands/credits/addons/transfer.js +++ b/src/commands/credits/addons/transfer.js @@ -1,4 +1,4 @@ -const { Permissions } = require('discord.js'); +const {Permissions} = require('discord.js'); const config = require('../../../../config.json'); const logger = require('../../../handlers/logger'); @@ -11,60 +11,69 @@ module.exports = async (interaction) => { try { if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { const embed = { - title: 'Transfer failed', - description: 'You need to have permission to manage this guild (MANAGE_GUILD)', + title : 'Transfer failed', + description : + 'You need to have permission to manage this guild (MANAGE_GUILD)', }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } const from = await interaction.options.getUser('from'); const to = await interaction.options.getUser('to'); const amount = await interaction.options.getInteger('amount'); // eslint-disable-next-line max-len - 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 }); + 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}); if (!fromUser) { const embed = { - title: 'Transfer', - description: 'That user has no credits, I can not transfer credits from the user', - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Transfer', + description : + 'That user has no credits, I can not transfer credits from the user', + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({embeds : [ embed ], ephemeral : true}); } if (!toUser) { const embed = { - title: 'Transfer', - description: 'That user has no credits, I can not transfer credits to the user', - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Transfer', + description : + 'That user has no credits, I can not transfer credits to the user', + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({embeds : [ embed ], ephemeral : true}); } if (amount <= 0) { const embed = { - title: 'Transfer failed', - description: "You can't transfer zero or below.", - color: 0xbb2124, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Transfer failed', + description : "You can't transfer zero or below.", + color : 0xbb2124, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } if (fromUser.balance < amount) { const embed = { - title: 'Transfer', - description: `${from.username} has insufficient credits. ${from.username} balance is ${fromUser.balance}`, - color: 0xbb2124, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Transfer', + description : `${from.username} has insufficient credits. ${ + from.username} balance is ${fromUser.balance}`, + color : 0xbb2124, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + return await interaction.editReply( + {embeds : [ embed ], ephemeral : true}); } fromUser.balance -= amount; @@ -73,19 +82,28 @@ module.exports = async (interaction) => { await saveUser(fromUser, toUser); const embed = { - title: 'Transfer', - description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`, - color: 0x22bb33, - fields: [ - { name: `${from.username} Balance`, value: `${fromUser.balance}`, inline: true }, - { name: `${to.username} Balance`, value: `${toUser.balance}`, inline: true }, + title : 'Transfer', + description : `You sent ${creditNoun(amount)} from ${from} to ${to}.`, + color : 0x22bb33, + fields : [ + { + name : `${from.username} Balance`, + value : `${fromUser.balance}`, + inline : true + }, + { + name : `${to.username} Balance`, + value : `${toUser.balance}`, + inline : true + }, ], - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - await logger.debug(`Gift sent from: ${interaction.user.username} to: ${to.username}`); - return await interaction.editReply({ embeds: [embed], ephemeral: true }); + await logger.debug( + `Gift sent from: ${interaction.user.username} to: ${to.username}`); + return await interaction.editReply({embeds : [ embed ], ephemeral : true}); } catch (e) { logger.error(e); } diff --git a/src/commands/credits/addons/work.js b/src/commands/credits/addons/work.js index 5df8ae4..9745d33 100644 --- a/src/commands/credits/addons/work.js +++ b/src/commands/credits/addons/work.js @@ -9,55 +9,57 @@ const workedRecently = new Set(); // eslint-disable-next-line consistent-return module.exports = async (interaction) => { try { - const guild = await guilds.findOne({ guildId: interaction.member.guild.id }); + const guild = await guilds.findOne({guildId : interaction.member.guild.id}); if (!workedRecently.has(interaction.member.id)) { const creditsEarned = Math.floor(Math.random() * guild.credits.workRate); await credits - .findOneAndUpdate( - { userId: interaction.member.id, guildId: interaction.member.guild.id }, - { $inc: { balance: creditsEarned } }, - { new: true, upsert: true }, - ) - .then(async () => { - logger.debug(`Credits added to user: ${interaction.member.id}`); - const embed = { - title: 'Work', - description: `You earned ${creditNoun(creditsEarned)}`, - color: config.colors.success, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; + .findOneAndUpdate( + { + userId : interaction.member.id, + guildId : interaction.member.guild.id + }, + {$inc : {balance : creditsEarned}}, + {new : true, upsert : true}, + ) + .then(async () => { + logger.debug(`Credits added to user: ${interaction.member.id}`); + const embed = { + title : 'Work', + description : `You earned ${creditNoun(creditsEarned)}`, + color : config.colors.success, + timestamp : new Date(), + footer : + {iconURL : config.footer.icon, text : config.footer.text}, + }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); - }) - .catch(async (err) => { - await logger.error(err); - }); + return interaction.editReply( + {embeds : [ embed ], ephemeral : true}); + }) + .catch(async (err) => { await logger.error(err); }); workedRecently.add(interaction.member.id); setTimeout(() => { logger.debug( - `User: ${interaction.member.id} has not worked within last ${ - guild.credits.workTimeout / 1000 - } seconds, work can be runned`, + `User: ${interaction.member.id} has not worked within last ${ + guild.credits.workTimeout / 1000} seconds, work can be runned`, ); workedRecently.delete(interaction.member.id); }, guild.credits.timeout); } else { logger.debug( - `User: ${interaction.member.id} has already worked within last ${ - guild.credits.workTimeout / 1000 - } seconds, no work is runned`, + `User: ${interaction.member.id} has already worked within last ${ + guild.credits.workTimeout / 1000} seconds, no work is runned`, ); const embed = { - title: 'Work', - description: `You can not work now, wait ${guild.credits.workTimeout / 1000} seconds until timeout is out.`, - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Work', + description : `You can not work now, wait ${ + guild.credits.workTimeout / 1000} seconds until timeout is out.`, + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({embeds : [ embed ], ephemeral : true}); } } catch (e) { await logger.error(e); diff --git a/src/commands/credits/index.js b/src/commands/credits/index.js index b03aa11..56b6a0b 100644 --- a/src/commands/credits/index.js +++ b/src/commands/credits/index.js @@ -1,5 +1,5 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { Permissions } = require('discord.js'); +const {SlashCommandBuilder} = require('@discordjs/builders'); +const {Permissions} = require('discord.js'); const config = require('../../../config.json'); const guilds = require('../../helpers/database/models/guildSchema'); @@ -16,96 +16,170 @@ const settings = require('./addons/settings'); const work = require('./addons/work'); module.exports = { - permissions: new Permissions([ + permissions : new Permissions([ Permissions.FLAGS.MANAGE_MESSAGES, Permissions.FLAGS.ADMINISTRATOR, ]), - guildOnly: true, - botAdminOnly: false, - data: new SlashCommandBuilder() - .setName('credits') - .setDescription('Manage your credits.') - .addSubcommand((subcommand) => subcommand - .setName('give') - .setDescription('Give credits to a user. (ADMIN)') - .addUserOption((option) => option.setName('user').setDescription('The user you want to pay.').setRequired(true)) - .addIntegerOption((option) => option.setName('amount').setDescription('The amount you will pay.').setRequired(true))) - .addSubcommand((subcommand) => subcommand - .setName('take') - .setDescription('Take credits from a user. (ADMIN)') - .addUserOption((option) => option - .setName('user') - .setDescription('The user you want to take credits from.') - .setRequired(true)) - .addIntegerOption((option) => option.setName('amount').setDescription('The amount you will take.').setRequired(true))) - .addSubcommand((subcommand) => subcommand - .setName('balance') - .setDescription("Check a user's balance.") - .addUserOption((option) => option - .setName('user') - .setDescription('The user whose balance you want to check.') - .setRequired(false))) - .addSubcommand((subcommand) => subcommand - .setName('redeem') - .setDescription('Redeem your credits.') - .addIntegerOption((option) => option.setName('amount').setDescription('How much credit you want to withdraw.'))) - .addSubcommand((subcommand) => subcommand - .setName('gift') - .setDescription('Gift someone credits from your credits.') - .addUserOption((option) => option.setName('user').setDescription('The user you want to pay.').setRequired(true)) - .addIntegerOption((option) => option.setName('amount').setDescription('The amount you will pay.').setRequired(true)) - .addStringOption((option) => option.setName('reason').setDescription('Your reason.'))) - .addSubcommand((subcommand) => subcommand.setName('top').setDescription('Check the top balance.')) - .addSubcommand((subcommand) => subcommand - .setName('transfer') - .setDescription('Transfer credits from a user to another user. (ADMIN)') - .addUserOption((option) => option - .setName('from') - .setDescription('The user you want to take credits from.') - .setRequired(true)) - .addUserOption((option) => option - .setName('to') - .setDescription('The user you want to give credits to.') - .setRequired(true)) - .addIntegerOption((option) => option.setName('amount').setDescription('The amount you will transfer.').setRequired(true))) - .addSubcommand((subcommand) => subcommand - .setName('set') - .setDescription('Set credits on a user. (ADMIN)') - .addUserOption((option) => option - .setName('user') - .setDescription('The user you want to set credits on.') - .setRequired(true)) - .addIntegerOption((option) => option.setName('amount').setDescription('The amount you will set.').setRequired(true))) - .addSubcommand((subcommand) => subcommand - .setName('settings') - .setDescription('Manage credit settings. (ADMIN)') - .addBooleanOption((option) => option.setName('status').setDescription('Toggle credits.')) - .addStringOption((option) => option.setName('url').setDescription('Controlpanel.gg URL.')) - .addStringOption((option) => option.setName('token').setDescription('Controlpanel.gg token.')) - .addNumberOption((option) => option.setName('rate').setDescription('Credits rate.')) - .addNumberOption((option) => option.setName('minimum-length').setDescription('Minimum length for credits.')) - .addNumberOption((option) => option.setName('work-rate').setDescription('Work rate (rate).')) - .addNumberOption((option) => option.setName('work-timeout').setDescription('Timeout between working for credits (milliseconds).')) - .addNumberOption((option) => option.setName('timeout').setDescription('Timeout between credits (milliseconds).'))) - .addSubcommand((subcommand) => subcommand - .setName('work') - .setDescription('Work for credits.')), + guildOnly : true, + botAdminOnly : false, + data : + new SlashCommandBuilder() + .setName('credits') + .setDescription('Manage your credits.') + .addSubcommand( + (subcommand) => + subcommand.setName('give') + .setDescription('Give credits to a user. (ADMIN)') + .addUserOption( + (option) => + option.setName('user') + .setDescription('The user you want to pay.') + .setRequired(true)) + .addIntegerOption( + (option) => + option.setName('amount') + .setDescription('The amount you will pay.') + .setRequired(true))) + .addSubcommand( + (subcommand) => + subcommand.setName('take') + .setDescription('Take credits from a user. (ADMIN)') + .addUserOption( + (option) => + option.setName('user') + .setDescription( + 'The user you want to take credits from.') + .setRequired(true)) + .addIntegerOption( + (option) => + option.setName('amount') + .setDescription('The amount you will take.') + .setRequired(true))) + .addSubcommand( + (subcommand) => + subcommand.setName('balance') + .setDescription("Check a user's balance.") + .addUserOption( + (option) => + option.setName('user') + .setDescription( + 'The user whose balance you want to check.') + .setRequired(false))) + .addSubcommand( + (subcommand) => + subcommand.setName('redeem') + .setDescription('Redeem your credits.') + .addIntegerOption( + (option) => option.setName('amount').setDescription( + 'How much credit you want to withdraw.'))) + .addSubcommand( + (subcommand) => + subcommand.setName('gift') + .setDescription('Gift someone credits from your credits.') + .addUserOption( + (option) => + option.setName('user') + .setDescription('The user you want to pay.') + .setRequired(true)) + .addIntegerOption( + (option) => + option.setName('amount') + .setDescription('The amount you will pay.') + .setRequired(true)) + .addStringOption( + (option) => option.setName('reason').setDescription( + 'Your reason.'))) + .addSubcommand((subcommand) => + subcommand.setName('top').setDescription( + 'Check the top balance.')) + .addSubcommand( + (subcommand) => + subcommand.setName('transfer') + .setDescription( + 'Transfer credits from a user to another user. (ADMIN)') + .addUserOption( + (option) => + option.setName('from') + .setDescription( + 'The user you want to take credits from.') + .setRequired(true)) + .addUserOption( + (option) => + option.setName('to') + .setDescription( + 'The user you want to give credits to.') + .setRequired(true)) + .addIntegerOption( + (option) => option.setName('amount') + .setDescription( + 'The amount you will transfer.') + .setRequired(true))) + .addSubcommand( + (subcommand) => + subcommand.setName('set') + .setDescription('Set credits on a user. (ADMIN)') + .addUserOption( + (option) => + option.setName('user') + .setDescription( + 'The user you want to set credits on.') + .setRequired(true)) + .addIntegerOption( + (option) => + option.setName('amount') + .setDescription('The amount you will set.') + .setRequired(true))) + .addSubcommand( + (subcommand) => + subcommand.setName('settings') + .setDescription('Manage credit settings. (ADMIN)') + .addBooleanOption( + (option) => option.setName('status').setDescription( + 'Toggle credits.')) + .addStringOption((option) => + option.setName('url').setDescription( + 'Controlpanel.gg URL.')) + .addStringOption( + (option) => option.setName('token').setDescription( + 'Controlpanel.gg token.')) + .addNumberOption( + (option) => option.setName('rate').setDescription( + 'Credits rate.')) + .addNumberOption( + (option) => option.setName('minimum-length') + .setDescription( + 'Minimum length for credits.')) + .addNumberOption( + (option) => option.setName('work-rate') + .setDescription('Work rate (rate).')) + .addNumberOption( + (option) => + option.setName('work-timeout') + .setDescription( + 'Timeout between working for credits (milliseconds).')) + .addNumberOption( + (option) => option.setName('timeout').setDescription( + 'Timeout between credits (milliseconds).'))) + .addSubcommand((subcommand) => + subcommand.setName('work').setDescription( + 'Work for credits.')), async execute(interaction) { - const guild = await guilds.findOne({ guildId: interaction.member.guild.id }); + const guild = await guilds.findOne({guildId : interaction.member.guild.id}); if (interaction.options.getSubcommand() === 'settings') { await settings(interaction); } - if (guild.credits.status === false && interaction.options.getSubcommand() !== 'settings') { + if (guild.credits.status === false && + interaction.options.getSubcommand() !== 'settings') { const embed = { - title: 'Credits', - description: 'Please enable credits by ``/credits settings``', - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, + title : 'Credits', + description : 'Please enable credits by ``/credits settings``', + color : config.colors.error, + timestamp : new Date(), + footer : {iconURL : config.footer.icon, text : config.footer.text}, }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); + return interaction.editReply({embeds : [ embed ], ephemeral : true}); } if (interaction.options.getSubcommand() === 'balance') { diff --git a/src/events/guildCreate.js b/src/events/guildCreate.js index 31a46aa..a730750 100644 --- a/src/events/guildCreate.js +++ b/src/events/guildCreate.js @@ -3,16 +3,16 @@ const logger = require('../handlers/logger'); const guilds = require('../helpers/database/models/guildSchema'); module.exports = { - name: 'interactionCreate', + name : 'interactionCreate', async execute(guild) { - const guildExist = await guilds.findOne({ guildId: guild.id }) - .then(logger.debug(`Found guild: ${guild.id}`)) - .catch(logger.error); + const guildExist = await guilds.findOne({guildId : guild.id}) + .then(logger.debug(`Found guild: ${guild.id}`)) + .catch(logger.error); if (!guildExist) { - await guilds.create({ guildId: guild.id }) - .then(() => logger.debug(`Create guild: ${guild.id} was success`)) - .catch((e) => logger.error(e)); + await guilds.create({guildId : guild.id}) + .then(() => logger.debug(`Create guild: ${guild.id} was success`)) + .catch((e) => logger.error(e)); } }, }; diff --git a/src/helpers/database/models/guildSchema.js b/src/helpers/database/models/guildSchema.js index e27aca5..3a19607 100644 --- a/src/helpers/database/models/guildSchema.js +++ b/src/helpers/database/models/guildSchema.js @@ -1,42 +1,47 @@ const mongoose = require('mongoose'); const guildSchema = new mongoose.Schema( - { - guildId: { - type: mongoose.SchemaTypes.Decimal128, - required: true, - unique: true, - index: true, - }, - credits: { - status: { - type: mongoose.SchemaTypes.Boolean, - default: false, + { + guildId : { + type : mongoose.SchemaTypes.Decimal128, + required : true, + unique : true, + index : true, }, - url: { - type: mongoose.SchemaTypes.String, - }, - token: { - type: mongoose.SchemaTypes.String, - }, - rate: { - type: mongoose.SchemaTypes.Number, default: 1, - }, - minimumLength: { - type: mongoose.SchemaTypes.Number, default: 5, - }, - timeout: { - type: mongoose.SchemaTypes.Number, default: 5000, - }, - workRate: { - type: mongoose.SchemaTypes.Number, default: 15, - }, - workTimeout: { - type: mongoose.SchemaTypes.Number, default: 900000, + credits : { + status : { + type : mongoose.SchemaTypes.Boolean, + default : false, + }, + url : { + type : mongoose.SchemaTypes.String, + }, + token : { + type : mongoose.SchemaTypes.String, + }, + rate : { + type : mongoose.SchemaTypes.Number, + default : 1, + }, + minimumLength : { + type : mongoose.SchemaTypes.Number, + default : 5, + }, + timeout : { + type : mongoose.SchemaTypes.Number, + default : 5000, + }, + workRate : { + type : mongoose.SchemaTypes.Number, + default : 15, + }, + workTimeout : { + type : mongoose.SchemaTypes.Number, + default : 900000, + }, }, }, - }, - { timestamps: true }, + {timestamps : true}, ); module.exports = mongoose.model('guild', guildSchema);