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) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members); |
| 14 | if (config.welcome.channel === "dm") { |
| 15 | await member.send({ |
| 16 | embeds: [new EmojiEmbed() |
| 17 | .setDescription(string) |
| 18 | .setStatus("Success") |
| 19 | ] |
| 20 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 21 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 22 | const channel = await member.guild.channels.fetch(config.welcome.channel); |
| 23 | if (channel.guild.id !== member.guild.id) return; |
| 24 | if (!channel) return; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 25 | try { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 26 | await channel.send({ |
| 27 | embeds: [new EmojiEmbed() |
| 28 | .setDescription(string) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 29 | .setStatus("Success") |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 30 | ], |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 31 | content: (config.welcome.ping ? `<@${config.welcome.ping}>` : "") + `<@${member.id}>` |
| 32 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 33 | } catch (err) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 34 | console.error(err); // TODO: SEN |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |