Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1 | import { getCommandMentionByName } from "./../utils/getCommandDataByName.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 2 | import convertCurlyBracketString from "../utils/convertCurlyBracketString.js"; |
| 3 | import client from "../utils/client.js"; |
| 4 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 5 | import { GuildChannel, GuildMember, BaseGuildTextChannel } from "discord.js"; |
PineaFan | 5bea7e1 | 2023-01-05 21:20:04 +0000 | [diff] [blame] | 6 | import singleNotify from "../utils/singleNotify.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 7 | |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 8 | export async function callback(member: GuildMember) { |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 9 | if (member.user.bot) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 10 | const config = await client.database.guilds.read(member.guild.id); |
| 11 | if (!config.welcome.enabled) return; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 12 | |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 13 | if (config.welcome.channel) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | let string = config.welcome.message; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 15 | if (string) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 16 | string = await convertCurlyBracketString( |
| 17 | string, |
| 18 | member.id, |
| 19 | member.displayName, |
| 20 | member.guild.name, |
| 21 | member.guild.members |
| 22 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 23 | if (config.welcome.channel === "dm") { |
| 24 | await member.send({ |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 25 | embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")] |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 26 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 27 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 28 | const channel: GuildChannel | null = (await member.guild.channels.fetch( |
| 29 | config.welcome.channel |
| 30 | )) as GuildChannel | null; |
| 31 | if (!channel) |
| 32 | return await singleNotify( |
| 33 | "welcomeChannelDeleted", |
| 34 | member.guild.id, |
| 35 | `The welcome channel has been deleted or is no longer accessible. Use ${getCommandMentionByName( |
| 36 | "settings/welcome" |
| 37 | )} to set a new one`, |
| 38 | "Warning" |
| 39 | ); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 40 | if (!(channel instanceof BaseGuildTextChannel)) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 41 | if (channel.guild.id !== member.guild.id) return; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 42 | try { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 43 | await channel.send({ |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 44 | embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")], |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 45 | content: (config.welcome.ping ? `<@&${config.welcome.ping}>` : "") + `<@${member.id}>` |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 46 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 47 | } catch (err) { |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame^] | 48 | await singleNotify( |
PineaFan | 5bea7e1 | 2023-01-05 21:20:04 +0000 | [diff] [blame] | 49 | "welcomeChannelDeleted", |
| 50 | member.guild.id, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 51 | `The welcome channel has been deleted or is no longer accessible. Use ${getCommandMentionByName( |
| 52 | "settings/welcome" |
| 53 | )} to set a new one`, |
PineaFan | 5bea7e1 | 2023-01-05 21:20:04 +0000 | [diff] [blame] | 54 | "Warning" |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 55 | ); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 60 | } |