From be5a9cf08cc35413d78889164e796d8b0c9f89f7 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Sat, 1 Jan 2022 00:49:40 -0700 Subject: [PATCH] *burp* global currency + image gen for it --- bot.js | 3 ++- commands/leveling/stats.js | 4 ++++ events/messageCreate.js | 6 ++++++ models/monners.js | 14 ++++++++++++++ util/lxp/cacheloop.js | 12 ++++++++++-- util/lxp/gainxp.js | 19 ++++++++++++++----- 6 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 models/monners.js diff --git a/bot.js b/bot.js index 733ada4..41074a9 100644 --- a/bot.js +++ b/bot.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}), diff --git a/commands/leveling/stats.js b/commands/leveling/stats.js index 7255a88..1d692f3 100644 --- a/commands/leveling/stats.js +++ b/commands/leveling/stats.js @@ -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"}) diff --git a/events/messageCreate.js b/events/messageCreate.js index 836aa15..83ebcec 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -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}); diff --git a/models/monners.js b/models/monners.js new file mode 100644 index 0000000..08cbcff --- /dev/null +++ b/models/monners.js @@ -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); \ No newline at end of file diff --git a/util/lxp/cacheloop.js b/util/lxp/cacheloop.js index a3f1ed2..bde7a52 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,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(); - }) - }) + }); + }); }; \ No newline at end of file diff --git a/util/lxp/gainxp.js b/util/lxp/gainxp.js index 30d5ca8..7814842 100644 --- a/util/lxp/gainxp.js +++ b/util/lxp/gainxp.js @@ -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>! `).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>! `, files: [new Discord.MessageAttachment(canvas.toBuffer(), 'level-up.png')] }); }