blob: 4971cc943d4dd278685a2b90a6fc6cefaf6a8856 [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 Grey75ea9172022-08-06 10:22:23 +010022 embeds: [
23 new EmojiEmbed()
24 .setDescription(string)
25 .setStatus("Success")
pineafan63fc5e22022-08-04 22:04:10 +010026 ]
27 });
pineafan813bdf42022-07-24 10:39:10 +010028 } else {
Skyler Grey75ea9172022-08-06 10:22:23 +010029 const channel = await member.guild.channels.fetch(
30 config.welcome.channel
31 );
pineafan63fc5e22022-08-04 22:04:10 +010032 if (channel.guild.id !== member.guild.id) return;
33 if (!channel) return;
pineafan813bdf42022-07-24 10:39:10 +010034 try {
pineafan41d93562022-07-30 22:10:15 +010035 await channel.send({
Skyler Grey75ea9172022-08-06 10:22:23 +010036 embeds: [
37 new EmojiEmbed()
38 .setDescription(string)
39 .setStatus("Success")
pineafan41d93562022-07-30 22:10:15 +010040 ],
Skyler Grey75ea9172022-08-06 10:22:23 +010041 content:
42 (config.welcome.ping
43 ? `<@${config.welcome.ping}>`
44 : "") + `<@${member.id}>`
pineafan63fc5e22022-08-04 22:04:10 +010045 });
pineafan813bdf42022-07-24 10:39:10 +010046 } catch (err) {
pineafan63fc5e22022-08-04 22:04:10 +010047 console.error(err); // TODO: SEN
pineafan813bdf42022-07-24 10:39:10 +010048 }
49 }
50 }
51 }
Skyler Grey75ea9172022-08-06 10:22:23 +010052}