2022-01-04 02:18:28 +05:00
|
|
|
const Canvas = require("canvas"),
|
|
|
|
Discord = require("discord.js"),
|
|
|
|
{ resolve } = require("path");
|
|
|
|
|
|
|
|
// Register assets fonts
|
|
|
|
Canvas.registerFont(resolve("./assets/fonts/RubikMonoOne-Regular.ttf"), { family: "RubikMonoOne" });
|
|
|
|
Canvas.registerFont(resolve("./assets/fonts/KeepCalm-Medium.ttf"), { family: "KeepCalm" });
|
|
|
|
|
2022-01-11 02:18:39 +05:00
|
|
|
const applyText = (canvas, text, defaultFontSize, width, font) => {
|
2022-01-04 02:18:28 +05:00
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
do {
|
2022-01-11 02:18:39 +05:00
|
|
|
ctx.font = `${(defaultFontSize -= 1)}px ${font}`;
|
|
|
|
} while (ctx.measureText(text).width > width);
|
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
return ctx.font;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = class {
|
|
|
|
constructor(client) {
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
|
|
|
|
async run(member) {
|
2022-01-31 20:25:57 +05:00
|
|
|
if (member.guild.id === "568120814776614924") return;
|
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
await member.guild.members.fetch();
|
|
|
|
|
|
|
|
const guildData = await this.client.findOrCreateGuild({
|
|
|
|
id: member.guild.id
|
|
|
|
});
|
|
|
|
member.guild.data = guildData;
|
|
|
|
|
|
|
|
const memberData = await this.client.findOrCreateMember({
|
|
|
|
id: member.id,
|
|
|
|
guildID: member.guild.id
|
|
|
|
});
|
|
|
|
if (memberData.mute.muted && memberData.mute.endDate > Date.now()) {
|
|
|
|
member.guild.channels.cache.forEach((channel) => {
|
2022-01-05 00:24:57 +05:00
|
|
|
channel.permissionOverwrites.edit(member.id, {
|
2022-01-04 02:18:28 +05:00
|
|
|
SEND_MESSAGES: false,
|
|
|
|
ADD_REACTIONS: false,
|
|
|
|
CONNECT: false
|
|
|
|
}).catch(() => {});
|
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
// Check if the autorole is enabled
|
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
|
|
|
|
|
|
|
// Check if welcome message is enabled
|
|
|
|
if (guildData.plugins.welcome.enabled) {
|
|
|
|
const channel = member.guild.channels.cache.get(guildData.plugins.welcome.channel);
|
|
|
|
if (channel) {
|
|
|
|
const message = guildData.plugins.welcome.message
|
|
|
|
.replace(/{user}/g, member)
|
|
|
|
.replace(/{server}/g, member.guild.name)
|
|
|
|
.replace(/{membercount}/g, member.guild.memberCount)
|
2022-01-13 00:26:23 +05:00
|
|
|
.replace(/{createdat}/g, this.client.printDate(member.user.createdAt));
|
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
|
|
|
|
ctx.font = applyText(canvas, member.guild.translate("administration/welcome:IMG_WELCOME", {
|
|
|
|
server: member.guild.name
|
2022-01-11 02:18:39 +05:00
|
|
|
}), 53, 625, "RubikMonoOne");
|
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
ctx.fillText(member.guild.translate("administration/welcome:IMG_WELCOME", {
|
|
|
|
server: member.guild.name
|
2022-01-11 02:18:39 +05:00
|
|
|
}), canvas.width - 700, canvas.height - 70);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
// Draw discriminator
|
|
|
|
ctx.font = "35px RubikMonoOne";
|
2022-01-11 02:18:39 +05:00
|
|
|
ctx.fillText(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";
|
2022-01-11 16:57:09 +05:00
|
|
|
ctx.fillText(`${member.guild.memberCount}й ${member.guild.translate("misc:NOUNS:MEMBERS:1")}`, 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";
|
|
|
|
ctx.fillText("#", canvas.width - 690, canvas.height - 165);
|
|
|
|
|
2022-01-11 02:18:39 +05:00
|
|
|
// Draw title
|
|
|
|
ctx.font = "45px RubikMonoOne";
|
|
|
|
ctx.strokeStyle = "#000000";
|
|
|
|
ctx.lineWidth = 10;
|
2022-01-04 02:18:28 +05:00
|
|
|
ctx.strokeText(member.guild.translate("administration/welcome:TITLE"), canvas.width - 670, canvas.height - 330);
|
2022-01-11 02:18:39 +05:00
|
|
|
ctx.fillStyle = "#FFFFFF";
|
2022-01-04 02:18:28 +05:00
|
|
|
ctx.fillText(member.guild.translate("administration/welcome:TITLE"), canvas.width - 670, canvas.height - 330);
|
|
|
|
|
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();
|
2022-01-11 02:18:39 +05:00
|
|
|
const avatar = await Canvas.loadImage(member.user.displayAvatarURL({
|
|
|
|
format: "png",
|
|
|
|
size: 512
|
|
|
|
}));
|
2022-01-04 02:18:28 +05:00
|
|
|
ctx.drawImage(avatar, 45, 90, 270, 270);
|
|
|
|
|
|
|
|
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), "welcome-image.png");
|
2022-01-11 02:18:39 +05:00
|
|
|
channel.send({
|
|
|
|
content: message,
|
|
|
|
files: [attachment]
|
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
} else {
|
2022-01-11 02:18:39 +05:00
|
|
|
channel.send({
|
|
|
|
content: message
|
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
}
|
|
|
|
};
|