blob: c2eede3c987473ec51a94e7f28625d3dd2d85501 [file] [log] [blame]
TheCodedProff86ba092023-01-27 17:10:07 -05001import { 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 {
PineaFan5bea7e12023-01-05 21:20:04 +000029 const channel: GuildChannel | null = await member.guild.channels.fetch(config.welcome.channel) as GuildChannel | null;
TheCodedProff86ba092023-01-27 17:10:07 -050030 if (!channel) return await singleNotify("welcomeChannelDeleted", member.guild.id, `The welcome channel has been deleted or is no longer accessible. Use ${getCommandMentionByName("settings/welcome")} to set a new one`, "Warning")
pineafan3a02ea32022-08-11 21:35:04 +010031 if (!(channel instanceof BaseGuildTextChannel)) return;
pineafan63fc5e22022-08-04 22:04:10 +010032 if (channel.guild.id !== member.guild.id) return;
pineafan813bdf42022-07-24 10:39:10 +010033 try {
pineafan41d93562022-07-30 22:10:15 +010034 await channel.send({
Skyler Grey11236ba2022-08-08 21:13:33 +010035 embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")],
TheCodedProf01cba762023-02-18 15:55:05 -050036 content: (config.welcome.ping ? `<@&${config.welcome.ping}>` : "") + `<@${member.id}>`
pineafan63fc5e22022-08-04 22:04:10 +010037 });
pineafan813bdf42022-07-24 10:39:10 +010038 } catch (err) {
PineaFan5bea7e12023-01-05 21:20:04 +000039 singleNotify(
40 "welcomeChannelDeleted",
41 member.guild.id,
TheCodedProff86ba092023-01-27 17:10:07 -050042 `The welcome channel has been deleted or is no longer accessible. Use ${getCommandMentionByName("settings/welcome")} to set a new one`,
PineaFan5bea7e12023-01-05 21:20:04 +000043 "Warning"
44 )
pineafan813bdf42022-07-24 10:39:10 +010045 }
46 }
47 }
48 }
Skyler Grey75ea9172022-08-06 10:22:23 +010049}