From 41c58e1d781a1c4aa2de637e6632689fdecdcad7 Mon Sep 17 00:00:00 2001 From: Androz2091 Date: Fri, 14 May 2021 11:40:47 +0200 Subject: [PATCH] :bug: Fix welcome and goodbye messages --- events/guildMemberAdd.js | 187 ++++++++++++++++++------------------ events/guildMemberRemove.js | 160 +++++++++++++++--------------- 2 files changed, 172 insertions(+), 175 deletions(-) diff --git a/events/guildMemberAdd.js b/events/guildMemberAdd.js index f2bd8e8267..7cd7002fb7 100644 --- a/events/guildMemberAdd.js +++ b/events/guildMemberAdd.js @@ -22,112 +22,111 @@ module.exports = class { async run (member) { - member.guild.members.fetch().then(async (guild) => { + await member.guild.members.fetch(); - const guildData = await this.client.findOrCreateGuild({ id: guild.id }); - member.guild.data = guildData; + const guildData = await this.client.findOrCreateGuild({ id: member.guild.id }); + member.guild.data = guildData; - const memberData = await this.client.findOrCreateMember({ id: member.id, guildID: guild.id }); - if(memberData.mute.muted && memberData.mute.endDate > Date.now()){ - guild.channels.cache.forEach((channel) => { - channel.updateOverwrite(member.id, { - SEND_MESSAGES: false, - ADD_REACTIONS: false, - CONNECT: false - }).catch(() => {}); - }); - } + 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) => { + channel.updateOverwrite(member.id, { + SEND_MESSAGES: false, + ADD_REACTIONS: false, + CONNECT: false + }).catch(() => {}); + }); + } - // Check if the autorole is enabled - if(guildData.plugins.autorole.enabled){ - member.roles.add(guildData.plugins.autorole.role).catch(() => {}); - } + // Check if the autorole is enabled + if(guildData.plugins.autorole.enabled){ + member.roles.add(guildData.plugins.autorole.role).catch(() => {}); + } - // 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, guild.name) - .replace(/{membercount}/g, guild.memberCount); - if(guildData.plugins.welcome.withImage){ - const canvas = Canvas.createCanvas(1024, 450), - ctx = canvas.getContext("2d"); + // 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); + if(guildData.plugins.welcome.withImage){ + const canvas = Canvas.createCanvas(1024, 450), + ctx = canvas.getContext("2d"); - // Background language - const background = await Canvas.loadImage("./assets/img/greetings_background.png"); - // This uses the canvas dimensions to stretch the image onto the entire canvas - ctx.drawImage(background, 0, 0, canvas.width, canvas.height); - // Draw username - ctx.fillStyle = "#ffffff"; - const username = stringCleaner(member.user.username, { - separator: " ", - lowercase: false, - decamelize: false, - preserveLeadingUnderscore: true, - }); - ctx.font = applyText(canvas, username, 48); - ctx.fillText(username, canvas.width - 660, canvas.height - 248); - // Draw server name - ctx.font = applyText(canvas, member.guild.translate("administration/welcome:IMG_WELCOME", { - server: member.guild.name - }), 53); - ctx.fillText(member.guild.translate("administration/welcome:IMG_WELCOME", { - server: member.guild.name - }), canvas.width - 690, canvas.height - 65); - // Draw discriminator - ctx.font = "40px Bold"; - ctx.fillText(member.user.discriminator, canvas.width - 623, canvas.height - 178); - // Draw number - ctx.font = "22px Bold"; - ctx.fillText(member.guild.translate("administration/welcome:IMG_NB", { - memberCount: member.guild.memberCount - }), 40, canvas.height - 50); - // Draw # for discriminator - ctx.fillStyle = "#44d14a"; - ctx.font = "75px SketchMatch"; - ctx.fillText("#", canvas.width - 690, canvas.height - 165); - // Draw Title with gradient - ctx.font = "90px Bold"; - ctx.strokeStyle = "#1d2124"; - ctx.lineWidth = 15; - ctx.strokeText(member.guild.translate("administration/welcome:TITLE"), canvas.width - 620, canvas.height - 330); - var gradient = ctx.createLinearGradient(canvas.width - 780, 0, canvas.width - 30, 0); - gradient.addColorStop(0, "#e15500"); - gradient.addColorStop(1, "#e7b121"); - ctx.fillStyle = gradient; - ctx.fillText(member.guild.translate("administration/welcome:TITLE"), canvas.width - 620, canvas.height - 330); + // Background language + const background = await Canvas.loadImage("./assets/img/greetings_background.png"); + // This uses the canvas dimensions to stretch the image onto the entire canvas + ctx.drawImage(background, 0, 0, canvas.width, canvas.height); + // Draw username + ctx.fillStyle = "#ffffff"; + const username = stringCleaner(member.user.username, { + separator: " ", + lowercase: false, + decamelize: false, + preserveLeadingUnderscore: true, + }); + ctx.font = applyText(canvas, username, 48); + ctx.fillText(username, canvas.width - 660, canvas.height - 248); + // Draw server name + ctx.font = applyText(canvas, member.guild.translate("administration/welcome:IMG_WELCOME", { + server: member.guild.name + }), 53); + ctx.fillText(member.guild.translate("administration/welcome:IMG_WELCOME", { + server: member.guild.name + }), canvas.width - 690, canvas.height - 65); + // Draw discriminator + ctx.font = "40px Bold"; + ctx.fillText(member.user.discriminator, canvas.width - 623, canvas.height - 178); + // Draw number + ctx.font = "22px Bold"; + ctx.fillText(member.guild.translate("administration/welcome:IMG_NB", { + memberCount: member.guild.memberCount + }), 40, canvas.height - 50); + // Draw # for discriminator + ctx.fillStyle = "#44d14a"; + ctx.font = "75px SketchMatch"; + ctx.fillText("#", canvas.width - 690, canvas.height - 165); + // Draw Title with gradient + ctx.font = "90px Bold"; + ctx.strokeStyle = "#1d2124"; + ctx.lineWidth = 15; + ctx.strokeText(member.guild.translate("administration/welcome:TITLE"), canvas.width - 620, canvas.height - 330); + var gradient = ctx.createLinearGradient(canvas.width - 780, 0, canvas.width - 30, 0); + gradient.addColorStop(0, "#e15500"); + gradient.addColorStop(1, "#e7b121"); + ctx.fillStyle = gradient; + ctx.fillText(member.guild.translate("administration/welcome:TITLE"), canvas.width - 620, canvas.height - 330); - // Pick up the pen - ctx.beginPath(); - //Define Stroke Line - ctx.lineWidth = 10; - //Define Stroke Style - ctx.strokeStyle = "#03A9F4"; - // Start the arc to form a circle - ctx.arc(180, 225, 135, 0, Math.PI * 2, true); - // Draw Stroke - ctx.stroke(); - // Put the pen down - ctx.closePath(); - // Clip off the region you drew on - ctx.clip(); + // Pick up the pen + ctx.beginPath(); + //Define Stroke Line + ctx.lineWidth = 10; + //Define Stroke Style + ctx.strokeStyle = "#03A9F4"; + // Start the arc to form a circle + ctx.arc(180, 225, 135, 0, Math.PI * 2, true); + // Draw Stroke + ctx.stroke(); + // Put the pen down + ctx.closePath(); + // Clip off the region you drew on + ctx.clip(); - const options = { format: "png", size: 512 }, - avatar = await Canvas.loadImage(member.user.displayAvatarURL(options)); + const options = { format: "png", size: 512 }, + avatar = await Canvas.loadImage(member.user.displayAvatarURL(options)); // Move the image downwards vertically and constrain its height to 200, so it"s a square - ctx.drawImage(avatar, 45, 90, 270, 270); + ctx.drawImage(avatar, 45, 90, 270, 270); - const attachment = new Discord.MessageAttachment(canvas.toBuffer(), "welcome-image.png"); - channel.send(message, attachment); - } else { - channel.send(message); - } + const attachment = new Discord.MessageAttachment(canvas.toBuffer(), "welcome-image.png"); + channel.send(message, attachment); + } else { + channel.send(message); } } + } - }); } }; \ No newline at end of file diff --git a/events/guildMemberRemove.js b/events/guildMemberRemove.js index 6944ca9daf..65c2aeef4c 100644 --- a/events/guildMemberRemove.js +++ b/events/guildMemberRemove.js @@ -22,96 +22,94 @@ module.exports = class { async run (member) { - member.guild.members.fetch().then(async (guild) => { + await member.guild.members.fetch(); - const guildData = await this.client.findOrCreateGuild({ id: guild.id }); - member.guild.data = guildData; + const guildData = await this.client.findOrCreateGuild({ id: member.guild.id }); + member.guild.data = guildData; - // Check if goodbye message is enabled - if(guildData.plugins.goodbye.enabled){ - const channel = guild.channels.cache.get(guildData.plugins.goodbye.channel); - if(channel){ - const message = guildData.plugins.goodbye.message - .replace(/{user}/g, member.user.tag) - .replace(/{server}/g, guild.name) - .replace(/{membercount}/g, guild.memberCount); - if(guildData.plugins.goodbye.withImage){ - const canvas = Canvas.createCanvas(1024, 450), - ctx = canvas.getContext("2d"); + // Check if goodbye message is enabled + if(guildData.plugins.goodbye.enabled){ + const channel = member.guild.channels.cache.get(guildData.plugins.goodbye.channel); + if(channel){ + const message = guildData.plugins.goodbye.message + .replace(/{user}/g, member.user.tag) + .replace(/{server}/g, member.guild.name) + .replace(/{membercount}/g, member.guild.memberCount); + if(guildData.plugins.goodbye.withImage){ + const canvas = Canvas.createCanvas(1024, 450), + ctx = canvas.getContext("2d"); - // Background language" - const background = await Canvas.loadImage("./assets/img/greetings_background.png"); - // This uses the canvas dimensions to stretch the image onto the entire canvas - ctx.drawImage(background, 0, 0, canvas.width, canvas.height); - // Draw username - ctx.fillStyle = "#ffffff"; - const username = stringCleaner(member.user.username, { - separator: " ", - lowercase: false, - decamelize: false, - preserveLeadingUnderscore: true, - }); - ctx.font = applyText(canvas, username, 48); - ctx.fillText(username, canvas.width - 660, canvas.height - 248); - // Draw server name - ctx.font = applyText(canvas, member.guild.translate("administration/goodbye:IMG_GOODBYE", { - server: member.guild.name - }), 53); - ctx.fillText(member.guild.translate("administration/goodbye:IMG_GOODBYE", { - server: member.guild.name - }), canvas.width - 690, canvas.height - 65); - // Draw discriminator - ctx.font = "40px Bold"; - ctx.fillText(member.user.discriminator, canvas.width - 623, canvas.height - 178); - // Draw number - ctx.font = "22px Bold"; - ctx.fillText(member.guild.translate("administration/goodbye:IMG_NB", { - memberCount: member.guild.memberCount - }), 40, canvas.height - 50); - // Draw # for discriminator - ctx.fillStyle = "#44d14a"; - ctx.font = "75px SketchMatch"; - ctx.fillText("#", canvas.width - 690, canvas.height - 165); - // Draw Title with gradient - ctx.font = "90px Bold"; - ctx.strokeStyle = "#1d2124"; - ctx.lineWidth = 15; - ctx.strokeText(member.guild.translate("administration/goodbye:TITLE"), canvas.width - 620, canvas.height - 330); - var gradient = ctx.createLinearGradient(canvas.width - 780, 0, canvas.width - 30, 0); - gradient.addColorStop(0, "#e15500"); - gradient.addColorStop(1, "#e7b121"); - ctx.fillStyle = gradient; - ctx.fillText(member.guild.translate("administration/goodbye:TITLE"), canvas.width - 620, canvas.height - 330); + // Background language" + const background = await Canvas.loadImage("./assets/img/greetings_background.png"); + // This uses the canvas dimensions to stretch the image onto the entire canvas + ctx.drawImage(background, 0, 0, canvas.width, canvas.height); + // Draw username + ctx.fillStyle = "#ffffff"; + const username = stringCleaner(member.user.username, { + separator: " ", + lowercase: false, + decamelize: false, + preserveLeadingUnderscore: true, + }); + ctx.font = applyText(canvas, username, 48); + ctx.fillText(username, canvas.width - 660, canvas.height - 248); + // Draw server name + ctx.font = applyText(canvas, member.guild.translate("administration/goodbye:IMG_GOODBYE", { + server: member.guild.name + }), 53); + ctx.fillText(member.guild.translate("administration/goodbye:IMG_GOODBYE", { + server: member.guild.name + }), canvas.width - 690, canvas.height - 65); + // Draw discriminator + ctx.font = "40px Bold"; + ctx.fillText(member.user.discriminator, canvas.width - 623, canvas.height - 178); + // Draw number + ctx.font = "22px Bold"; + ctx.fillText(member.guild.translate("administration/goodbye:IMG_NB", { + memberCount: member.guild.memberCount + }), 40, canvas.height - 50); + // Draw # for discriminator + ctx.fillStyle = "#44d14a"; + ctx.font = "75px SketchMatch"; + ctx.fillText("#", canvas.width - 690, canvas.height - 165); + // Draw Title with gradient + ctx.font = "90px Bold"; + ctx.strokeStyle = "#1d2124"; + ctx.lineWidth = 15; + ctx.strokeText(member.guild.translate("administration/goodbye:TITLE"), canvas.width - 620, canvas.height - 330); + var gradient = ctx.createLinearGradient(canvas.width - 780, 0, canvas.width - 30, 0); + gradient.addColorStop(0, "#e15500"); + gradient.addColorStop(1, "#e7b121"); + ctx.fillStyle = gradient; + ctx.fillText(member.guild.translate("administration/goodbye:TITLE"), canvas.width - 620, canvas.height - 330); - // Pick up the pen - ctx.beginPath(); - //Define Stroke Line - ctx.lineWidth = 10; - //Define Stroke Style - ctx.strokeStyle = "#df0909"; - // Start the arc to form a circle - ctx.arc(180, 225, 135, 0, Math.PI * 2, true); - // Draw Stroke - ctx.stroke(); - // Put the pen down - ctx.closePath(); - // Clip off the region you drew on - ctx.clip(); + // Pick up the pen + ctx.beginPath(); + //Define Stroke Line + ctx.lineWidth = 10; + //Define Stroke Style + ctx.strokeStyle = "#df0909"; + // Start the arc to form a circle + ctx.arc(180, 225, 135, 0, Math.PI * 2, true); + // Draw Stroke + ctx.stroke(); + // Put the pen down + ctx.closePath(); + // Clip off the region you drew on + ctx.clip(); - const options = { format: "png", size: 512 }, - avatar = await Canvas.loadImage(member.user.displayAvatarURL(options)); + const options = { format: "png", size: 512 }, + avatar = await Canvas.loadImage(member.user.displayAvatarURL(options)); // Move the image downwards vertically and constrain its height to 200, so it"s a square - ctx.drawImage(avatar, 45, 90, 270, 270); + ctx.drawImage(avatar, 45, 90, 270, 270); - const attachment = new Discord.MessageAttachment(canvas.toBuffer(), "goodbye-image.png"); - channel.send(message, attachment); - } else { - channel.send(message); - } + const attachment = new Discord.MessageAttachment(canvas.toBuffer(), "goodbye-image.png"); + channel.send(message, attachment); + } else { + channel.send(message); } } - - }); + } } }; \ No newline at end of file