From 85b16f8ad767c8c1dfb159dbc4bf391cb92a2334 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Sat, 20 Feb 2021 01:30:39 -0700 Subject: [PATCH] XP models, local xp setup --- commands/setupeconomy.js | 46 ++++++++++++++++++++++++++++++++++++++++ events/messageDelete.js | 2 +- models/localxp.js | 10 +++++++++ models/xp.js | 6 ++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 commands/setupeconomy.js create mode 100644 models/localxp.js create mode 100644 models/xp.js diff --git a/commands/setupeconomy.js b/commands/setupeconomy.js new file mode 100644 index 0000000..74e20b2 --- /dev/null +++ b/commands/setupeconomy.js @@ -0,0 +1,46 @@ +const Discord = require('discord.js'); + +const LXP = require('../models/localxp'); + +module.exports = { + name: "setupleveling", + aliases: ['setuplvl', 'setlvl', 'setleveling', 'levelingsetup', 'lvlset', 'lvlsetup'], + meta: { + category: 'Leveling', + description: "Setup and enable your server's local leveling!", + syntax: '`setupleveling`', + extra: "Requires administrator permissions. Disabled by default.", + guildOnly: true + }, + help: new Discord.MessageEmbed() + .setTitle("Help -> Local Leveling Setup") + .setDescription("Set up your local leveling system to allow your server's members to progress in ranks, which lets you enable leveling roles and shops *features not available at this time*") //TODO remove the "features not available" as soon as they are available + .addField("Syntax", "`setupleveling`") + .addField("Important Notice", "You must be a server administrator in order to use this command. Please know that local leveling systems can cost a great deal of our database storage space when used on larger servers, so please only enable this feature **if you will actually make use of it**, not just for fun."), + async execute(message, msg, args, cmd, prefix, mention, client) { + if (!message.member.permissions.has("ADMINISTRATOR")) {return message.channel.send("You must be a **server administrator** in order to use this command.");} + if (await LXP.findOne({gid: message.guild.id})) {return message.channel.send("Your leveling is already set up!");} //TODO add message to lead to disable cmd when complete + let am; + try { + am = await message.channel.send("Would you like to enable :thumbsup: or disable :thumbsdown: level up messages? (You can specify a set channel for this later.)"); + await am.react('👍'); + await am.react('👎'); + } catch {return message.channel.send(":thinking: hmmm... something went wrong there. I might not have permissions to add reactions to messages, and this could be the issue.");} + try { + let rc = am.createReactionCollector((r, u) => ['👍', '👎'].includes(r.emoji.name) && u.id === message.author.id, {max: 1, time: 60000}); + rc.on("collect", async r => { + let xp = new LXP({gid: message.guild.id}); + xp.msg = r.emoji.name === "👍"; + return message.channel.send(new Discord.MessageEmbed() + .setTitle("XP System Enabled!") + .setThumbnail(message.guild.iconURL({size: 2048})) + .setDescription(`Your server now has its leveling system enabled! If you enabled level up messages, you can set the channel for that using \`${prefix}levelchannel\`.`) //TODO update this with info on how the shiz works + .setColor("c375f0") + .setFooter("Natsuki", client.user.avatarURL()) + .setTimestamp() + ); + }); + rc.on("end", collected => {if (!collected.size) {return message.channel.send("Looks like you ran out of time! Try again?");}}); + } catch {return message.channel.send("Hmm... there was some error problem thingy that happened when I tried to enable XP for your server. If it keeps not working, then go yell at my devs!");} + } +}; \ No newline at end of file diff --git a/events/messageDelete.js b/events/messageDelete.js index 5fc5f7a..ea89835 100644 --- a/events/messageDelete.js +++ b/events/messageDelete.js @@ -16,7 +16,7 @@ module.exports = async (client, message) => { if (message.attachments.size) { if (message.attachments.first().url.includes(".png") || message.attachments.first().url.includes(".jpg") || message.attachments.first().url.includes(".gif")) {/*console.log('e');*/ try {mde.setImage(message.attachments.first().url);} catch {}} let av = Array.from(message.attachments.values()); - as = ''; for (let a of av) { + let as = ''; for (let a of av) { as += `[Att. ${av.indexOf(a) + 1}](${a.url})`; if (av.indexOf(a) + 1 < av.length) {as += ' | ';} } diff --git a/models/localxp.js b/models/localxp.js new file mode 100644 index 0000000..cd4b995 --- /dev/null +++ b/models/localxp.js @@ -0,0 +1,10 @@ +const mongoose = require('mongoose'); + +const lxp = new mongoose.Schema({ + gid: {type: String, unique: true}, + msg: {type: Boolean, default: true}, + xp: {type: Object, default: {}}, + lvch: {type: String, default: ''} +}); + +module.exports = mongoose.model('localxp', lxp); \ No newline at end of file diff --git a/models/xp.js b/models/xp.js new file mode 100644 index 0000000..abbc38d --- /dev/null +++ b/models/xp.js @@ -0,0 +1,6 @@ +const mongoose = require('mongoose'); + +const XP = mongoose.Schema({ + uid: {type: String, unique: true}, + level: {type: Number} +}) \ No newline at end of file