pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 1 | import convertCurlyBracketString from '../utils/convertCurlyBracketString.js' |
| 2 | import client from '../utils/client.js'; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 3 | import EmojiEmbed from '../utils/generateEmojiEmbed.js'; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 4 | |
| 5 | export 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 | |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 10 | if (config.welcome.channel) { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 11 | let string = config.welcome.message |
| 12 | if (string) { |
| 13 | string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 14 | if (config.welcome.channel === 'dm') { |
| 15 | try { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 16 | await member.send({ |
| 17 | embeds: [new EmojiEmbed() |
| 18 | .setDescription(string) |
| 19 | .setStatus('Success') |
| 20 | ] |
| 21 | }) |
| 22 | } catch {} |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 23 | } else { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 24 | let channel = await member.guild.channels.fetch(config.welcome.channel) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 25 | if (channel.guild.id !== member.guild.id) return |
| 26 | if (!channel) return |
| 27 | try { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 28 | 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 | }) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 35 | } catch (err) { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 36 | console.error(err) // SEN |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |