2024-06-15 17:46:43 +05:00
|
|
|
const Canvas = require("@napi-rs/canvas"),
|
2022-07-26 17:20:10 +05:00
|
|
|
BaseEvent = require("../../base/BaseEvent"),
|
2022-07-31 17:08:00 +05:00
|
|
|
{ AttachmentBuilder } = require("discord.js"),
|
2024-06-15 17:46:43 +05:00
|
|
|
{ applyText } = require("../../helpers/functions");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-07-23 17:14:42 +05:00
|
|
|
class GuildMemberAdd extends BaseEvent {
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
name: "guildMemberAdd",
|
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
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-07-23 17:14:42 +05:00
|
|
|
* @param {import("discord.js").GuildMember} member
|
|
|
|
*/
|
2022-08-02 17:18:47 +05:00
|
|
|
async execute(client, member) {
|
2023-07-03 19:30:47 +05:00
|
|
|
if (member.guild && member.guildId === "568120814776614924") return;
|
2022-02-13 16:50:44 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
await member.guild.members.fetch();
|
|
|
|
|
2024-05-24 23:11:03 +05:00
|
|
|
const guildData = await client.getGuildData(member.guild.id);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-01-31 20:09:32 +05:00
|
|
|
if (guildData.plugins.autorole.enabled) member.roles.add(guildData.plugins.autorole.role);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
if (guildData.plugins.welcome.enabled) {
|
|
|
|
const channel = member.guild.channels.cache.get(guildData.plugins.welcome.channel);
|
2023-06-26 17:25:17 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
if (channel) {
|
|
|
|
const message = guildData.plugins.welcome.message
|
|
|
|
.replace(/{user}/g, member)
|
|
|
|
.replace(/{server}/g, member.guild.name)
|
2022-08-08 18:19:56 +05:00
|
|
|
.replace(/{membercount}/g, member.guild.memberCount);
|
2023-06-26 17:25:17 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
if (guildData.plugins.welcome.withImage) {
|
|
|
|
const canvas = Canvas.createCanvas(1024, 450),
|
|
|
|
ctx = canvas.getContext("2d");
|
|
|
|
|
2022-01-11 02:18:39 +05:00
|
|
|
// Draw background
|
2022-01-04 02:18:28 +05:00
|
|
|
const background = await Canvas.loadImage("./assets/img/greetings_background.png");
|
|
|
|
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
|
|
|
|
|
2022-01-11 02:18:39 +05:00
|
|
|
// Draw layer
|
|
|
|
ctx.fillStyle = "#FFFFFF";
|
|
|
|
ctx.globalAlpha = "0.4";
|
|
|
|
ctx.fillRect(0, 0, 25, canvas.height);
|
|
|
|
ctx.fillRect(canvas.width - 25, 0, 25, canvas.height);
|
|
|
|
ctx.fillRect(25, 0, canvas.width - 50, 25);
|
|
|
|
ctx.fillRect(25, canvas.height - 25, canvas.width - 50, 25);
|
|
|
|
ctx.fillStyle = "#FFFFFF";
|
|
|
|
ctx.globalAlpha = "0.4";
|
|
|
|
ctx.fillRect(344, canvas.height - 296, 625, 65);
|
|
|
|
ctx.fillStyle = "#FFFFFF";
|
|
|
|
ctx.globalAlpha = "0.4";
|
|
|
|
ctx.fillRect(389, canvas.height - 225, 138, 65);
|
|
|
|
ctx.fillStyle = "#FFFFFF";
|
|
|
|
ctx.globalAlpha = "0.4";
|
|
|
|
ctx.fillRect(308, canvas.height - 110, 672, 65);
|
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
// Draw username
|
2022-01-11 02:18:39 +05:00
|
|
|
ctx.globalAlpha = 1;
|
|
|
|
ctx.fillStyle = "#FFFFFF";
|
|
|
|
ctx.font = applyText(canvas, member.user.username, 48, 600, "RubikMonoOne");
|
|
|
|
ctx.fillText(member.user.username, canvas.width - 670, canvas.height - 250);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
// Draw server name
|
2023-07-05 00:58:06 +05:00
|
|
|
ctx.font = applyText(
|
|
|
|
canvas,
|
|
|
|
client.translate("administration/welcome:IMG_WELCOME", {
|
|
|
|
server: member.guild.name,
|
|
|
|
}, guildData.language),
|
|
|
|
53,
|
|
|
|
625,
|
|
|
|
"RubikMonoOne",
|
|
|
|
);
|
|
|
|
|
|
|
|
ctx.fillText(
|
|
|
|
client.translate("administration/welcome:IMG_WELCOME", {
|
|
|
|
server: member.guild.name,
|
|
|
|
}, guildData.language),
|
|
|
|
canvas.width - 700,
|
|
|
|
canvas.height - 70,
|
|
|
|
);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
// Draw discriminator
|
|
|
|
ctx.font = "35px RubikMonoOne";
|
2023-06-07 23:59:38 +05:00
|
|
|
ctx.fillText(member.user.discriminator === "0" ? "" : member.user.discriminator, canvas.width - 623, canvas.height - 178);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-01-11 02:18:39 +05:00
|
|
|
// Draw membercount
|
2022-01-04 02:18:28 +05:00
|
|
|
ctx.font = "22px RubikMonoOne";
|
2023-06-27 21:19:55 +05:00
|
|
|
ctx.fillText(`${member.guild.memberCount}й ${client.translate("misc:NOUNS:MEMBERS:1", null, guildData.language)}`, 40, canvas.height - 35);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
// Draw # for discriminator
|
2022-01-11 02:18:39 +05:00
|
|
|
ctx.fillStyle = "#FFFFFF";
|
2022-01-04 02:18:28 +05:00
|
|
|
ctx.font = "70px RubikMonoOne";
|
2023-06-27 21:19:55 +05:00
|
|
|
ctx.fillText(member.user.discriminator === "0" ? "" : "#", canvas.width - 690, canvas.height - 165);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-01-11 02:18:39 +05:00
|
|
|
// Draw title
|
|
|
|
ctx.font = "45px RubikMonoOne";
|
|
|
|
ctx.strokeStyle = "#000000";
|
|
|
|
ctx.lineWidth = 10;
|
2023-06-27 21:19:55 +05:00
|
|
|
ctx.strokeText(client.translate("administration/welcome:TITLE", null, guildData.language), canvas.width - 670, canvas.height - 330);
|
2022-01-11 02:18:39 +05:00
|
|
|
ctx.fillStyle = "#FFFFFF";
|
2023-06-27 21:19:55 +05:00
|
|
|
ctx.fillText(client.translate("administration/welcome:TITLE", null, guildData.language), canvas.width - 670, canvas.height - 330);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-01-11 02:18:39 +05:00
|
|
|
// Draw avatar circle
|
2022-01-04 02:18:28 +05:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.lineWidth = 10;
|
2022-01-11 02:18:39 +05:00
|
|
|
ctx.strokeStyle = "#FFFFFF";
|
2022-01-04 02:18:28 +05:00
|
|
|
ctx.arc(180, 225, 135, 0, Math.PI * 2, true);
|
|
|
|
ctx.stroke();
|
|
|
|
ctx.closePath();
|
|
|
|
ctx.clip();
|
2023-06-26 17:25:17 +05:00
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
const avatar = await Canvas.loadImage(
|
|
|
|
member.displayAvatarURL({
|
|
|
|
extension: "jpg",
|
|
|
|
}),
|
|
|
|
);
|
2022-01-04 02:18:28 +05:00
|
|
|
ctx.drawImage(avatar, 45, 90, 270, 270);
|
|
|
|
|
2024-06-15 17:46:43 +05:00
|
|
|
const attachment = new AttachmentBuilder((await canvas.encode("png")), { name: "welcome.png" });
|
2023-06-26 17:25:17 +05:00
|
|
|
|
2022-01-11 02:18:39 +05:00
|
|
|
channel.send({
|
|
|
|
content: message,
|
2022-12-15 21:02:38 +05:00
|
|
|
files: [attachment],
|
2022-01-11 02:18:39 +05:00
|
|
|
});
|
2023-10-30 21:45:10 +05:00
|
|
|
} else
|
|
|
|
channel.send({ content: message });
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
}
|
2022-07-23 17:14:42 +05:00
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = GuildMemberAdd;
|