From e2630e80f31880e1fef198a4ae0ba98f4415a9f4 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Wed, 5 Jan 2022 20:59:27 -0700 Subject: [PATCH] custom names for monners --- bot.js | 3 ++- commands/leveling/claim.js | 4 ++-- commands/leveling/daily.js | 2 +- commands/leveling/namemonners.js | 41 ++++++++++++++++++++++++++++++++ commands/leveling/stats.js | 2 +- events/messageCreate.js | 2 ++ events/ready.js | 4 ++++ models/monnersnames.js | 0 util/lxp/gainxp.js | 6 ++--- util/lxp/spawnchest.js | 2 +- 10 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 commands/leveling/namemonners.js create mode 100644 models/monnersnames.js diff --git a/bot.js b/bot.js index 39a24e3..124aeaf 100644 --- a/bot.js +++ b/bot.js @@ -52,7 +52,8 @@ client.misc = { animeID: new Discord.Collection(), charsNum: 0, charsLove: new Discord.Collection(), - monners: {} + monners: {}, + monnersNames: new Map() }, loggers: {}, rl: readline.createInterface({input: process.stdin, output: process.stdout}), diff --git a/commands/leveling/claim.js b/commands/leveling/claim.js index 18b6a91..a6d6f87 100644 --- a/commands/leveling/claim.js +++ b/commands/leveling/claim.js @@ -14,7 +14,7 @@ module.exports = { async execute(message, msg, args, cmd, prefix, mention, client) { if (!client.misc.cache.chests.enabled.includes(message.guild.id)) {return message.channel.send("Chests aren't enabled in this server!");} if (!client.misc.cache.chests.waiting.has(message.channel.id)) {return message.channel.send("There are no chests to claim in this channel.");} - if (!client.misc.cache.monners[message.author.id]) {return message.channel.send("There was an issue on my side with claiming your chest. This happened because I don't have your Monners info cached, so send a message anywhere and then try again. Sorry!");} + if (!client.misc.cache.monners[message.author.id]) {return message.channel.send(`There was an issue on my side with claiming your chest. This happened because I don't have your ${message.misc.mn} info cached, so send a message anywhere and then try again. Sorry!`);} let chest = client.misc.cache.chests.waiting.get(message.channel.id); client.misc.cache.monners[message.author.id] += chest.amount; @@ -22,7 +22,7 @@ module.exports = { chest.message.delete().catch(() => {}); return message.channel.send({embeds: [new Discord.MessageEmbed() .setAuthor({name: message.member.displayName, iconURL: message.member.displayAvatarURL()}) - .setDescription(`You've claimed ${client.utils.an(chest.rarity.name, true)} Chest with **${chest.amount} Monners<:monners:926736756047495218>**`) + .setDescription(`You've claimed ${client.utils.an(chest.rarity.name, true)} Chest with **${chest.amount} ${message.misc.mn}<:monners:926736756047495218>**`) .setColor(chest.rarity.color) ]}).catch(() => {}); } diff --git a/commands/leveling/daily.js b/commands/leveling/daily.js index 17888bb..3b105d6 100644 --- a/commands/leveling/daily.js +++ b/commands/leveling/daily.js @@ -44,7 +44,7 @@ module.exports = { .setAuthor({iconURL: message.guild ? message.member.displayAvatarURL() : message.author.iconURL(), name: message.guild ? message.member.displayName : message.author.username}) .setDescription(`You've claimed today's daily!`) .addField("Streak", streakIncrease ? `Your streak has **increased** to **${tm.daily.streak}**` : 'Your streak has **reset** to **1**.', true) - .addField("Bonus Monners", `<:monners:926736756047495218> ${bonus}`, true) + .addField(`Bonus ${message.misc.mn}`, `<:monners:926736756047495218> ${bonus}`, true) .addField("Total Dailies Claimed", `${tm.daily.total}`) .setColor('c375f0') ]}); diff --git a/commands/leveling/namemonners.js b/commands/leveling/namemonners.js new file mode 100644 index 0000000..1621217 --- /dev/null +++ b/commands/leveling/namemonners.js @@ -0,0 +1,41 @@ +const Discord = require('discord.js'); + +const Saves = require('../../models/saves'); + +module.exports = { + name: "namemonners", + aliases: ['namemon', 'nm'], + meta: { + category: 'Leveling', + description: "Rename the currency for your server", + syntax: '`namemonners `', + extra: null, + guildOnly: true + }, + help: new Discord.MessageEmbed() + .setTitle("Help -> Monners Naming") + .setDescription("Rename the Monners for your server. This merely a cosmetic effect. Monners gains will remain global regardless.") + .addField("Notice", "You must be an administrator in the server in order to edit these settings.") + .addField("Syntax", "`namemonners `"), + async execute(message, msg, args, cmd, prefix, mention, client) { + if (!args.length) {return message.channel.send(`Syntax: \`${prefix}namemonners \``);} + if (!message.member.permissions.has("ADMINISTRATOR")) {return message.channel.send("You must be an administrator in this server in order to do that.");} + let name = args.join(" "); + const names = await Saves.findOne({name: 'monnersnames'}); + const nsaves = names.saves; + if (name.toLowerCase() === 'clear') { + nsaves.delete(message.guild.id); + client.misc.cache.monnersNames.delete(message.guild.id); + message.channel.send("I'll now refer to currency in this server as Monners again."); + } else { + if (name.length > 12) {return message.channel.send("That name is too long! Keep it short and simple.");} + if (name.match(//gm)) {return message.channel.send("You can't have an emoji in your monners name.");} + if (!name.match(/^[a-zA-Z0-9-]+$/gm)) {return message.channel.send("Your name must contain only alphanumeric characters.");} + nsaves.set(message.guild.id, name); + client.misc.cache.monnersNames.set(message.guild.id, name); + message.channel.send(`Cool. I'll refer to Monners in this server as "${name}" now.`); + } + names.saves = nsaves; + return await names.save(); + } +}; \ No newline at end of file diff --git a/commands/leveling/stats.js b/commands/leveling/stats.js index da059ca..aaa8890 100644 --- a/commands/leveling/stats.js +++ b/commands/leveling/stats.js @@ -71,7 +71,7 @@ module.exports = { .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> ${tcur}`) + .addField(`${message.misc.mn}`, `<:monners:926736756047495218> ${tcur}`) .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 5af311a..fb1e8c2 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -35,6 +35,8 @@ module.exports = async (client, message) => { : message.content.slice(3 + client.user.id.length).trim().replace('\u200E', '').split(/\s+/g); let cmd = args.shift().toLowerCase().trim(); + message.misc = {mn: message.guild ? (client.misc.cache.monnersNames.get(message.guild.id) || 'Monners') : 'Monners'}; + if (message.content.includes("@everyone")) {return;} if ([`<@${client.user.id}>`, `<@!${client.user.id}>`].includes(msg)) { diff --git a/events/ready.js b/events/ready.js index 8defbdc..c87a803 100644 --- a/events/ready.js +++ b/events/ready.js @@ -5,6 +5,7 @@ const lastfm = require("lastfm"); const GuildSettings = require('../models/guild'); const BotDataSchema = require('../models/bot'); const LogData = require('../models/log'); +const Saves = require('../models/saves'); const siftStatuses = require('../util/siftstatuses'); const localXPCacheClean = require('../util/lxp/cacheloop'); @@ -82,6 +83,9 @@ module.exports = async client => { await require('../util/cache')(client); + let mnsaves = await Saves.findOne({name: 'monnersnames'}) || new Saves({name: 'monnersnames'}); + client.misc.cache.monnersNames = mnsaves.saves; + setInterval(() => localXPCacheClean(client), 150000); setInterval(() => monitorCacheClean(client), 150000); diff --git a/models/monnersnames.js b/models/monnersnames.js new file mode 100644 index 0000000..e69de29 diff --git a/util/lxp/gainxp.js b/util/lxp/gainxp.js index c43ccd3..ccf4d93 100644 --- a/util/lxp/gainxp.js +++ b/util/lxp/gainxp.js @@ -38,7 +38,7 @@ module.exports = async (client, member, channel) => { 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}**, and gained **${cur}** bonus Monners<:monners:926736756047495218>! `).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 ${client.misc.cache.monnersNames.get(channel.guild.id) || 'Monners'}<:monners:926736756047495218>! `).catch((e) => {/*console.error(e)*/});} else { const canvas = Canvas.createCanvas(1193, 411); const context = canvas.getContext('2d'); @@ -55,7 +55,7 @@ module.exports = async (client, member, channel) => { 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) + 57); + context.fillText(`${oldMonners} + ${cur} Bonus ${client.misc.cache.monnersNames.get(channel.guild.id) || 'Monners'}`, (canvas.width / 2.8) + 70, (canvas.height / 1.55) + 57); context.font = applyText(canvas, `${ch.guild.members.cache.get(member).displayName}`); //center text context.fillText(`${ch.guild.members.cache.get(member).displayName}`, canvas.width / 2.8, canvas.height / 2.7); @@ -64,7 +64,7 @@ module.exports = async (client, member, channel) => { context.drawImage(avatar, 40, 40, canvas.height - 80, canvas.height - 80); ch.send({ - content: `<:awoo:560193779764559896> <@${member}> has reached **Level ${x + 1}**, and gained **${cur}** bonus Monners<:monners:926736756047495218>! `, + content: `<:awoo:560193779764559896> <@${member}> has reached **Level ${x + 1}**, and gained **${cur}** bonus ${client.misc.cache.monnersNames.get(channel.guild.id) || 'Monners'}<:monners:926736756047495218>! `, files: [new Discord.MessageAttachment(canvas.toBuffer(), 'level-up.png')] }); } diff --git a/util/lxp/spawnchest.js b/util/lxp/spawnchest.js index 38fc7d1..65f94ef 100644 --- a/util/lxp/spawnchest.js +++ b/util/lxp/spawnchest.js @@ -66,7 +66,7 @@ module.exports = async (client, member, channel, prefix) => { let chestEmbed = new Discord.MessageEmbed() .setTitle(`${client.utils.an(rarity.name, true)} Chest has spawned!`) - .setDescription(`It has **${amount} Monners<:monners:926736756047495218>**`) + .setDescription(`It has **${amount} ${client.misc.cache.monnersNames.get(member.guild.id) || 'Monners'}<:monners:926736756047495218>**`) .setFooter({text: `Type ${prefix}claim to claim it!`}) .setColor(rarity.color) //create the chest message