blob: b4bc374d8a35a92169b44ce4b2bb56ca35a335da [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import convertCurlyBracketString from "../utils/convertCurlyBracketString.js";
2import client from "../utils/client.js";
3import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafan813bdf42022-07-24 10:39:10 +01004
5export async function callback(_, member) {
pineafan63fc5e22022-08-04 22:04:10 +01006 if (member.bot) return;
7 const config = await client.database.guilds.read(member.guild.id);
8 if (!config.welcome.enabled) return;
pineafan813bdf42022-07-24 10:39:10 +01009
pineafan41d93562022-07-30 22:10:15 +010010 if (config.welcome.channel) {
pineafan63fc5e22022-08-04 22:04:10 +010011 let string = config.welcome.message;
pineafan813bdf42022-07-24 10:39:10 +010012 if (string) {
pineafan63fc5e22022-08-04 22:04:10 +010013 string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members);
14 if (config.welcome.channel === "dm") {
15 await member.send({
16 embeds: [new EmojiEmbed()
17 .setDescription(string)
18 .setStatus("Success")
19 ]
20 });
pineafan813bdf42022-07-24 10:39:10 +010021 } else {
pineafan63fc5e22022-08-04 22:04:10 +010022 const channel = await member.guild.channels.fetch(config.welcome.channel);
23 if (channel.guild.id !== member.guild.id) return;
24 if (!channel) return;
pineafan813bdf42022-07-24 10:39:10 +010025 try {
pineafan41d93562022-07-30 22:10:15 +010026 await channel.send({
27 embeds: [new EmojiEmbed()
28 .setDescription(string)
pineafan63fc5e22022-08-04 22:04:10 +010029 .setStatus("Success")
pineafan41d93562022-07-30 22:10:15 +010030 ],
pineafan63fc5e22022-08-04 22:04:10 +010031 content: (config.welcome.ping ? `<@${config.welcome.ping}>` : "") + `<@${member.id}>`
32 });
pineafan813bdf42022-07-24 10:39:10 +010033 } catch (err) {
pineafan63fc5e22022-08-04 22:04:10 +010034 console.error(err); // TODO: SEN
pineafan813bdf42022-07-24 10:39:10 +010035 }
36 }
37 }
38 }
39}