blob: 56391ec28621d39332a50a90913eb8de5a39d3b7 [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) {
Skyler Grey75ea9172022-08-06 10:22:23 +010013 string = await convertCurlyBracketString(
14 string,
15 member.id,
16 member.displayName,
17 member.guild.name,
18 member.guild.members
19 );
pineafan63fc5e22022-08-04 22:04:10 +010020 if (config.welcome.channel === "dm") {
21 await member.send({
Skyler Grey11236ba2022-08-08 21:13:33 +010022 embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")]
pineafan63fc5e22022-08-04 22:04:10 +010023 });
pineafan813bdf42022-07-24 10:39:10 +010024 } else {
Skyler Grey11236ba2022-08-08 21:13:33 +010025 const channel = await member.guild.channels.fetch(config.welcome.channel);
pineafan63fc5e22022-08-04 22:04:10 +010026 if (channel.guild.id !== member.guild.id) return;
27 if (!channel) return;
pineafan813bdf42022-07-24 10:39:10 +010028 try {
pineafan41d93562022-07-30 22:10:15 +010029 await channel.send({
Skyler Grey11236ba2022-08-08 21:13:33 +010030 embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")],
31 content: (config.welcome.ping ? `<@${config.welcome.ping}>` : "") + `<@${member.id}>`
pineafan63fc5e22022-08-04 22:04:10 +010032 });
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 }
Skyler Grey75ea9172022-08-06 10:22:23 +010039}