parent
bc888b9c11
commit
a459a39a2e
@ -0,0 +1,8 @@ |
||||
const mongoose = require('mongoose'); |
||||
|
||||
const StatusSchema = new mongoose.Schema({ |
||||
f: String, |
||||
statuses: [{id: String, clear: Date}] |
||||
}); |
||||
|
||||
module.exports = new mongoose.model('statuses', StatusSchema); |
@ -0,0 +1,11 @@ |
||||
const StatusCache = require('../models/statuses'); |
||||
|
||||
module.exports = async (id, time) => { |
||||
let statuses = await StatusCache.findOne({f: 'lol'}) || new StatusCache({f: 'lol', statuses: []}); |
||||
let exists = false; |
||||
let status; for (status of statuses.statuses) { |
||||
if (status.id === id) {statuses.statuses[statuses.statuses.indexOf(status)].clear = time; exists = true;} |
||||
} |
||||
if (!exists) {statuses.statuses.push({id: id, clear: time});} |
||||
return statuses.save(); |
||||
}; |
@ -0,0 +1,25 @@ |
||||
const UserData = require('../models/user'); |
||||
const StatusCache = require('../models/statuses'); |
||||
|
||||
module.exports = async function (client, lookFor) { |
||||
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 status; for (status of statuses) { |
||||
if (date.getTime() > status.clear.getTime()) { |
||||
if (lookFor && status.id !== lookFor) {continue;} |
||||
let tu = await UserData.findOne({uid: status.id}); |
||||
if (tu) { |
||||
tu.statusmsg = ''; |
||||
tu.statustype = ''; |
||||
tu.save(); |
||||
let u = await client.users.fetch(status.id); |
||||
if (u) {u.send("Heya! Your status has been set for 12 hours, so I've cleared it for you.").catch(() => {});} |
||||
} |
||||
} else {ns.push(status);} |
||||
} |
||||
statusesm.statuses = ns; |
||||
return statusesm.save(); |
||||
}; |
Loading…
Reference in new issue