currency release

master
Kit Kasune 3 years ago
parent 2809deb3dc
commit 1097605ea9
  1. 3
      bot.js
  2. 7
      commands/leveling/stats.js
  3. 19
      events/message.js
  4. 10
      models/monners.js
  5. 2
      models/xp.js
  6. 11
      util/lxp/cacheloop.js
  7. 5
      util/lxp/gainxp.js

@ -23,7 +23,8 @@ client.misc = {
xp: {}, xp: {},
hasLevelRoles: [] hasLevelRoles: []
}, },
mute: new Map() mute: new Map(),
monners: {}
}, },
loggers: {}, loggers: {},
neptune: '782727129414500374' neptune: '782727129414500374'

@ -1,10 +1,11 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
const LXP = require('../../models/localxp'); const LXP = require('../../models/localxp');
const Monners = require('../../models/monners');
module.exports = { module.exports = {
name: "stats", name: "stats",
aliases: ['level', 'xp', 'lvl'], aliases: ['level', 'xp', 'lvl', '$', 'bal', 'balance', 'mooners', 'muni', 'currency'],
meta: { meta: {
category: 'Leveling', category: 'Leveling',
description: "View your rank in the server", description: "View your rank in the server",
@ -14,7 +15,7 @@ module.exports = {
}, },
help: new Discord.MessageEmbed() help: new Discord.MessageEmbed()
.setTitle("Help -> Stats") .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]`"), .addField("Syntax", "`stats [@user|userID]`"),
async execute(message, msg, args, cmd, prefix, mention, client) { 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!");} 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!`);} 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]}; 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];} } 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() return message.channel.send(new Discord.MessageEmbed()
.setTitle(`${u.displayName}${u.displayName.toLowerCase().endsWith('s') ? "'" : "'s"} Stats`) .setTitle(`${u.displayName}${u.displayName.toLowerCase().endsWith('s') ? "'" : "'s"} Stats`)
.setDescription("Local leveling stats") .setDescription("Local leveling stats")
.addField("Level", xp.level, true) .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("XP", `**${xp.xp}** of **${Math.ceil(100 + (((xp.level / 2.85) ** 2.2) * 2.5))}** needed to level up`, true)
.addField("Mooners", `<a:CF_mooners:868652679717589012> ${tmoon ? tmoon.currency : 0}`)
.setThumbnail(client.users.cache.get(u.id).avatarURL({size: 2048})) .setThumbnail(client.users.cache.get(u.id).avatarURL({size: 2048}))
.setColor("328ba8") .setColor("328ba8")
.setFooter("Luno") .setFooter("Luno")

@ -6,6 +6,7 @@ const wait = require('../util/wait');
const UserData = require('../models/user'); const UserData = require('../models/user');
const AR = require('../models/ar'); const AR = require('../models/ar');
const LXP = require('../models/localxp'); const LXP = require('../models/localxp');
const Monners = require('../models/monners');
module.exports = async (client, message) => { module.exports = async (client, message) => {
if (message.author.bot) {return undefined;} 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)) { 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]) {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] = { 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, 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, level: xp.xp[message.author.id] ? xp.xp[message.author.id][1] : 1,
lastXP: new Date().getTime() - 60000 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);} if (message.guild && message.channel.id === "815709333107114043") {return require('../util/newpartner.js')(message, client);}

@ -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);

@ -3,4 +3,4 @@ const mongoose = require('mongoose');
const XP = mongoose.Schema({ const XP = mongoose.Schema({
uid: {type: String, unique: true}, uid: {type: String, unique: true},
level: {type: Number} level: {type: Number}
}) });

@ -1,4 +1,5 @@
const LXP = require('../../models/localxp'); const LXP = require('../../models/localxp');
const Monners = require('../../models/monners');
module.exports = async (client) => { module.exports = async (client) => {
let cd = new Date().getTime(); let cd = new Date().getTime();
@ -6,14 +7,20 @@ module.exports = async (client) => {
LXP.findOne({gid: gxp}).then(xp => { LXP.findOne({gid: gxp}).then(xp => {
if (!xp) {return;} if (!xp) {return;}
Object.keys(client.misc.cache.lxp.xp[gxp]).forEach(user => { 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.xp[user] = [client.misc.cache.lxp.xp[gxp][user].xp, client.misc.cache.lxp.xp[gxp][user].level];
xp.markModified(`xp.${user}`); xp.markModified(`xp.${user}`);
if (cd - client.misc.cache.lxp.xp[gxp][user].lastXP > 600000) { if (cd - client.misc.cache.lxp.xp[gxp][user].lastXP > 600000) {
delete client.misc.cache.lxp.xp[gxp][user]; 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];} if (!Object.keys(client.misc.cache.lxp.xp[gxp]).length) {delete client.misc.cache.lxp.xp[gxp];}
} }
}); });
xp.save(); xp.save();
}) });
}) });
}; };

@ -4,6 +4,7 @@ const LR = require('../../models/levelroles');
module.exports = async (client, member, channel) => { 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].lastXP = new Date().getTime();
client.misc.cache.lxp.xp[channel.guild.id][member].xp += 10; 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 x = client.misc.cache.lxp.xp[channel.guild.id][member].level;
let max = Math.ceil(100 + (((x / 2.85) ** 2.2) * 2.5)); let max = Math.ceil(100 + (((x / 2.85) ** 2.2) * 2.5));
@ -17,7 +18,9 @@ module.exports = async (client, member, channel) => {
try { try {
let ch = xp.lvch.length ? channel.guild.channels.cache.get(xp.lvch) : channel; let ch = xp.lvch.length ? channel.guild.channels.cache.get(xp.lvch) : channel;
if (ch.partial) {await ch.fetch().catch(() => {});} 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(`<a:CF_moonheart:868653516913246208> <@${member}> has reached **Level ${x + 1}**, and gained **${cur}** bonus Mooners<a:CF_mooners:868652679717589012>!`).catch((e) => {/*console.error(e)*/});}
if (client.misc.cache.lxp.hasLevelRoles.includes(channel.guild.id)) { if (client.misc.cache.lxp.hasLevelRoles.includes(channel.guild.id)) {
LR.findOne({gid: channel.guild.id}).then(async lr => { LR.findOne({gid: channel.guild.id}).then(async lr => {
if (!lr) {return;} if (!lr) {return;}

Loading…
Cancel
Save