diff --git a/commands/clearstatus.js b/commands/clearstatus.js index dd06cff..0c46737 100644 --- a/commands/clearstatus.js +++ b/commands/clearstatus.js @@ -15,14 +15,12 @@ module.exports = { }, 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 && !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(); - require('../util/siftstatuses')(client, message.author.id); - return message.reply("welcome back! I cleared your status."); + require('../util/siftstatuses')(client, message.author.id, true); + return message.reply("welcome back! I cleared your status.").then(m => {m.delete({timeout: 5000}).then(() => {message.delete().catch(() => {});})}); } }; \ No newline at end of file diff --git a/events/message.js b/events/message.js index 45f7a2c..a6a5de8 100644 --- a/events/message.js +++ b/events/message.js @@ -33,18 +33,14 @@ module.exports = async (client, message) => { } if (mention && message.guild) {require('../util/mention')(message, msg, args, cmd, prefix, mention, client);} - let tu = await UserData.findOne({uid: message.author.id}); + UserData.findOne({uid: message.author.id}).then(async (tu) => { if (tu && tu.statusmsg.length && tu.statusclearmode === 'auto') { tu.statusmsg = ''; tu.statustype = ''; tu.save(); - const statuses = await StatusCache.findOne({f: 'lol'}); - let status; for (status of statuses.statuses) { - if (status.id === message.author.id) {delete statuses.statuses.indexOf(status);} - } - statuses.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.'); - } + require('../util/siftstatuses')(client, message.author.id, true); + 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.').then(m => {m.delete({timeout: 5000});}); + }}); try { if (msg.startsWith(prefix) || msg.startsWith(`<@${client.user.id}>`) || msg.startsWith(`<@!${client.user.id}>`)) { diff --git a/util/mention.js b/util/mention.js index 14ead11..6809bb0 100644 --- a/util/mention.js +++ b/util/mention.js @@ -12,6 +12,9 @@ module.exports = async(message, msg, args, cmd, prefix, mention, client) => { if (tu && tu.statusmsg.length) { if (!client.misc.statusPings.has(message.guild.id)) {client.misc.statusPings.set(message.guild.id, new Discord.Collection());} client.misc.statusPings.get(message.guild.id).set(mention.id, new Date()); - return message.reply(`That user ${tu.statustype === 'dnd' ? 'wishes not to be disturbed' : 'is AFK'}. Reason: \`${tu.statusmsg}\`. (This status was set ${moment(tu.statussetat.getTime()).fromNow()})`); + let m = await message.channel.send(`That user ${tu.statustype === 'dnd' ? 'wishes not to be disturbed' : 'is AFK'}. Reason: ${tu.statusmsg}.${tu.statssetat ? ` \`(This status was set ${moment(tu.statussetat.getTime()).fromNow()})\`` : ''}`); + await require('../util/wait')(10000); + m.delete().catch((e) => {console.log(e);}); + console.log(m); } }; \ No newline at end of file diff --git a/util/siftstatuses.js b/util/siftstatuses.js index 7cfe378..320526e 100644 --- a/util/siftstatuses.js +++ b/util/siftstatuses.js @@ -1,14 +1,16 @@ const UserData = require('../models/user'); const StatusCache = require('../models/statuses'); -module.exports = async function (client, lookFor) { +module.exports = async function (client, lookFor, forceClear) { let statusesm = await StatusCache.findOne({f: 'lol'}) || new StatusCache({f: 'lol', statuses: []}); let statuses = statusesm.statuses; let date = new Date(); let ns = []; if (!client) {return 'no client found or given';} + let forcePass; let status; for (status of statuses) { - if (date.getTime() > status.clear.getTime()) { + forcePass = lookFor && status.id === lookFor && forceClear; + if (date.getTime() > status.clear.getTime() || forcePass) { if (lookFor && status.id !== lookFor) {continue;} let tu = await UserData.findOne({uid: status.id}); if (tu) {