*burp* global currency + image gen for it

master
Kit Kasune 3 years ago
parent 899d621dbf
commit be5a9cf08c
  1. 3
      bot.js
  2. 4
      commands/leveling/stats.js
  3. 6
      events/messageCreate.js
  4. 14
      models/monners.js
  5. 12
      util/lxp/cacheloop.js
  6. 19
      util/lxp/gainxp.js

@ -43,7 +43,8 @@ client.misc = {
charsID: new Discord.Collection(),
animeID: new Discord.Collection(),
charsNum: 0,
charsLove: new Discord.Collection()
charsLove: new Discord.Collection(),
monners: {}
},
loggers: {},
rl: readline.createInterface({input: process.stdin, output: process.stdout}),

@ -2,6 +2,8 @@ const Discord = require('discord.js');
const Canvas = require('canvas');
Canvas.registerFont('./resources/fonts/Nunito-Regular.ttf', {family: "Nunito"});
const Monners = require('../../models/monners');
const applyText = (base, canvas, text) => {
const ctx = canvas.getContext('2d');
let fontSize = base;
@ -61,12 +63,14 @@ 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 = client.misc.cache.monners[u.id] ? {currency: client.misc.cache.monners[u.id]} : await Monners.findOne({uid: u.id});
if (!message.channel.permissionsFor(message.guild.me.id).has("ATTACH_FILES")) {
return message.channel.send({embeds: [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 / 3) ** 2) * 2))}** needed to level up`, true)
.addField("Monners", `<:monners:926736756047495218> ${tmoon ? tmoon.currency : 0}`)
.setThumbnail(client.users.cache.get(u.id).avatarURL({size: 2048}))
.setColor("c375f0")
.setFooter({text: "Natsuki"})

@ -7,6 +7,7 @@ const UserData = require('../models/user');
const AR = require('../models/ar');
const LXP = require('../models/localxp');
const Monitors = require('../models/monitor');
const Monners = require('../models/monners');
const channelTypes = ["GUILD_MESSAGE", "DM", "GUILD_NEWS_THREAD", "GUILD_PRIVATE_THREAD", "GUILD_PUBLIC_THREAD", "GUILD_NEWS", "GROUP_DM", "GUILD_STORE", "GUILD_TEXT"];
@ -72,6 +73,11 @@ module.exports = async (client, message) => {
});
}
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 (message.guild && client.misc.cache.monitEnabled.includes(message.guild.id)) {
if (!client.misc.cache.monit[message.guild.id]) {
let tm = await Monitors.findOne({gid: message.guild.id});

@ -0,0 +1,14 @@
const mongoose = require('mongoose');
const Monners = mongoose.Schema({
uid: {type: String, unique: true},
currency: {type: Number, default: 0},
daily: {type: {
streak: Number,
last: Number,
total: Number
}, default: {}},
transactions: {type: Object, default: {}}
});
module.exports = mongoose.model('monners', Monners);

@ -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,21 @@ 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 (!Object.keys(client.misc.cache.monners).includes(user)) {return;}
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();
})
})
});
});
};

@ -18,6 +18,7 @@ const applyText = (canvas, text) => {
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 / 35) + 1);
let x = client.misc.cache.lxp.xp[channel.guild.id][member].level;
let max = Math.ceil(100 + (((x / 3) ** 2) * 2));
@ -31,8 +32,13 @@ 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(() => {});}
let cur = ((Math.floor((x + 1) / 10) + 1) * 5);
oldMonners = client.misc.cache.monners[member];
client.misc.cache.monners[member] += cur;
if (ch && ch.permissionsFor(ch.guild.me.id).has('SEND_MESSAGES')) {
if (!ch.permissionsFor(ch.guild.me.id).has('ATTACH_FILES')) {ch.send(`<:awoo:560193779764559896> <@${member}> has reached **Level ${x + 1}**!`).catch((e) => {/*console.error(e)*/});}
if (!ch.permissionsFor(ch.guild.me.id).has('ATTACH_FILES')) {ch.send(`<:awoo:560193779764559896> <@${member}> has reached **Level ${x + 1}**, and gained **${cur}** bonus Monners<:monners:926736756047495218>! <a:meowth_monners:926736229184208927>`).catch((e) => {/*console.error(e)*/});}
else {
const canvas = Canvas.createCanvas(1193, 411);
const context = canvas.getContext('2d');
@ -45,17 +51,20 @@ module.exports = async (client, member, channel) => {
context.font = '50px "Nunito"'; //top text
context.fillStyle = '#ffffff';
context.fillText(`Level up - Level ${x + 1}`, canvas.width / 2.8, canvas.height / 3);
context.fillText(`Level up - Level ${x + 1}`, canvas.width / 2.8, canvas.height / 1.7);
const monnersImage = await Canvas.loadImage('https://cdn.discordapp.com/emojis/926736756047495218');
context.drawImage(monnersImage, canvas.width / 2.8, canvas.height / 1.5, 58, 60);
context.fillText(`${oldMonners} + ${cur} Bonus Monners`, (canvas.width / 2.8) + 70, (canvas.height / 1.55) + 50);
context.font = applyText(canvas, `${ch.guild.members.cache.get(member).displayName}`); //center text
context.fillStyle = '#ffffff';
context.fillText(`${ch.guild.members.cache.get(member).displayName}`, canvas.width / 2.8, canvas.height / 1.5);
context.fillText(`${ch.guild.members.cache.get(member).displayName}`, canvas.width / 2.8, canvas.height / 2.7);
const avatar = await Canvas.loadImage(ch.guild.members.cache.get(member).displayAvatarURL({format: 'jpg', size: 2048}));
context.drawImage(avatar, 40, 40, canvas.height - 80, canvas.height - 80);
ch.send({
content: `<:awoo:560193779764559896> <@${member}> has reached **Level ${x + 1}**!`,
content: `<:awoo:560193779764559896> <@${member}> has reached **Level ${x + 1}**, and gained **${cur}** bonus Monners<:monners:926736756047495218>! <a:meowth_monners:926736229184208927>`,
files: [new Discord.MessageAttachment(canvas.toBuffer(), 'level-up.png')]
});
}

Loading…
Cancel
Save