From 1097605ea9b0384f43a7cd59c06c1eb3a6ac2e80 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Sat, 24 Jul 2021 19:02:56 -0600 Subject: [PATCH] currency release --- bot.js | 3 ++- commands/leveling/stats.js | 7 +++++-- events/message.js | 19 ++++++++++++++----- models/monners.js | 10 ++++++++++ models/xp.js | 2 +- util/lxp/cacheloop.js | 11 +++++++++-- util/lxp/gainxp.js | 5 ++++- 7 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 models/monners.js diff --git a/bot.js b/bot.js index 5f0e83f..b973f02 100644 --- a/bot.js +++ b/bot.js @@ -23,7 +23,8 @@ client.misc = { xp: {}, hasLevelRoles: [] }, - mute: new Map() + mute: new Map(), + monners: {} }, loggers: {}, neptune: '782727129414500374' diff --git a/commands/leveling/stats.js b/commands/leveling/stats.js index 6e88018..a358233 100644 --- a/commands/leveling/stats.js +++ b/commands/leveling/stats.js @@ -1,10 +1,11 @@ const Discord = require('discord.js'); const LXP = require('../../models/localxp'); +const Monners = require('../../models/monners'); module.exports = { name: "stats", - aliases: ['level', 'xp', 'lvl'], + aliases: ['level', 'xp', 'lvl', '$', 'bal', 'balance', 'mooners', 'muni', 'currency'], meta: { category: 'Leveling', description: "View your rank in the server", @@ -14,7 +15,7 @@ module.exports = { }, help: new Discord.MessageEmbed() .setTitle("Help -> Stats") - .setDescription("View your level and XP in the server, or someone else's") + .setDescription("View your level, XP, and Mooners in the server, or someone else's") .addField("Syntax", "`stats [@user|userID]`"), async execute(message, msg, args, cmd, prefix, mention, client) { if (!client.misc.cache.lxp.enabled.includes(message.guild.id)) {return message.channel.send("Your server doesn't have leveling enabled!");} @@ -27,11 +28,13 @@ module.exports = { if (!txp.xp[u.id]) {return message.channel.send(`${u.id === message.author.id ? "You" : "That user"} doesn't have any leveling info available!`);} xp = {xp: txp.xp[u.id][0], level: txp.xp[u.id][1]}; } else {xp = client.misc.cache.lxp.xp[message.guild.id][u.id];} + let tmoon = await Monners.findOne({uid: u.id}); return message.channel.send(new Discord.MessageEmbed() .setTitle(`${u.displayName}${u.displayName.toLowerCase().endsWith('s') ? "'" : "'s"} Stats`) .setDescription("Local leveling stats") .addField("Level", xp.level, true) .addField("XP", `**${xp.xp}** of **${Math.ceil(100 + (((xp.level / 2.85) ** 2.2) * 2.5))}** needed to level up`, true) + .addField("Mooners", ` ${tmoon ? tmoon.currency : 0}`) .setThumbnail(client.users.cache.get(u.id).avatarURL({size: 2048})) .setColor("328ba8") .setFooter("Luno") diff --git a/events/message.js b/events/message.js index c698b9a..0ef8472 100644 --- a/events/message.js +++ b/events/message.js @@ -6,6 +6,7 @@ const wait = require('../util/wait'); const UserData = require('../models/user'); const AR = require('../models/ar'); const LXP = require('../models/localxp'); +const Monners = require('../models/monners'); module.exports = async (client, message) => { if (message.author.bot) {return undefined;} @@ -52,19 +53,27 @@ module.exports = async (client, message) => { } if (message.guild && client.misc.cache.lxp.enabled.includes(message.guild.id)) { - LXP.findOne({gid: message.guild.id}).then(xp => { + if (!client.misc.cache.lxp.xp[message.guild.id] || !client.misc.cache.lxp.xp[message.guild.id][message.author.id]) { + let xp = await LXP.findOne({gid: message.guild.id}); if (!client.misc.cache.lxp.xp[message.guild.id]) {client.misc.cache.lxp.xp[message.guild.id] = {};} if (!client.misc.cache.lxp.xp[message.guild.id][message.author.id]) {client.misc.cache.lxp.xp[message.guild.id][message.author.id] = { xp: xp.xp[message.author.id] ? xp.xp[message.author.id][0] : 0, level: xp.xp[message.author.id] ? xp.xp[message.author.id][1] : 1, lastXP: new Date().getTime() - 60000 };} - if (new Date().getTime() - client.misc.cache.lxp.xp[message.guild.id][message.author.id].lastXP > 60000) { - require('../util/lxp/gainxp')(client, message.member.id, message.channel); - } - }); + } + + if (!client.misc.cache.monners[message.author.id]) { + let tmonners = await Monners.findOne({uid: message.author.id}) || new Monners({uid: message.author.id}); + client.misc.cache.monners[message.author.id] = tmonners.currency; + } + + if (new Date().getTime() - client.misc.cache.lxp.xp[message.guild.id][message.author.id].lastXP > 60000) { + require('../util/lxp/gainxp')(client, message.member.id, message.channel); + } } + if (message.guild && message.channel.id === "815709333107114043") {return require('../util/newpartner.js')(message, client);} diff --git a/models/monners.js b/models/monners.js new file mode 100644 index 0000000..bc3f663 --- /dev/null +++ b/models/monners.js @@ -0,0 +1,10 @@ +const mongoose = require('mongoose'); + +const Monners = mongoose.Schema({ + uid: {type: String, unique: true}, + currency: {type: Number, default: 0}, + daily: {type: Object, default: {}}, + transactions: {type: Object, default: {}} +}); + +module.exports = mongoose.model('monners', Monners); \ No newline at end of file diff --git a/models/xp.js b/models/xp.js index abbc38d..2f99790 100644 --- a/models/xp.js +++ b/models/xp.js @@ -3,4 +3,4 @@ const mongoose = require('mongoose'); const XP = mongoose.Schema({ uid: {type: String, unique: true}, level: {type: Number} -}) \ No newline at end of file +}); \ No newline at end of file diff --git a/util/lxp/cacheloop.js b/util/lxp/cacheloop.js index a3f1ed2..0566a5a 100644 --- a/util/lxp/cacheloop.js +++ b/util/lxp/cacheloop.js @@ -1,4 +1,5 @@ const LXP = require('../../models/localxp'); +const Monners = require('../../models/monners'); module.exports = async (client) => { let cd = new Date().getTime(); @@ -6,14 +7,20 @@ module.exports = async (client) => { LXP.findOne({gid: gxp}).then(xp => { if (!xp) {return;} Object.keys(client.misc.cache.lxp.xp[gxp]).forEach(user => { + Monners.findOne({uid: user}).then(m => { + if (!m) {m = new Monners({uid: user});} + m.currency = client.misc.cache.monners[user]; + m.save(); + }); xp.xp[user] = [client.misc.cache.lxp.xp[gxp][user].xp, client.misc.cache.lxp.xp[gxp][user].level]; xp.markModified(`xp.${user}`); if (cd - client.misc.cache.lxp.xp[gxp][user].lastXP > 600000) { delete client.misc.cache.lxp.xp[gxp][user]; + delete client.misc.cache.monners[user]; if (!Object.keys(client.misc.cache.lxp.xp[gxp]).length) {delete client.misc.cache.lxp.xp[gxp];} } }); xp.save(); - }) - }) + }); + }); }; \ No newline at end of file diff --git a/util/lxp/gainxp.js b/util/lxp/gainxp.js index f6f0b45..8e36f88 100644 --- a/util/lxp/gainxp.js +++ b/util/lxp/gainxp.js @@ -4,6 +4,7 @@ const LR = require('../../models/levelroles'); module.exports = async (client, member, channel) => { client.misc.cache.lxp.xp[channel.guild.id][member].lastXP = new Date().getTime(); client.misc.cache.lxp.xp[channel.guild.id][member].xp += 10; + client.misc.cache.monners[member] += (Math.floor(client.misc.cache.lxp.xp[channel.guild.id][member].level / 25) + 1); let x = client.misc.cache.lxp.xp[channel.guild.id][member].level; let max = Math.ceil(100 + (((x / 2.85) ** 2.2) * 2.5)); @@ -17,7 +18,9 @@ module.exports = async (client, member, channel) => { try { let ch = xp.lvch.length ? channel.guild.channels.cache.get(xp.lvch) : channel; if (ch.partial) {await ch.fetch().catch(() => {});} - if (ch && ch.permissionsFor(ch.guild.me.id).has('SEND_MESSAGES')) {ch.send(`<:wew:835643715745087529> <@${member}> has reached **Level ${x + 1}**!`).catch((e) => {/*console.error(e)*/});} + let cur = ((Math.floor((x + 1) / 10) + 1) * 5); + client.misc.cache.monners[member] += cur; + if (ch && ch.permissionsFor(ch.guild.me.id).has('SEND_MESSAGES')) {ch.send(` <@${member}> has reached **Level ${x + 1}**, and gained **${cur}** bonus Mooners!`).catch((e) => {/*console.error(e)*/});} if (client.misc.cache.lxp.hasLevelRoles.includes(channel.guild.id)) { LR.findOne({gid: channel.guild.id}).then(async lr => { if (!lr) {return;}