blob: 77220860ac38e2439e016ca65bd9b513a7727889 [file] [log] [blame]
PineaFan752af462022-12-31 21:59:38 +00001import type { NucleusClient } from "../utils/client.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
PineaFan752af462022-12-31 21:59:38 +00008export async function callback(_client: NucleusClient, 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 {
PineaFan5bea7e12023-01-05 21:20:04 +000028 const channel: GuildChannel | null = await member.guild.channels.fetch(config.welcome.channel) as GuildChannel | null;
pineafan3a02ea32022-08-11 21:35:04 +010029 if (!channel) return; // TODO: SEN
30 if (!(channel instanceof BaseGuildTextChannel)) return;
pineafan63fc5e22022-08-04 22:04:10 +010031 if (channel.guild.id !== member.guild.id) return;
pineafan813bdf42022-07-24 10:39:10 +010032 try {
pineafan41d93562022-07-30 22:10:15 +010033 await channel.send({
Skyler Grey11236ba2022-08-08 21:13:33 +010034 embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")],
35 content: (config.welcome.ping ? `<@${config.welcome.ping}>` : "") + `<@${member.id}>`
pineafan63fc5e22022-08-04 22:04:10 +010036 });
pineafan813bdf42022-07-24 10:39:10 +010037 } catch (err) {
PineaFan5bea7e12023-01-05 21:20:04 +000038 singleNotify(
39 "welcomeChannelDeleted",
40 member.guild.id,
41 "The welcome channel has been deleted or is no longer accessible. Use /settings welcome to set a new one",
42 "Warning"
43 )
pineafan813bdf42022-07-24 10:39:10 +010044 }
45 }
46 }
47 }
Skyler Grey75ea9172022-08-06 10:22:23 +010048}