-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguildMemberAdd.js
66 lines (54 loc) · 2.85 KB
/
guildMemberAdd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
module.exports = async (guild, member) => {
Promise.all([DB.servers.findOne({id:guild.id}).cache(), DB.users.findOne({id:member.id}).cache()]).then(([svData, userData]) => {
if (!svData?.modules.GREET.enabled) return;
const welcomeTimer = svData.modules.GREET.timer;
let welcomeText = svData.modules.GREET.text
.replace(/%pfLink%/g, `${paths.DASH}/profile/${userData.personalhandle || userData.id}`)
.replace(/%lvGlobal%/g, `${userData.modules.level}`)
.replace(/%reputation%/g, `${userData.modules.commend || 0}`)
.replace(/%membernumber%/g, `${guild.memberCount}`)
.replace(/%user%/g, `<@${member.id}>`)
.replace(/%userid%/g, `${member.id}`)
.replace(/%usermention%/g, `<@${member.id}>`)
.replace(/%mention%/g, `<@${member.id}>`)
.replace(/%username%/g, member.user.username)
.replace(/%tag%/g, member.user.tag)
.replace(/%server%/g, guild.name)
.replace(/%servername%/g, guild.name)
.replace(/%serverIcon%/g, `${guild.iconURL}`)
.replace(/%userAvatar%/g, `${member.user.avatarURL}`)
.replace(/%userBackground%/g, `${paths.CDN}/backdrops/${userData.modules.bgID}.png`)
.split("%embed%");
welcomeText[0] = welcomeText[0].replace(/[^<]#([^ |^>|^"]+)/g,
(m, p1) => `<#${(guild.channels.find((x) => x.name === p1) || { id: "0000000" }).id}>`);
let embed;
if (welcomeText[1]){
try {
embed = welcomeText[1] ? JSON.parse(welcomeText[1]) : {};
} catch (err) {
embed = undefined;
}
}
welcomeText = welcomeText[0] || welcomeText;
const welcomeChannel = svData.modules.GREET.channel;
const welcomeSkin = svData.modules.GREET.type;
const welcomeImage = true || svData.modules.GREET.image;
if (embed) {
embed.image = embed.image?.url ? embed.image : welcomeImage && embed ? { url: "attachment://in.png" } : undefined;
embed.color = embed.color === 0 ? parseInt((userData.modules.favcolor || "#FF3355").replace("#", ""), 16) : embed.color;
}
const P = { lngs: [svData.modules.LANGUAGE || "en", "dev"] };
const txt = $t("logs.userJoin", P).replace(/\*/g, "");
const url = `${paths.GENERATORS}/userio/in/${member.id}/${welcomeSkin || "minimal"}.png?text=${encodeURIComponent(txt)}&ava=${member.user.avatarURL}`;
resolveFile(url).then(async (buffer) => {
const welcomeChannelObj = PLX.getChannel(welcomeChannel);
if (!welcomeChannelObj.permissionsOf(PLX.user.id).has('viewChannel') || !welcomeChannelObj.permissionsOf(PLX.user.id).has('sendMessages')) return;
welcomeChannelObj.send({
content: welcomeText,
embed
}, (welcomeImage ? {file:buffer, name: "in.png" } : null)).then((ms) => {
if (welcomeTimer) ms.deleteAfter(welcomeTimer).catch(() => null);
}).catch(console.error);
}).catch(console.error);
}).catch(err=>null);
};