Skip to content

Commit

Permalink
new econ command
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Wood committed Jan 24, 2024
1 parent 9b850d8 commit 44f107e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ client.on("messageCreate", async (message) => {
"https://img.freepik.com/premium-photo/abstract-blue-black-gradient-plain-studio-background_570543-8893.jpg"; // Replace with your default background URL
}

//if(!userData.guilds[guildId].users[userId].messageTimeout)

// Increment XP for the user in the specific guild
userData.guilds[guildId].users[userId].xp +=
Math.floor(Math.random() * 15) + 10;
Expand Down
89 changes: 89 additions & 0 deletions src/commands/economy/rob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const Command = require("../../structures/Command");
const { MessageEmbed } = require("discord.js");
const Profile = require("../../database/models/economy/profile.js");
const { createProfile } = require("../../utils/utils.js");

module.exports = class extends Command {
constructor(...args) {
super(...args, {
name: "rob",
description: "Rob someone!",
category: "Economy",
usage: "<user>",
examples: "rob @Peter"
})
}
async run(message, args) {
const user = message.mentions.members.first();
const profile = await Profile.findOne({ userID: message.author.id, guildId: message.guild.id });
if(!profile) {
await createProfile(user, message.guild);
await message.channel.sendCustom({
embeds: [
new MessageEmbed()
.setColor("BLURPLE")
.setDescription(`Creating profile.\nUse this command again to use it.`)
]
});
} else {
if (!profile.lastMonthly) {
await Profile.updateOne(
{ userID: message.author.id, guildId: message.guild.id }, { $set: { lastMonthly: Date.now() } }
);
let amount = Math.floor(Math.random() * profile.wallet);
await Profile.updateOne({
userID: user.id,
guildId: message.guild.id,
}, { $inc: { wallet: -amount }});
await Profile.updateOne({
userID: message.author.id,
guildId: message.guild.id,
}, { $inc: { wallet: amount } });

await message.channel.sendCustom({
embeds: [
new MessageEmbed()
.setDescription(`Successfully robbed ${user} for $${amount}.`)
.setColor(this.client.color.green)
.setTimestamp()
]
})
} else if (Date.now - profile.lastRobbed > 600000) {
await Profile.updateOne(
{ userID: message.author.id, guildId: message.guild.id }, { $set: { lastMonthly: Date.now() } }
);
let amount = Math.floor(Math.random() * profile.wallet);
await Profile.updateOne({
userID: user.id,
guildId: message.guild.id,
}, { $inc: { wallet: -amount }});
await Profile.updateOne({
userID: message.author.id,
guildId: message.guild.id,
}, { $inc: { wallet: amount } });

await message.channel.sendCustom({
embeds: [
new MessageEmbed()
.setDescription(`Successfully robbed ${user} for $${amount}.`)
.setColor(this.client.color.green)
.setTimestamp()
]
})
} else {
const lastRobbed = new Date(profile.lastRobbed);
const timeLeft = Math.round((lastRobbed.getTime() + 600000 - Date.now()) / 1000);
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft - minutes * 60;
await message.channel.sendCustom({
embeds: [
new MessageEmbed()
.setColor("BLURPLE")
.setTitle(`${message.author.username}'s Monthly`)
.setDescription(`You have to wait ${days}d ${hours}h ${minutes}m ${seconds}s before you can collect your monthly earnings!`)
]
})
}
}
}
}
1 change: 1 addition & 0 deletions src/database/models/economy/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let profile = new mongoose.Schema({
lastWeekly: { type: Date },
lastMonthly: { type: Date },
lastBeg: { type: Date },
lastRob: { type: Date },
passiveUpdated: { type: Date }
});

Expand Down
1 change: 1 addition & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ async function createProfile(user, guild) {
lastWeekly: new Date() - 604800000,
lastMonthly: new Date() - 2592000000,
lastBeg: new Date() - 180000,
lastRobbed: new Date() - 600000,
passiveUpdated: new Date()
})
newProfile.save().catch(() => {});
Expand Down

0 comments on commit 44f107e

Please sign in to comment.