pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import convertCurlyBracketString from "../utils/convertCurlyBracketString.js"; |
| 2 | import client from "../utils/client.js"; |
| 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) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | if (member.bot) return; |
| 7 | const config = await client.database.guilds.read(member.guild.id); |
| 8 | if (!config.welcome.enabled) return; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 9 | |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 10 | if (config.welcome.channel) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | let string = config.welcome.message; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 12 | if (string) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 13 | string = await convertCurlyBracketString( |
| 14 | string, |
| 15 | member.id, |
| 16 | member.displayName, |
| 17 | member.guild.name, |
| 18 | member.guild.members |
| 19 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 20 | if (config.welcome.channel === "dm") { |
| 21 | await member.send({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 22 | embeds: [ |
| 23 | new EmojiEmbed() |
| 24 | .setDescription(string) |
| 25 | .setStatus("Success") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 26 | ] |
| 27 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 28 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 29 | const channel = await member.guild.channels.fetch( |
| 30 | config.welcome.channel |
| 31 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 32 | if (channel.guild.id !== member.guild.id) return; |
| 33 | if (!channel) return; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 34 | try { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 35 | await channel.send({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 36 | embeds: [ |
| 37 | new EmojiEmbed() |
| 38 | .setDescription(string) |
| 39 | .setStatus("Success") |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 40 | ], |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 41 | content: |
| 42 | (config.welcome.ping |
| 43 | ? `<@${config.welcome.ping}>` |
| 44 | : "") + `<@${member.id}>` |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 45 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 46 | } catch (err) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 47 | console.error(err); // TODO: SEN |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | } |
| 51 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 52 | } |