blob: 8e471c6bb85a4471252dd2cf187ad5dd57bc33b8 [file] [log] [blame]
Skyler Greyda16adf2023-03-05 10:22:12 +00001import { getCommandMentionByName } from "./../utils/getCommandDataByName.js";
pineafan63fc5e22022-08-04 22:04:10 +01002import convertCurlyBracketString from "../utils/convertCurlyBracketString.js";
3import client from "../utils/client.js";
4import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafan3a02ea32022-08-11 21:35:04 +01005import { GuildChannel, GuildMember, BaseGuildTextChannel } from "discord.js";
PineaFan5bea7e12023-01-05 21:20:04 +00006import singleNotify from "../utils/singleNotify.js";
pineafan813bdf42022-07-24 10:39:10 +01007
pineafan6de4da52023-03-07 20:43:44 +00008export async function callback(member: GuildMember) {
pineafan3a02ea32022-08-11 21:35:04 +01009 if (member.user.bot) return;
pineafan63fc5e22022-08-04 22:04:10 +010010 const config = await client.database.guilds.read(member.guild.id);
11 if (!config.welcome.enabled) return;
pineafan813bdf42022-07-24 10:39:10 +010012
pineafan41d93562022-07-30 22:10:15 +010013 if (config.welcome.channel) {
pineafan63fc5e22022-08-04 22:04:10 +010014 let string = config.welcome.message;
pineafan813bdf42022-07-24 10:39:10 +010015 if (string) {
Skyler Grey75ea9172022-08-06 10:22:23 +010016 string = await convertCurlyBracketString(
17 string,
18 member.id,
19 member.displayName,
20 member.guild.name,
21 member.guild.members
22 );
pineafan63fc5e22022-08-04 22:04:10 +010023 if (config.welcome.channel === "dm") {
24 await member.send({
Skyler Grey11236ba2022-08-08 21:13:33 +010025 embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")]
pineafan63fc5e22022-08-04 22:04:10 +010026 });
pineafan813bdf42022-07-24 10:39:10 +010027 } else {
Skyler Greyda16adf2023-03-05 10:22:12 +000028 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 );
pineafan3a02ea32022-08-11 21:35:04 +010040 if (!(channel instanceof BaseGuildTextChannel)) return;
pineafan63fc5e22022-08-04 22:04:10 +010041 if (channel.guild.id !== member.guild.id) return;
pineafan813bdf42022-07-24 10:39:10 +010042 try {
pineafan41d93562022-07-30 22:10:15 +010043 await channel.send({
Skyler Grey11236ba2022-08-08 21:13:33 +010044 embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")],
TheCodedProf01cba762023-02-18 15:55:05 -050045 content: (config.welcome.ping ? `<@&${config.welcome.ping}>` : "") + `<@${member.id}>`
pineafan63fc5e22022-08-04 22:04:10 +010046 });
pineafan813bdf42022-07-24 10:39:10 +010047 } catch (err) {
PineaFan5bea7e12023-01-05 21:20:04 +000048 singleNotify(
49 "welcomeChannelDeleted",
50 member.guild.id,
Skyler Greyda16adf2023-03-05 10:22:12 +000051 `The welcome channel has been deleted or is no longer accessible. Use ${getCommandMentionByName(
52 "settings/welcome"
53 )} to set a new one`,
PineaFan5bea7e12023-01-05 21:20:04 +000054 "Warning"
Skyler Greyda16adf2023-03-05 10:22:12 +000055 );
pineafan813bdf42022-07-24 10:39:10 +010056 }
57 }
58 }
59 }
Skyler Grey75ea9172022-08-06 10:22:23 +010060}