AR caching and functionality

master
Kit Kasune 4 years ago
parent b32e49d878
commit 90e1b21815
  1. 5
      bot.js
  2. 1
      commands/ar.js
  3. 8
      events/message.js
  4. 15
      events/ready.js
  5. 31
      package-lock.json
  6. 9
      util/cache/ar.js

@ -10,7 +10,10 @@ client.misc = {
activeDMs: new Discord.Collection(), activeDMs: new Discord.Collection(),
statusPings: new Discord.Collection(), statusPings: new Discord.Collection(),
startup: new Date(), startup: new Date(),
startupNoConnect: null startupNoConnect: null,
cache: {
ar: new Map()
}
}; };
//const config = require('./config.js'); //const config = require('./config.js');

@ -43,6 +43,7 @@ module.exports = {
if (tar.triggers.length === 20) {return message.channel.send("Because of data storage concerns, your ARs are capped at 20 per server. You can join the official support server and talk to the devs if you have a legitimate reason for raising this limit and they can see about raising it for you!");} if (tar.triggers.length === 20) {return message.channel.send("Because of data storage concerns, your ARs are capped at 20 per server. You can join the official support server and talk to the devs if you have a legitimate reason for raising this limit and they can see about raising it for you!");}
let h = false; let ar; for (ar of tar.triggers) {if (ar.toLowerCase() === `${trigger}`.toLowerCase()) {h = true;}} let h = false; let ar; for (ar of tar.triggers) {if (ar.toLowerCase() === `${trigger}`.toLowerCase()) {h = true;}}
if (!h) {tar.triggers.push(trigger);} if (!h) {tar.triggers.push(trigger);}
client.misc.cache.ar.set(message.guild.id, tar.triggers);
tar.ars[`${trigger}`.trim().toLowerCase()] = `${response}`.trim(); tar.ars[`${trigger}`.trim().toLowerCase()] = `${response}`.trim();
tar.markModified('tar.ars'); tar.markModified('tar.ars');
tar.save(); tar.save();

@ -4,7 +4,7 @@ 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'); const AR = require('../models/ar');
module.exports = async (client, message) => { module.exports = async (client, message) => {
if (message.author.bot) {return undefined;} if (message.author.bot) {return undefined;}
@ -42,6 +42,12 @@ module.exports = async (client, message) => {
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});}); 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});});
}}); }});
if (client.misc.cache.ar.has(message.guild.id) && client.misc.cache.ar.get(message.guild.id).includes(msg.trim())) {
AR.findOne({gid: message.guild.id}).then(ar => {
if (ar && ar.triggers.length && ar.triggers.includes(msg.trim()) && Object.keys(ar.ars).includes(msg.trim())) {return message.channel.send(ar.ars[msg.trim()]);}
});
}
try { try {
if (msg.startsWith(prefix) || msg.startsWith(`<@${client.user.id}>`) || msg.startsWith(`<@!${client.user.id}>`)) { if (msg.startsWith(prefix) || msg.startsWith(`<@${client.user.id}>`) || msg.startsWith(`<@!${client.user.id}>`)) {
let command = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd)); let command = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd));

@ -2,6 +2,7 @@ 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 ora = require('ora');
const GuildSettings = require('../models/guild'); const GuildSettings = require('../models/guild');
const BotDataSchema = require('../models/bot'); const BotDataSchema = require('../models/bot');
@ -27,7 +28,11 @@ module.exports = async client => {
let responses = { let responses = {
"PLAYING": [ "PLAYING": [
`with my darling`, 'RAIN: Shadow Lords' `with my darling`, 'RAIN: Shadow Lords', "with my waifu", "with the neko formula",
"with magic", "terrible anime games", "anime OSTs at max volume",
`${Math.ceil(Math.random() * 100)} days of trying to become a samurai`,
"with the sauce", "witch hats are >", "explosion magic is the best magic",
"with Kazuma's sanity"
,`in ${client.guilds.cache.size} servers` ,`in ${client.guilds.cache.size} servers`
], ],
"WATCHING": [ "WATCHING": [
@ -36,7 +41,7 @@ module.exports = async client => {
"a slime somehow start an empire", "a fox-maid get her tail fluffed", "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", "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", "Mob hit 100", "a really bad harem anime", "The Black Swordsman",
"The Misfit of Demon King Academy" "The Misfit of Demon King Academy", "Akame ga Kill"
,`over ${client.guilds.cache.size} servers` ,`over ${client.guilds.cache.size} servers`
] ]
}; };
@ -66,6 +71,12 @@ module.exports = async client => {
setInterval(() => {setPL(); siftStatuses(client, null);}, 120000); setInterval(() => {setPL(); siftStatuses(client, null);}, 120000);
console.log('');
let ora_arCache = ora("Caching ARs...").start();
await require('../util/cache/ar')(client);
ora_arCache.stop(); ora_arCache.clear();
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.ar.size}`)} ${chalk.blueBright(`guilds with auto responses.`)}`);
let botData = await BotDataSchema.findOne({finder: 'lel'}) let botData = await BotDataSchema.findOne({finder: 'lel'})
? await BotDataSchema.findOne({finder: 'lel'}) ? await BotDataSchema.findOne({finder: 'lel'})
: new BotDataSchema({ : new BotDataSchema({

31
package-lock.json generated

@ -1388,9 +1388,11 @@
"integrity": "sha512-2N7AmszH/WPPpl5Z3XMw1HAP+8d+xugnKQAeKvxFZ/04dbT/CAznqwbl+7eSr3HkwdepNwtb2yx3CAMQWvG01Q==", "integrity": "sha512-2N7AmszH/WPPpl5Z3XMw1HAP+8d+xugnKQAeKvxFZ/04dbT/CAznqwbl+7eSr3HkwdepNwtb2yx3CAMQWvG01Q==",
"requires": { "requires": {
"clone-response": "^1.0.2", "clone-response": "^1.0.2",
"get-stream": "^4.0.0",
"http-cache-semantics": "^4.0.0", "http-cache-semantics": "^4.0.0",
"keyv": "^3.0.0", "keyv": "^3.0.0",
"lowercase-keys": "^1.0.1", "lowercase-keys": "^1.0.1",
"normalize-url": "^3.1.0",
"responselike": "^1.0.2" "responselike": "^1.0.2"
} }
}, },
@ -1438,6 +1440,14 @@
"ms": "2.1.2" "ms": "2.1.2"
} }
}, },
"decompress-response": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
"integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=",
"requires": {
"mimic-response": "^1.0.0"
}
},
"doctrine": { "doctrine": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz",
@ -1559,6 +1569,14 @@
"write": "1.0.3" "write": "1.0.3"
} }
}, },
"get-stream": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz",
"integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==",
"requires": {
"pump": "^3.0.0"
}
},
"globals": { "globals": {
"version": "12.3.0", "version": "12.3.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-12.3.0.tgz", "resolved": "https://registry.npmjs.org/globals/-/globals-12.3.0.tgz",
@ -1572,8 +1590,11 @@
"@sindresorhus/is": "^0.14.0", "@sindresorhus/is": "^0.14.0",
"@szmarczak/http-timer": "^1.1.2", "@szmarczak/http-timer": "^1.1.2",
"cacheable-request": "^6.0.0", "cacheable-request": "^6.0.0",
"decompress-response": "^3.3.0",
"duplexer3": "^0.1.4", "duplexer3": "^0.1.4",
"get-stream": "^4.1.0",
"lowercase-keys": "^1.0.1", "lowercase-keys": "^1.0.1",
"mimic-response": "^1.0.1",
"p-cancelable": "^1.0.0", "p-cancelable": "^1.0.0",
"to-readable-stream": "^1.0.0", "to-readable-stream": "^1.0.0",
"url-parse-lax": "^3.0.0" "url-parse-lax": "^3.0.0"
@ -1701,6 +1722,11 @@
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz",
"integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==" "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ=="
}, },
"mimic-response": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ=="
},
"mute-stream": { "mute-stream": {
"version": "0.0.8", "version": "0.0.8",
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
@ -1727,6 +1753,11 @@
} }
} }
}, },
"normalize-url": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-3.3.0.tgz",
"integrity": "sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg=="
},
"onetime": { "onetime": {
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz",

9
util/cache/ar.js vendored

@ -0,0 +1,9 @@
const AR = require('../../models/ar');
module.exports = async client => {
client.misc.cache.ar = new Map();
for await (const ar of AR.find()) {
client.misc.cache.ar.set(ar.gid, ar.triggers);
}
};
Loading…
Cancel
Save