clean statuses to prevent chat clutter

master
Kit Kasune 4 years ago
parent 669332adbe
commit 5708bf773d
  1. 8
      commands/clearstatus.js
  2. 12
      events/message.js
  3. 5
      util/mention.js
  4. 6
      util/siftstatuses.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(() => {});})});
}
};

@ -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}>`)) {

@ -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);
}
};

@ -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) {

Loading…
Cancel
Save