2023-04-30 16:57:02 +05:00
|
|
|
const { PermissionsBitField, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
|
2023-06-06 22:48:46 +05:00
|
|
|
const BaseEvent = require("../base/BaseEvent");
|
|
|
|
|
|
|
|
const xpCooldown = {};
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-07-23 17:14:42 +05:00
|
|
|
class MessageCreate extends BaseEvent {
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
name: "messageCreate",
|
2022-12-15 21:02:38 +05:00
|
|
|
once: false,
|
2022-07-23 17:14:42 +05:00
|
|
|
});
|
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 = {};
|
|
|
|
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({
|
2022-12-15 21:02:38 +05:00
|
|
|
id: message.guild.id,
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
2022-08-08 18:19:56 +05:00
|
|
|
message.guild.data = data.guildData = guild;
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-11-25 01:25:58 +05:00
|
|
|
if (message.content.match(new RegExp(`^<@!?${client.user.id}>( |)$`))) return message.replyT("misc:HELLO_SERVER", null, { mention: true });
|
2022-01-04 02:18:28 +05:00
|
|
|
if (message.guild) {
|
|
|
|
const memberData = await client.findOrCreateMember({
|
|
|
|
id: message.author.id,
|
2022-12-15 21:02:38 +05:00
|
|
|
guildId: message.guild.id,
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
|
|
|
data.memberData = memberData;
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
const userData = await client.findOrCreateUser({
|
2022-12-15 21:02:38 +05:00
|
|
|
id: message.author.id,
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
|
|
|
data.userData = userData;
|
|
|
|
|
|
|
|
if (message.guild) {
|
|
|
|
await updateXp(client, message, data);
|
|
|
|
|
2023-04-30 16:57:02 +05:00
|
|
|
if (message.content.includes("discord.com/channels/")) {
|
2023-06-08 12:53:31 +05:00
|
|
|
const link = message.content.match(/(https|http):\/\/(ptb\.|canary\.)?(discord.com)\/(channels)\/\d+\/\d+\/\d+/g)[0],
|
2023-06-08 12:31:06 +05:00
|
|
|
ids = link.match(/\d+/g),
|
|
|
|
channelId = ids[1],
|
2023-04-30 16:57:02 +05:00
|
|
|
messageId = ids[2];
|
|
|
|
|
|
|
|
const msg = await client.channels.cache.get(channelId).messages.fetch(messageId);
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setAuthor({
|
|
|
|
name: message.translate("misc:QUOTE_TITLE", {
|
2023-06-07 23:59:38 +05:00
|
|
|
user: msg.author.discriminator === "0" ? msg.author.username : msg.author.tag,
|
2023-04-30 16:57:02 +05:00
|
|
|
}),
|
|
|
|
iconURL: "https://wynem.com/assets/images/icons/quote.webp",
|
|
|
|
})
|
2023-06-22 17:36:58 +05:00
|
|
|
.setThumbnail(msg.author.displayAvatarURL())
|
2023-04-30 16:57:02 +05:00
|
|
|
.setDescription(msg.content !== "" ? msg.content : `*${message.translate("common:MISSING")}*`)
|
|
|
|
.addFields([
|
|
|
|
{
|
|
|
|
name: message.translate("misc:QUOTE_ATTACHED"),
|
|
|
|
value: msg.attachments.size > 0 ? msg.attachments.map(a => {
|
|
|
|
return `[${a.name}](${a.url})`;
|
|
|
|
}).join("\n") : `*${message.translate("common:MISSING")}*`,
|
|
|
|
},
|
|
|
|
])
|
|
|
|
.setFooter({
|
2023-06-07 23:59:38 +05:00
|
|
|
text: message.translate("misc:QUOTE_FOOTER", { user: message.author.discriminator === "0" ? message.author.username : message.author.tag }),
|
2023-04-30 16:57:02 +05:00
|
|
|
})
|
|
|
|
.setColor(client.config.embed.color)
|
|
|
|
.setTimestamp(msg.createdTimestamp);
|
|
|
|
|
|
|
|
const row = new ActionRowBuilder()
|
|
|
|
.addComponents(
|
|
|
|
new ButtonBuilder()
|
|
|
|
.setLabel(message.translate("misc:QUOTE_JUMP"))
|
|
|
|
.setStyle(ButtonStyle.Link)
|
|
|
|
.setURL(msg.url),
|
|
|
|
new ButtonBuilder()
|
|
|
|
.setCustomId("quote_delete")
|
|
|
|
.setEmoji("1102200816582000750")
|
|
|
|
.setStyle(ButtonStyle.Danger),
|
|
|
|
);
|
|
|
|
|
|
|
|
const reply = await message.reply({
|
|
|
|
embeds: [embed],
|
|
|
|
components: [row],
|
|
|
|
});
|
|
|
|
|
|
|
|
const filter = i => i.user.id === message.author.id;
|
|
|
|
const collector = message.channel.createMessageComponentCollector({ filter, time: (60 * 1000) });
|
|
|
|
|
|
|
|
collector.on("collect", async i => {
|
|
|
|
if (i.isButton() && i.customId === "quote_delete")
|
|
|
|
if (reply.deletable) await reply.delete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-15 21:02:38 +05:00
|
|
|
if (data.guildData.plugins.automod.enabled && !data.guildData.plugins.automod.ignored.includes(message.channel.id))
|
|
|
|
if (/(discord\.(gg|io|me|li)\/.+|discordapp\.com\/invite\/.+)/i.test(message.content))
|
2022-07-31 17:08:00 +05:00
|
|
|
if (!message.channel.permissionsFor(message.member).has(PermissionsBitField.Flags.ManageMessages)) {
|
2023-03-26 18:31:19 +05:00
|
|
|
message.error("administration/automod:DELETED");
|
2023-06-17 00:44:47 +05:00
|
|
|
message.delete();
|
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-08-04 19:26:17 +05:00
|
|
|
message.replyT("general/afk:DELETED", {
|
2023-03-26 18:31:19 +05:00
|
|
|
user: message.author.username,
|
2022-10-09 14:26:22 +05:00
|
|
|
}, { mention: true });
|
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({
|
2022-12-15 21:02:38 +05:00
|
|
|
id: u.id,
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
2023-06-07 23:59:38 +05:00
|
|
|
if (userData.afk) message.replyT("general/afk:IS_AFK", { user: u.discriminator === "0" ? u.username : u.tag, reason: userData.afk }, { ephemeral: true });
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2023-03-26 18:31:19 +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
|
|
|
|
2022-10-03 20:21:42 +05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
* @param {import("discord.js").Message} msg
|
|
|
|
* @param {*} data
|
|
|
|
* @returns
|
|
|
|
*/
|
2022-01-04 02:18:28 +05:00
|
|
|
async function updateXp(client, msg, data) {
|
2022-10-03 20:21:42 +05:00
|
|
|
const points = parseInt(data.memberData.exp),
|
|
|
|
level = parseInt(data.memberData.level),
|
|
|
|
isInCooldown = xpCooldown[msg.author.id];
|
|
|
|
|
2022-12-15 21:02:38 +05:00
|
|
|
if (isInCooldown)
|
2022-01-04 02:18:28 +05:00
|
|
|
if (isInCooldown > Date.now()) return;
|
|
|
|
|
2022-10-03 20:21:42 +05:00
|
|
|
const toWait = Date.now() + (60 * 1000); // 1 min
|
2022-01-04 02:18:28 +05:00
|
|
|
xpCooldown[msg.author.id] = toWait;
|
|
|
|
|
2022-10-03 20:21:42 +05:00
|
|
|
const won = client.functions.randomNum(1, 2);
|
2022-01-04 02:18:28 +05:00
|
|
|
const newXp = parseInt(points + won, 10);
|
|
|
|
const neededXp = 5 * (level * level) + 80 * level + 100;
|
|
|
|
|
2022-10-03 20:21:42 +05:00
|
|
|
if (newXp > neededXp) {
|
|
|
|
data.memberData.level = parseInt(level + 1, 10);
|
|
|
|
data.memberData.exp = 0;
|
|
|
|
msg.replyT("misc:LEVEL_UP", {
|
2022-12-15 21:02:38 +05:00
|
|
|
level: data.memberData.level,
|
2022-10-03 20:21:42 +05:00
|
|
|
}, { mention: false });
|
|
|
|
} else data.memberData.exp = parseInt(newXp, 10);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
await data.memberData.save();
|
2022-07-23 17:14:42 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MessageCreate;
|