From 0bd89058296b43433fd031c6500a4c62680cb7b4 Mon Sep 17 00:00:00 2001 From: TheEssem Date: Wed, 9 Sep 2020 20:14:01 -0500 Subject: [PATCH] Don't read database on every message (why the hell did i think this was even remotely good design) --- events/messageCreate.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/events/messageCreate.js b/events/messageCreate.js index 09945f5..f6518b5 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -12,9 +12,20 @@ module.exports = async (message) => { // don't run command if bot can't send messages if (message.channel.guild && (!message.channel.guild.members.get(client.user.id).permission.has("sendMessages") || !message.channel.permissionsOf(client.user.id).has("sendMessages"))) return; + // this is here to prevent reading the database if a message is unrelated + let valid = false; + for (const key of collections.aliases.keys()) { + const commandRegex = new RegExp(key, "i"); + if (commandRegex.test(message.content)) { + valid = true; + break; + } + } + if (!valid) return; + // prefix can be a mention or a set of special characters const guildDB = message.channel.guild ? await database.guilds.findOne({ id: message.channel.guild.id }).lean().exec() : null; - const prefixMention = new RegExp(`^<@!?${client.user.id}> `); + const prefixMention = new RegExp(`^${client.user.mention} `); const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : (message.channel.guild ? guildDB.prefix : ""); // ignore other stuff