Preliminary DM support, update URLs to point to new repo link

This commit is contained in:
TheEssem 2020-09-01 17:10:19 -05:00
parent 631cdc5ef6
commit c471bd8af8
27 changed files with 105 additions and 66 deletions

View file

@ -8,15 +8,14 @@ const collections = require("../utils/collections.js");
module.exports = async (message) => {
// ignore dms and other bots
if (message.author.bot) return;
if (!message.channel.guild) return;
// don't run command if bot can't send messages
if (!message.channel.guild.members.get(client.user.id).permission.has("sendMessages") || !message.channel.permissionsOf(client.user.id).has("sendMessages")) return;
if (message.channel.guild && (!message.channel.guild.members.get(client.user.id).permission.has("sendMessages") || !message.channel.permissionsOf(client.user.id).has("sendMessages"))) return;
// prefix can be a mention or a set of special characters
const guildDB = await database.guilds.findOne({ id: message.channel.guild.id }).lean().exec();
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 prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : guildDB.prefix;
const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : (message.channel.guild ? guildDB.prefix : "");
// ignore other stuff
if (message.content.startsWith(prefix) === false) return;
@ -27,7 +26,7 @@ module.exports = async (message) => {
const command = args.shift().toLowerCase();
// don't run if message is in a disabled channel
if (guildDB.disabledChannels && guildDB.disabledChannels.includes(message.channel.id) && command != "channel") return;
if (guildDB && guildDB.disabledChannels && guildDB.disabledChannels.includes(message.channel.id) && command != "channel") return;
// check if command exists
const cmd = collections.commands.get(command) || collections.commands.get(collections.aliases.get(command));
@ -68,7 +67,7 @@ module.exports = async (message) => {
await client.createMessage(message.channel.id, `${message.author.mention}, the request timed out before I could download that image. Try uploading your image somewhere else.`);
} else {
logger.error(error.toString());
await client.createMessage(message.channel.id, "Uh oh! I ran into an error while running this command. Please report the content of the attached file here or on the esmBot Support server: <https://github.com/TheEssem/esmBot/issues>", [{
await client.createMessage(message.channel.id, "Uh oh! I ran into an error while running this command. Please report the content of the attached file here or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>", [{
file: Buffer.from(`Message: ${error}\n\nStack Trace: ${error.stack}`),
name: "error.txt"
}]);