Status caching and ping warning ratelimit

master
Kit Kasune 4 years ago
parent bc888b9c11
commit a459a39a2e
  1. 10
      bot.js
  2. 4
      commands/afk.js
  3. 4
      commands/blacklist.js
  4. 4
      commands/dnd.js
  5. 9
      events/message.js
  6. 25
      events/ready.js
  7. 8
      models/statuses.js
  8. 21
      package-lock.json
  9. 1
      package.json
  10. 11
      util/cachestatus.js
  11. 11
      util/mention.js
  12. 25
      util/siftstatuses.js

@ -13,9 +13,13 @@ async function init() {
['command', 'event'].forEach(x => require(`./handle/${x}`)(client)); ['command', 'event'].forEach(x => require(`./handle/${x}`)(client));
client.developers = ["330547934951112705", "673477059904929802"]; client.developers = ["330547934951112705", "673477059904929802"];
client.misc = {};
client.misc.savers = ['497598953206841375']; client.misc = {
client.misc.activeDMs = new Discord.Collection(); savers: ['497598953206841375'],
activeDMs: new Discord.Collection(),
statusPings: new Discord.Collection()
};
client.utils = {}; client.utils = {};
client.utils.logch = async () => {return client.guilds.cache.get('762707532417335296').channels.cache.get('762732961753595915');}; client.utils.logch = async () => {return client.guilds.cache.get('762707532417335296').channels.cache.get('762732961753595915');};

@ -24,7 +24,11 @@ module.exports = {
if (reason.length > 150) {return message.reply("That status a bit long; keep it under 150 characters.");} if (reason.length > 150) {return message.reply("That status a bit long; keep it under 150 characters.");}
tu.statustype = 'afk'; tu.statustype = 'afk';
tu.statusmsg = reason.trim(); tu.statusmsg = reason.trim();
tu.statussetat = new Date();
let tempDate = new Date();
tu.statusclearat = tempDate.setHours(tempDate.getHours() + 12);
tu.save(); tu.save();
require('../util/cachestatus')(message.author.id, tempDate.setHours(tempDate.getHours() + 12));
return message.reply(`I set your ${tu.statusclearmode === 'auto' ? 'automatically' : 'manually'}-clearing AFK message to: ${reason.trim()}`); return message.reply(`I set your ${tu.statusclearmode === 'auto' ? 'automatically' : 'manually'}-clearing AFK message to: ${reason.trim()}`);
} }
}; };

@ -60,7 +60,7 @@ module.exports = {
if (!blacklistUser) {return message.reply("You must specify a user to blacklist!");} if (!blacklistUser) {return message.reply("You must specify a user to blacklist!");}
let usersData = await UserData.findOne( { uid: blacklistUser } ) || new UserData({uid: blacklistUser}); let usersData = await UserData.findOne( { uid: blacklistUser } ) || new UserData({uid: blacklistUser});
if (!checkPerms(tu, usersData);) {return;} if (!checkPerms(tu, usersData)) {return;}
if (usersData.blacklisted === true) {return message.reply('they\'re already blacklisted :eyes:');} if (usersData.blacklisted === true) {return message.reply('they\'re already blacklisted :eyes:');}
@ -73,7 +73,7 @@ module.exports = {
if (!blacklistedUser) { return message.reply("You need to specify who you're letting free..." );} if (!blacklistedUser) { return message.reply("You need to specify who you're letting free..." );}
let userData = await UserData.findOne( { uid: blacklistedUser } ) || new UserData({uid: blacklistedUser}); let userData = await UserData.findOne( { uid: blacklistedUser } ) || new UserData({uid: blacklistedUser});
if (!checkPerms(tu, userData);) {return;} if (!checkPerms(tu, userData)) {return;}
if(userData.blacklisted === false) {return message.reply('hate to break it you... they\'re not even blacklisted!');} if(userData.blacklisted === false) {return message.reply('hate to break it you... they\'re not even blacklisted!');}

@ -24,7 +24,11 @@ module.exports = {
if (reason.length > 150) {return message.reply("That status a bit long; keep it under 150 characters.");} if (reason.length > 150) {return message.reply("That status a bit long; keep it under 150 characters.");}
tu.statustype = 'dnd'; tu.statustype = 'dnd';
tu.statusmsg = reason.trim(); tu.statusmsg = reason.trim();
tu.statussetat = new Date();
let tempDate = new Date();
tu.statusclearat = tempDate.setHours(tempDate.getHours() + 12);
tu.save(); tu.save();
require('../util/cachestatus')(message.author.id, tempDate.setHours(tempDate.getHours() + 12));
return message.reply(`I set your ${tu.statusclearmode === 'auto' ? 'automatically' : 'manually'}-clearing Do not Disturb message to: ${reason.trim()}`); return message.reply(`I set your ${tu.statusclearmode === 'auto' ? 'automatically' : 'manually'}-clearing Do not Disturb message to: ${reason.trim()}`);
} }
}; };

@ -1,8 +1,10 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
const mongoose = require('mongoose');
const chalk = require('chalk'); const chalk = require('chalk');
const wait = require('../util/wait'); const wait = require('../util/wait');
const UserData = require('../models/user'); const UserData = require('../models/user');
const StatusCache = require('../models/statuses');
module.exports = async (client, message) => { module.exports = async (client, message) => {
if (message.author.bot) {return undefined;} if (message.author.bot) {return undefined;}
@ -36,6 +38,11 @@ module.exports = async (client, message) => {
tu.statusmsg = ''; tu.statusmsg = '';
tu.statustype = ''; tu.statustype = '';
tu.save(); 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.'); 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.');
} }

@ -2,7 +2,11 @@ const Discord = require('discord.js');
const chalk = require('chalk'); const chalk = require('chalk');
const moment = require('moment'); const moment = require('moment');
const mongoose = require('mongoose'); const mongoose = require('mongoose');
const GuildSettings = require('../models/guild'); const GuildSettings = require('../models/guild');
const BotDataSchema = require('../models/bot');
const siftStatuses = require('../util/siftstatuses');
var prefix = 'n?'; var prefix = 'n?';
@ -30,27 +34,36 @@ module.exports = async client => {
let responses = { let responses = {
"PLAYING": [ "PLAYING": [
`in ${client.guilds.cache.size} servers` `with my darling`, 'RAIN: Shadow Lords'
,`in ${client.guilds.cache.size} servers`
], ],
"WATCHING": [ "WATCHING": [
`for ${client.commands.size} commands` `for ${client.commands.size} commands`,
"I'm not a bad slime, slurp!", "Lelouch rule the world!",
"a slime somehow start an empire", "a fox-maid get her tail fluffed",
"a raccoon-girl and some guy with a shield", "some chick with unusually red hair",
"Mob hit 100", "a really bad harem anime", "The Black Swordsman",
"The Misfit of Demon King Academy"
,`over ${client.guilds.cache.size} servers` ,`over ${client.guilds.cache.size} servers`
] ]
}; };
const setR = () => { const setR = () => {
let type = Object.keys(responses)[Math.floor(Math.random() * Object.keys(responses).length)]; let type = Object.keys(responses)[Math.floor(Math.random() * Object.keys(responses).length)];
client.user.setActivity(responses[type][Math.floor(Math.random() * responses[type].length)] + " | " + prefix + "help", {type: type});}; if (type === "PLAYING") {client.user.setActivity(responses[type][Math.floor(Math.random() * responses[type].length)] + " | " + prefix + "help");}
else {client.user.setActivity(responses[type][Math.floor(Math.random() * responses[type].length)] + " | " + prefix + "help", {type: type});}
}
setR(); setR();
setInterval(setR, 14400000);
const BotDataSchema = require('../models/bot'); setInterval(setR, 14400000);
const setP = async () => {let tg; for (tg of Array.from(client.guilds.cache.values)) { const setP = async () => {let tg; for (tg of Array.from(client.guilds.cache.values)) {
let tguild = await GuildSettings.findOne({gid: tg.id}); let tguild = await GuildSettings.findOne({gid: tg.id});
if (tguild && tguild.prefix && tguild.prefix.length) {client.guildconfig.prefixes.set(tg.id, tguild.prefix);} if (tguild && tguild.prefix && tguild.prefix.length) {client.guildconfig.prefixes.set(tg.id, tguild.prefix);}
}}; }};
setP(); setP();
setInterval(setP, 120000); siftStatuses();
setInterval(() => {setP(); siftStatuses(client, null);}, 120000);
let botData = await BotDataSchema.findOne({finder: 'lel'}) let botData = await BotDataSchema.findOne({finder: 'lel'})
? await BotDataSchema.findOne({finder: 'lel'}) ? await BotDataSchema.findOne({finder: 'lel'})

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

21
package-lock.json generated

@ -3789,11 +3789,6 @@
"ip-address": "^5.8.8" "ip-address": "^5.8.8"
} }
}, },
"@lavaclient/types": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@lavaclient/types/-/types-1.0.2.tgz",
"integrity": "sha512-7OmlW8PD0mU4n4qD79YiT86mJDMmV0qoPLdXnepqv067gf9204p5tXRrs/cr+vGljqewELyUtUuQd74rRTZViw=="
},
"@nodelib/fs.scandir": { "@nodelib/fs.scandir": {
"version": "2.1.3", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz",
@ -7315,22 +7310,6 @@
"resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz", "resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz",
"integrity": "sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==" "integrity": "sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A=="
}, },
"lavaclient": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/lavaclient/-/lavaclient-3.1.2.tgz",
"integrity": "sha512-kfY6/3zkWyv3fc+G/Br8aEWrRBxwhgQy8xA3cJmIAxRGey8TC4kCM0gXKbAQDqcEErSAakRln18f+uwUkOExPA==",
"requires": {
"@lavaclient/types": "1.0.2",
"ws": "^7.3.1"
},
"dependencies": {
"ws": {
"version": "7.3.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz",
"integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA=="
}
}
},
"lavalink": { "lavalink": {
"version": "2.10.2", "version": "2.10.2",
"resolved": "https://registry.npmjs.org/lavalink/-/lavalink-2.10.2.tgz", "resolved": "https://registry.npmjs.org/lavalink/-/lavalink-2.10.2.tgz",

@ -14,7 +14,6 @@
"ffmpeg-static": "^4.2.7", "ffmpeg-static": "^4.2.7",
"gblapi.js": "^2.0.5", "gblapi.js": "^2.0.5",
"heroku": "^7.42.1", "heroku": "^7.42.1",
"lavaclient": "^3.1.2",
"lavaqueue": "^3.1.6", "lavaqueue": "^3.1.6",
"manyitems": "^1.0.2", "manyitems": "^1.0.2",
"moment": "^2.28.0", "moment": "^2.28.0",

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

@ -1,4 +1,6 @@
const mongooes= require('mongoose'); const Discord = require('discord.js');
const moment = require('moment');
const UserData = require('../models/user'); const UserData = require('../models/user');
const GuildSettings = require('../models/guild'); const GuildSettings = require('../models/guild');
@ -6,5 +8,10 @@ module.exports = async(message, msg, args, cmd, prefix, mention, client) => {
let tu = await UserData.findOne({uid: mention.id}); let tu = await UserData.findOne({uid: mention.id});
let tg = message.guild ? await GuildSettings.findOne({gid: message.guild.id}) : null; let tg = message.guild ? await GuildSettings.findOne({gid: message.guild.id}) : null;
if (tg && tg.nostatus) {return;} if (tg && tg.nostatus) {return;}
if (tu) {if (tu.statusmsg.length) {return message.reply(`That user ${tu.statustype === 'dnd' ? 'wishes not to be disturbed' : 'is AFK'}. Reason: ${tu.statusmsg}`);}} if (client.misc.statusPings.has(message.guild.id) && client.misc.statusPings.get(message.guild.id).has(mention.id) && new Date().getTime() - client.misc.statusPings.get(message.guild.id).get(mention.id).getTime() < 300000) {return;}
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()})`);
}
}; };

@ -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…
Cancel
Save