From c3be0dbc134c8ea6b1573102c5caafe0260c2aa8 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Sat, 10 Oct 2020 14:10:56 -0600 Subject: [PATCH] Status clearing and user command tracking --- commands/clearstatus.js | 20 ++++++++++++++++++++ events/message.js | 9 +++++++++ util/oncommand.js | 7 ++++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 commands/clearstatus.js diff --git a/commands/clearstatus.js b/commands/clearstatus.js new file mode 100644 index 0000000..61a3681 --- /dev/null +++ b/commands/clearstatus.js @@ -0,0 +1,20 @@ +const Discord = require('discord.js'); +const mongooes = require('mongoose'); +const UserData = require('../models/user'); + +module.exports = { + name: "clearstatus", + aliases: ['statusclear', 'cs'], + help: "Clears your status, if you have one set. Does not take any arguments.", + async execute(message, msg, args, cmd, prefix, mention, client) { + let tu = await UserData.findOne({uid: message.author.id}); + if (!tu && !tu.statusmsg.length) { + return message.reply("you have no status for me to clear"); + } + if (tu.statusclearmode === "auto") {return;} + tu.statusmsg = ''; + tu.statustype = ''; + tu.save(); + return message.reply("welcome back! I cleared your status."); + } +}; \ No newline at end of file diff --git a/events/message.js b/events/message.js index 1abcd5d..dd22d9b 100644 --- a/events/message.js +++ b/events/message.js @@ -1,6 +1,8 @@ const Discord = require('discord.js'); +const mongoose = require('mongoose'); const chalk = require('chalk'); const wait = require('../util/wait'); +const UserData = require('../models/user'); module.exports = async (client, message) => { if (message.author.bot) {return undefined;} @@ -23,6 +25,13 @@ module.exports = async (client, message) => { var cmd = args.shift().toLowerCase().trim(); if (mention && message.guild) {require('../util/mention')(message, msg, args, cmd, prefix, mention, client);} + let tu = await UserData.findOne({uid: message.author.id}); + if (tu && tu.statusmsg.length && tu.statusclearmode === 'auto') { + tu.statusmsg = ''; + tu.statustype = ''; + tu.save(); + message.reply('Hey there! You asked me to clear your status when you send a message next, so I went ahead and did that for you.'); + } try { if (msg.startsWith(prefix) || msg.startsWith(`<@${client.user.id}>`) || msg.startsWith(`<@!${client.user.id}>`)) { diff --git a/util/oncommand.js b/util/oncommand.js index 8f00588..efad3a6 100644 --- a/util/oncommand.js +++ b/util/oncommand.js @@ -1,6 +1,7 @@ const Discord = require('discord.js'); const mongoose = require('mongoose'); const chalk = require('chalk'); +const UserData = require('../models/user'); module.exports = async (message, msg, args, cmd, prefix, mention, client) => { /*const config = client.config; @@ -15,6 +16,10 @@ module.exports = async (message, msg, args, cmd, prefix, mention, client) => { let botData = await require('../models/bot').findOne({finder: 'lel'}); botData.commands = botData.commands + 1; - botData.save(); + let tu = await UserData.findOne({uid: message.author.id}) + ? await UserData.findOne({uid: message.author.id}) + : new UserData({uid: message.author.id}); + tu.commands = tu.commands + 1; + tu.save(); }; \ No newline at end of file