From c039ade4f44ebc9e98a1953143b8d46c4e3b03eb Mon Sep 17 00:00:00 2001 From: CodyDimensions <92368816+CodyDimensions@users.noreply.github.com> Date: Fri, 4 Feb 2022 06:45:42 -0800 Subject: [PATCH 1/2] Add files via upload --- daily.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 daily.js diff --git a/daily.js b/daily.js new file mode 100644 index 0000000..220967d --- /dev/null +++ b/daily.js @@ -0,0 +1,32 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const { MessageEmbed } = require('discord.js'); +const db = require('quick.db'); +const ms = require('ms'); + +module.exports = { + data: new SlashCommandBuilder() //create a new slash command + .setName('daily') //name of the command + .setDescription('Get daily coins'), //description of the cmd + async execute(client, interaction) { + let user = interaction.user; //interaction user (the one who use the slash command) + let amount = 300; // the amount of money for daily reward + + let time = 86400000; // 1 day --> ms + let daily = await db.get(`daily_${user.id}`) // get the db of the Date of getting daily reward + + let duration = ms(time - (Date.now() - daily), { long: true }); // the time (1 day) minus (the date of using the cmd minus the daily db). Then convert the ms to hours/minutes/s, simply make the time writing long. + + if(daily !== null && time - (Date.now() - daily) > 0) { // if the daily db is not null and the time (1 day) minus (the date of using the cmd minus the daily db) is bigger than 0 + interaction.reply({ content: `**You will be able to get daily reward after \`${duration}\`** `, ephemeral: true }); + } else { // if it is 24hrs later since last time using this command (successfully) then it will return an embed + let embed = new MessageEmbed() + .setTitle(`Here are your daily coins, ${user.username}`) + .setDescription(`Congratulation! You received ${amount} coins!`) + interaction.reply({ embeds: [embed] }); //send a embed that u received coins successfully + + db.add(`wallet_${user.id}`, amount) //add the amount of money to wallet db + db.set(`daily_${user.id}`, Date.now()) // set the Date this command is used, so next time for using this command is 24 hours later. + } + } + +} \ No newline at end of file From 83941ec6764de668216ddf8c691b7a2c23c2a5be Mon Sep 17 00:00:00 2001 From: CodyDimensions <92368816+CodyDimensions@users.noreply.github.com> Date: Fri, 4 Feb 2022 22:46:19 +0800 Subject: [PATCH 2/2] Delete balance.js --- balance.js | 56 ------------------------------------------------------ 1 file changed, 56 deletions(-) delete mode 100644 balance.js diff --git a/balance.js b/balance.js deleted file mode 100644 index 29a85b3..0000000 --- a/balance.js +++ /dev/null @@ -1,56 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { MessageEmbed } = require('discord.js'); -const db = require('quick.db'); //the npm we use to create/get database - -module.exports = { - data: new SlashCommandBuilder() //create a new slash cmd with slash command builder - .setName('balance') //set the name of the slash command - .setDescription('Displays the balance of a user.') //description of the slash cmd - .addUserOption((option) => { //add a slash cmd options for user to choose which balance of the user he/she wants to display - return option - .setName('user') //name of the option - .setDescription('Select a user') //description of the option - .setRequired(false) //user can choose a user or check the balance of interaction user - }), - /* you can use this also if you don't want to use {} - .addUserOption((option) => //add a slash cmd options for user to choose which balance of the user he/she wants to display - option - .setName('user') //name of the option - .setDescription('Select a user') //description of the option - .setRequired(false) //user can choose a user or check the balance of interaction user - ), - */ - async execute(client, interaction) { - let user = interaction.options.getUser('user') //get the user from the options of slash cmd - - //user getted in options and get the wallet * bank db of them - let wallet = db.get(`wallet_${user.id}`) //get the wallet db of a user - let bank = db.get(`bank_${user.id}`) //get the bank db of a user - - //user did not select any user, so they get the interaction user's wallet/bank db - let authorWallet = db.get(`wallet_${interaction.user.id}`) - let authorBank = db.get(`bank_${interaction.user.id}`) - - if(wallet == null) wallet = 0; //if the wallet db is null, it will show 0 in the wallet variable - if(bank == null) bank = 0; //if bank db is null, it will show 0 in the bank variable - - if(authorWallet == null) authorWallet = 0; //set the authorWallet var to 0 - if(authorBank == null) authorBank = 0; //set the authorBank var to 0 - - if(!user) { //if the user didn't select any user in option - let authorEmbed = new MessageEmbed() //create a new embed message - .setTitle(`${interaction.user.username}'s Balance`) - .setDescription(`**Wallet:** ${authorWallet}\n**Bank:** ${authorBank}`) - .setThumbnail(interaction.user.displayAvatarURL({ dynamic: true })) - .setTimestamp() - interaction.reply({ embeds: [authorEmbed] }) - } else { //the user that selected user in option - let userEmbed = new MessageEmbed() //create a new embed message - .setTitle(`${user.username}'s Balance`) - .setDescription(`**Wallet:** ${wallet}\n**Bank:** ${bank}`) - .setThumbnail(user.displayAvatarURL({ dynamic: true })) - .setTimestamp() - interaction.reply({ embeds: [userEmbed] }) - } - } -};