woomy/src/events/message.js

241 lines
8.6 KiB
JavaScript
Raw Normal View History

2020-03-26 04:57:53 +00:00
const cooldown = new Set();
2020-01-25 10:02:43 +00:00
module.exports = async (client, message) => {
if (message.author.bot) return;
if (typeof(message.content) === 'string') message.content = message.content.replace(/\u8203/g,'').replace(/\uB200/g,'').replace("\\uB200",''); // Remove zero-width characters
2020-01-25 10:02:43 +00:00
var settings;
if(message.guild) {
settings = message.settings = client.getSettings(message.guild.id) || client.defaultSettings;
} else {
settings= client.config.defaultSettings;
}
var prefix = settings.prefix;
if(client.devmode == true) {
prefix = settings.devprefix;
}
2020-01-25 10:45:12 +00:00
let blacklisted = false;
2020-01-25 10:02:43 +00:00
if(message.guild) {
perms = message.channel.permissionsFor(client.user);
2020-03-09 01:11:33 +00:00
var modRole = message.guild.roles.cache.get(settings.modRole);
var adminRole = message.guild.roles.cache.get(settings.adminRole);
var autorole = message.guild.roles.cache.get(settings.autorole);
var mutedRole = message.guild.roles.cache.get(settings.mutedRole);
var welcomeChannel = message.guild.channels.cache.get(settings.welcomeChannel);
2020-01-25 10:02:43 +00:00
if(!welcomeChannel && settings.welcomeChannel != "off" || !adminRole && settings.adminRole != "None set" || !modRole && settings.modRole != "None set" || !mutedRole && settings.mutedRole != "None set" || !autorole && settings.autorole != "off") {
var adminReset = false;
var modReset = false;
var mutedReset = false;
var autoReset = false;
var welcomeReset = false;
if(!adminRole && settings.adminRole != "None set") {
2020-03-09 01:11:33 +00:00
var role = message.guild.roles.cache.find(r => r.name === settings.adminRole);
2020-01-25 10:02:43 +00:00
if(!role) {
adminReset = true;
client.settings.set(message.guild.id, client.config.defaultSettings.adminRole, "adminRole");
} else {
client.settings.set(message.guild.id, role.id, "adminRole");
};
};
if(!mutedRole && settings.mutedRole != "None set") {
2020-03-09 01:11:33 +00:00
var role = message.guild.roles.cache.find(r => r.name === settings.mutedRole);
2020-01-25 10:02:43 +00:00
if(!role) {
mutedReset = true;
client.settings.set(message.guild.id, client.config.defaultSettings.mutedRole, "mutedRole");
} else {
client.settings.set(message.guild.id, role.id, "mutedRole");
};
};
if(!modRole && settings.modRole != "None set") {
2020-03-09 01:11:33 +00:00
var role = message.guild.roles.cache.find(r => r.name === settings.modRole);
2020-01-25 10:02:43 +00:00
if(!role) {
modReset = true;
client.settings.set(message.guild.id, client.config.defaultSettings.modRole, "modRole");
} else {
client.settings.set(message.guild.id, role.id, "modRole");
};
};
if(!autorole && settings.autorole != "off") {
2020-03-09 01:11:33 +00:00
var role = message.guild.roles.cache.find(r => r.name === settings.autorole);
2020-01-25 10:02:43 +00:00
if(!role) {
autoReset = true;
client.settings.set(message.guild.id, client.config.defaultSettings.autorole, "autorole");
} else {
client.settings.set(message.guild.id, role.id, "autorole");
};
};
if(!welcomeChannel && settings.welcomeChannel != "off") {
2020-03-09 01:11:33 +00:00
var channel = message.guild.channels.cache.find(c => c.name === settings.welcomeChannel);
2020-01-25 10:02:43 +00:00
if(!channel) {
welcomeReset = true;
client.settings.set(message.guild.id, client.config.defaultSettings.welcomeChannel, "welcomeChannel");
} else {
client.settings.set(message.guild.id, channel.id, "welcomeChannel");
};
};
var errors = "";
if(adminReset == true) {
adminReset = false;
errors += ", `admin role`";
};
if(modReset == true) {
modReset = false;
errors += ", `mod role`";
};
if(mutedReset == true) {
mutedReset = false;
errors += ", `muted role`";
};
if(autoReset == true) {
autoReset = false;
errors += ", `autorole`";
};
if(welcomeReset == true) {
welcomeReset = false;;
errors += ", `join/leave channel`";
};
if(errors.length > 1) {
var errors = errors.substr(2);
message.channel.send(`<:error:466995152976871434> A role or channel was deleted, and the following settings have been restored to their default values: ${errors}`);
};
};
if (!message.member) {
2020-03-09 01:11:33 +00:00
await message.guild.members.fetch(message.author);
2020-01-25 10:02:43 +00:00
};
if(message.settings.blacklisted != "ARRAY" && settings.blacklisted.length > 0) {
settings.blacklisted.forEach(function(ID) {
if(ID == message.author.id) {
blacklisted = true;
}
});
};
};
2020-03-19 10:20:18 +00:00
//const prefixMention = new RegExp(`^<@!?${client.user.id}>( |)$`);
const myMention = `<@&${client.user.id}>`;
const myMention2 = `<@!${client.user.id}>`;
2020-03-19 10:20:45 +00:00
2020-03-19 10:20:18 +00:00
if (message.content.startsWith(myMention) || message.content.startsWith(myMention2)) {
if(message.content.length > myMention.length + 1 && (message.content.substr(0, myMention.length + 1) == myMention + ' ' || message.content.substr(0, myMention2.length + 1) == myMention2 + ' ')) {
prefix = message.content.substr(0, myMention.length) + ' ';
} else {
return message.channel.send(`Current prefix: \`${prefix}\``);
};
};
2020-03-19 10:20:45 +00:00
2020-01-25 10:02:43 +00:00
if (message.content.indexOf(prefix) !== 0) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const cmd = client.commands.get(command) || client.commands.get(client.aliases.get(command));
if (!cmd) return;
2020-03-09 01:11:33 +00:00
2020-03-26 04:57:53 +00:00
if (cooldown.has(message.author.id)) {
return message.channel.send(
2020-03-26 05:01:27 +00:00
`⏱️ You are being ratelimited. Please try again in 2 seconds.`
).then(msg => {
msg.delete({timeout: 2000});
});
};
2020-01-25 10:02:43 +00:00
2020-03-22 13:01:54 +00:00
if (message.guild && !perms.has('SEND_MESSAGES')) {
2020-01-25 10:21:30 +00:00
return message.author.send(`<:error:466995152976871434> I don't have permission to speak in **#${message.channel.name}**, Please ask a moderator to give me the send messages permission!`);
};
if (!cmd.conf.enabled) {
return message.channel.send('<:error:466995152976871434> This command has been disabled by my developers.')
}
2020-01-25 10:21:30 +00:00
if(message.guild && blacklisted == true) {
try {
return message.author.send(
2020-08-16 08:19:28 +00:00
`<:denied:466995195150336020> You have been blocked from using commands in \`${message.guild.name}\``
2020-01-25 10:21:30 +00:00
);
} catch(err) {
client.logger.log(err, "error")
};
};
2020-01-25 10:02:43 +00:00
if (cmd && !message.guild && cmd.conf.guildOnly)
return message.channel.send("<:denied:466995195150336020> This command is unavailable in DM's. Try running it in a server I'm in!");
if (message.guild) {
var missing = cmd.conf.requiredPerms.filter(p => !perms.has(p))
if(missing.length > 0) {
missing = "`" + (missing.join("`, `")) + "`";
return message.channel.send(`<:error:466995152976871434> Missing permissions: ${missing}`)
};
};
const level = client.permlevel(message);
if(cmd.conf.permLevel == "Developer") {
var isDeveloper;
if(message.client.config.owners.includes(message.author.id)) {
isDeveloper = true;
}
if(isDeveloper != true) {
return message.channel.send("<:denied:466995195150336020> This command can only be used by my developers!")
}
}
if (level < client.levelCache[cmd.conf.permLevel]) {
var usrlvl = client.levelCache[cmd.conf.permLevel];
if (usrlvl === 1) var displevel = "Moderator";
if (usrlvl === 2) var displevel = "Administrator";
if (usrlvl === 3) var displevel = "Server Owner";
if (!modRole && usrlvl < 2 && cmd.conf.permLevel == "Moderator" && message.guild) {
return message.channel.send("<:error:466995152976871434> No moderator role set! Please ask the server owner to set one with `" + message.settings.prefix + "modrole <role>`")
}
if (!adminRole && usrlvl < 3 && cmd.conf.permLevel == "Administrator" && message.guild) {
return message.channel.send("<:error:466995152976871434> No administrator role set! Please ask the server owner to set one with `" + message.settings.prefix + "adminrole <role>`")
}
var englesh = "a";
if (displevel === "Administrator") englesh = "an";
if (displevel === "Server Owner") englesh = "the";
return message.channel.send(`<:denied:466995195150336020> You need to be ${englesh} ${displevel} to run this command!`);
}
message.author.permLevel = level;
message.flags = [];
while (args[0] && args[0][0] === "-") {
message.flags.push(args.shift().slice(1));
};
2020-03-26 04:57:53 +00:00
cooldown.add(message.author.id);
2020-01-25 10:02:43 +00:00
setTimeout(() => {
2020-03-26 04:57:53 +00:00
cooldown.delete(message.author.id);
}, 2000);
2020-01-25 10:02:43 +00:00
client.logger.cmd(`${client.config.permLevels.find(l => l.level === level).name} ran command ${cmd.help.name}`);
2020-01-25 10:02:43 +00:00
cmd.run(client, message, args, level);
2020-03-24 05:47:26 +00:00
};