blob: 5597b818da1635cf732de8a6102065bc7e7e8347 [file] [log] [blame]
Skyler Greyda16adf2023-03-05 10:22:12 +00001import { getCommandMentionByName } from "./../utils/getCommandDataByName.js";
PineaFan752af462022-12-31 21:59:38 +00002import type { NucleusClient } from "../utils/client.js";
pineafan63fc5e22022-08-04 22:04:10 +01003import convertCurlyBracketString from "../utils/convertCurlyBracketString.js";
4import client from "../utils/client.js";
5import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafan3a02ea32022-08-11 21:35:04 +01006import { GuildChannel, GuildMember, BaseGuildTextChannel } from "discord.js";
PineaFan5bea7e12023-01-05 21:20:04 +00007import singleNotify from "../utils/singleNotify.js";
pineafan813bdf42022-07-24 10:39:10 +01008
PineaFan752af462022-12-31 21:59:38 +00009export async function callback(_client: NucleusClient, member: GuildMember) {
pineafan3a02ea32022-08-11 21:35:04 +010010 if (member.user.bot) return;
pineafan63fc5e22022-08-04 22:04:10 +010011 const config = await client.database.guilds.read(member.guild.id);
12 if (!config.welcome.enabled) return;
pineafan813bdf42022-07-24 10:39:10 +010013
pineafan41d93562022-07-30 22:10:15 +010014 if (config.welcome.channel) {
pineafan63fc5e22022-08-04 22:04:10 +010015 let string = config.welcome.message;
pineafan813bdf42022-07-24 10:39:10 +010016 if (string) {
Skyler Grey75ea9172022-08-06 10:22:23 +010017 string = await convertCurlyBracketString(
18 string,
19 member.id,
20 member.displayName,
21 member.guild.name,
22 member.guild.members
23 );
pineafan63fc5e22022-08-04 22:04:10 +010024 if (config.welcome.channel === "dm") {
25 await member.send({
Skyler Grey11236ba2022-08-08 21:13:33 +010026 embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")]
pineafan63fc5e22022-08-04 22:04:10 +010027 });
pineafan813bdf42022-07-24 10:39:10 +010028 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +000029 const channel: GuildChannel | null = (await member.guild.channels.fetch(
30 config.welcome.channel
31 )) as GuildChannel | null;
32 if (!channel)
33 return await singleNotify(
34 "welcomeChannelDeleted",
35 member.guild.id,
36 `The welcome channel has been deleted or is no longer accessible. Use ${getCommandMentionByName(
37 "settings/welcome"
38 )} to set a new one`,
39 "Warning"
40 );
pineafan3a02ea32022-08-11 21:35:04 +010041 if (!(channel instanceof BaseGuildTextChannel)) return;
pineafan63fc5e22022-08-04 22:04:10 +010042 if (channel.guild.id !== member.guild.id) return;
pineafan813bdf42022-07-24 10:39:10 +010043 try {
pineafan41d93562022-07-30 22:10:15 +010044 await channel.send({
Skyler Grey11236ba2022-08-08 21:13:33 +010045 embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")],
TheCodedProf01cba762023-02-18 15:55:05 -050046 content: (config.welcome.ping ? `<@&${config.welcome.ping}>` : "") + `<@${member.id}>`
pineafan63fc5e22022-08-04 22:04:10 +010047 });
pineafan813bdf42022-07-24 10:39:10 +010048 } catch (err) {
PineaFan5bea7e12023-01-05 21:20:04 +000049 singleNotify(
50 "welcomeChannelDeleted",
51 member.guild.id,
Skyler Greyda16adf2023-03-05 10:22:12 +000052 `The welcome channel has been deleted or is no longer accessible. Use ${getCommandMentionByName(
53 "settings/welcome"
54 )} to set a new one`,
PineaFan5bea7e12023-01-05 21:20:04 +000055 "Warning"
Skyler Greyda16adf2023-03-05 10:22:12 +000056 );
pineafan813bdf42022-07-24 10:39:10 +010057 }
58 }
59 }
60 }
Skyler Grey75ea9172022-08-06 10:22:23 +010061}