From 0c7a1d6110ed5a8ee137a4d1b59059c4ddf0cdcc Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 19 Feb 2021 13:23:31 -0700 Subject: [PATCH] add slap counter and model --- commands/slap.js | 12 +++++++++++- models/vscount.js | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 models/vscount.js diff --git a/commands/slap.js b/commands/slap.js index 6700f24..421ca08 100644 --- a/commands/slap.js +++ b/commands/slap.js @@ -1,6 +1,9 @@ const Discord = require('discord.js'); + const Saves = require('../models/saves'); const UserData = require('../models/user'); +const VC = require('../models/vscount'); + const makeId = require('../util/makeid'); module.exports = { @@ -19,13 +22,20 @@ module.exports = { if (!args.length) { return message.channel.send(message.guild ? "Please mention someone to slap!" : "Oi! You don't get to waltz into my DM just to slap me!");} if (mention && args[0].match(/^<@(?:!?)(?:\d+)>$/)) { - if (!message.guild) {return message.reply("Please make sure you're in a server so you can mention someone other than me to slap!");} + if (!message.guild) {return message.reply("Oi! You don't get to waltz into my DM just to slap me!");} if (!message.guild.members.cache.has(mention.id)) {return message.reply("That user is not in this server!");} if (message.author.id === mention.id) {return message.reply("Wait wouldn't slapping yourself be a form of self-harm? ToS is that you??");} + let slaps = await VC.findOne({uid: message.author.id, countOf: 'slap'}) || new VC({uid: message.author.id, countOf: 'slap'}); + slaps.against[mention.id] = slaps.against[mention.id] ? slaps.against[mention.id] + 1 : 1; + slaps.total++; + slaps.markModified(`against.${mention.id}`); + slaps.save(); return message.channel.send(new Discord.MessageEmbed() .setAuthor(`${message.guild ? message.member.displayName : message.author.username} slaps ${message.guild.members.cache.get(mention.id).displayName}`, message.author.avatarURL()) + .setDescription(`That makes slap **#${slaps.against[mention.id]}** from you to them!`) .setImage(String(Array.from(saves.values())[Math.floor(Math.random() * saves.size)])) .setColor('d93846') + .setFooter(`${slaps.total} slap${slaps.total === 1 ? '' : 's'} total`) ); } if (['s', 'save', 'n', 'new', 'a', 'add'].includes(args[0].toLowerCase())) { diff --git a/models/vscount.js b/models/vscount.js new file mode 100644 index 0000000..90ede8d --- /dev/null +++ b/models/vscount.js @@ -0,0 +1,10 @@ +const mongoose = require('mongoose'); + +const vscount = new mongoose.Schema({ + uid: String, + countOf: String, + total: ({type: Number, default: 0}), + against: ({type: Object, default: {}}) +}); + +module.exports = mongoose.model("vscount", vscount); \ No newline at end of file