2022-01-05 00:24:57 +05:00
|
|
|
const { Permissions } = require("discord.js"),
|
|
|
|
xpCooldown = {},
|
2022-07-23 17:14:42 +05:00
|
|
|
BaseEvent = require("../base/BaseEvent");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-07-23 17:14:42 +05:00
|
|
|
class MessageCreate extends BaseEvent {
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
name: "messageCreate",
|
|
|
|
once: false
|
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
}
|
|
|
|
|
2022-07-23 17:14:42 +05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
* @param {import("discord.js").Message} message
|
|
|
|
*/
|
|
|
|
async execute(client, message) {
|
2022-02-15 01:26:29 +05:00
|
|
|
if (message.guild && message.guild.id === "568120814776614924") return;
|
2022-07-03 21:47:48 +05:00
|
|
|
if (message.content.includes("no bitches")) message.reply({ files: [{ name: "b.png", attachment: "./assets/img/b.png" }] });
|
2022-07-03 21:53:05 +05:00
|
|
|
if (message.content.includes("bitches") && !message.content.includes("no bitches")) message.reply({ files: [{ name: "nob.png", attachment: "./assets/img/nob.png" }] });
|
2022-02-13 16:50:44 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
const data = {};
|
2022-07-23 17:14:42 +05:00
|
|
|
data.config = client.config;
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
if (message.author.bot) return;
|
|
|
|
|
|
|
|
if (message.guild && !message.member) await message.guild.members.fetch(message.author.id);
|
|
|
|
|
|
|
|
if (message.guild) {
|
|
|
|
const guild = await client.findOrCreateGuild({
|
|
|
|
id: message.guild.id
|
|
|
|
});
|
|
|
|
message.guild.data = data.guild = guild;
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-07-26 17:20:10 +05:00
|
|
|
if (message.content.match(new RegExp(`^<@!?${client.user.id}>( |)$`))) return message.replyT("misc:HELLO_SERVER", { username: message.author.username });
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
if (message.guild) {
|
|
|
|
const memberData = await client.findOrCreateMember({
|
|
|
|
id: message.author.id,
|
|
|
|
guildID: message.guild.id
|
|
|
|
});
|
|
|
|
data.memberData = memberData;
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
const userData = await client.findOrCreateUser({
|
|
|
|
id: message.author.id
|
|
|
|
});
|
|
|
|
data.userData = userData;
|
|
|
|
|
|
|
|
if (message.guild) {
|
|
|
|
await updateXp(client, message, data);
|
|
|
|
|
|
|
|
if (data.guild.plugins.automod.enabled && !data.guild.plugins.automod.ignored.includes(message.channel.id)) {
|
|
|
|
if (/(discord\.(gg|io|me|li)\/.+|discordapp\.com\/invite\/.+)/i.test(message.content)) {
|
2022-01-05 00:24:57 +05:00
|
|
|
if (!message.channel.permissionsFor(message.member).has(Permissions.FLAGS.MANAGE_MESSAGES)) {
|
2022-01-04 02:18:28 +05:00
|
|
|
message.delete();
|
|
|
|
message.author.send("```" + message.content + "```");
|
|
|
|
return message.error("administration/automod:DELETED", {
|
|
|
|
username: message.author.tag
|
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
const afkReason = data.userData.afk;
|
|
|
|
if (afkReason) {
|
|
|
|
data.userData.afk = null;
|
|
|
|
await data.userData.save();
|
2022-07-26 17:20:10 +05:00
|
|
|
message.replyT("general/setafk:DELETED", {
|
2022-01-04 02:18:28 +05:00
|
|
|
username: message.author.username
|
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
message.mentions.users.forEach(async (u) => {
|
|
|
|
const userData = await client.findOrCreateUser({
|
|
|
|
id: u.id
|
|
|
|
});
|
2022-01-06 15:29:31 +05:00
|
|
|
if (userData.afk) message.error("general/setafk:IS_AFK", { user: u.tag, reason: userData.afk });
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-07-23 17:14:42 +05:00
|
|
|
return;
|
2022-01-04 02:18:28 +05:00
|
|
|
}
|
2022-07-23 17:14:42 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
async function updateXp(client, msg, data) {
|
|
|
|
const points = parseInt(data.memberData.exp);
|
|
|
|
const level = parseInt(data.memberData.level);
|
|
|
|
const isInCooldown = xpCooldown[msg.author.id];
|
|
|
|
if (isInCooldown) {
|
|
|
|
if (isInCooldown > Date.now()) return;
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-03-01 22:53:05 +05:00
|
|
|
const toWait = Date.now() + 60000; // 1 min
|
2022-01-04 02:18:28 +05:00
|
|
|
xpCooldown[msg.author.id] = toWait;
|
|
|
|
|
2022-03-27 13:39:14 +05:00
|
|
|
const won = client.functions.randomNum(1, 4);
|
2022-01-04 02:18:28 +05:00
|
|
|
const newXp = parseInt(points + won, 10);
|
|
|
|
const neededXp = 5 * (level * level) + 80 * level + 100;
|
|
|
|
|
|
|
|
if (newXp > neededXp) data.memberData.level = parseInt(level + 1, 10);
|
|
|
|
|
|
|
|
data.memberData.exp = parseInt(newXp, 10);
|
|
|
|
await data.memberData.save();
|
2022-07-23 17:14:42 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MessageCreate;
|