blob: 9be71d5c92a3c4971f298d8af61d85890740ad81 [file] [log] [blame]
pineafan813bdf42022-07-24 10:39:10 +01001import convertCurlyBracketString from '../utils/convertCurlyBracketString.js'
2import client from '../utils/client.js';
pineafan41d93562022-07-30 22:10:15 +01003import EmojiEmbed from '../utils/generateEmojiEmbed.js';
pineafan813bdf42022-07-24 10:39:10 +01004
5export async function callback(_, member) {
6 if (member.bot) return
7 let config = await client.database.guilds.read(member.guild.id);
8 if (!config.welcome.enabled) return
9
pineafan41d93562022-07-30 22:10:15 +010010 if (config.welcome.channel) {
pineafan813bdf42022-07-24 10:39:10 +010011 let string = config.welcome.message
12 if (string) {
13 string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members)
pineafan813bdf42022-07-24 10:39:10 +010014 if (config.welcome.channel === 'dm') {
15 try {
pineafan41d93562022-07-30 22:10:15 +010016 await member.send({
17 embeds: [new EmojiEmbed()
18 .setDescription(string)
19 .setStatus('Success')
20 ]
21 })
22 } catch {}
pineafan813bdf42022-07-24 10:39:10 +010023 } else {
pineafan41d93562022-07-30 22:10:15 +010024 let channel = await member.guild.channels.fetch(config.welcome.channel)
pineafan813bdf42022-07-24 10:39:10 +010025 if (channel.guild.id !== member.guild.id) return
26 if (!channel) return
27 try {
pineafan41d93562022-07-30 22:10:15 +010028 await channel.send({
29 embeds: [new EmojiEmbed()
30 .setDescription(string)
31 .setStatus('Success')
32 ],
33 content: (config.welcome.ping ? `<@${config.welcome.ping}>` : '') + `<@${member.id}>`
34 })
pineafan813bdf42022-07-24 10:39:10 +010035 } catch (err) {
pineafan41d93562022-07-30 22:10:15 +010036 console.error(err) // SEN
pineafan813bdf42022-07-24 10:39:10 +010037 }
38 }
39 }
40 }
41}