blob: 47ed1406ec1701aa3b92b4745859ad2595145ea5 [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";
pineafan813bdf42022-07-24 10:39:10 +01006
PineaFan752af462022-12-31 21:59:38 +00007export async function callback(_client: NucleusClient, member: GuildMember) {
pineafan3a02ea32022-08-11 21:35:04 +01008 if (member.user.bot) return;
pineafan63fc5e22022-08-04 22:04:10 +01009 const config = await client.database.guilds.read(member.guild.id);
10 if (!config.welcome.enabled) return;
pineafan813bdf42022-07-24 10:39:10 +010011
pineafan41d93562022-07-30 22:10:15 +010012 if (config.welcome.channel) {
pineafan63fc5e22022-08-04 22:04:10 +010013 let string = config.welcome.message;
pineafan813bdf42022-07-24 10:39:10 +010014 if (string) {
Skyler Grey75ea9172022-08-06 10:22:23 +010015 string = await convertCurlyBracketString(
16 string,
17 member.id,
18 member.displayName,
19 member.guild.name,
20 member.guild.members
21 );
pineafan63fc5e22022-08-04 22:04:10 +010022 if (config.welcome.channel === "dm") {
23 await member.send({
Skyler Grey11236ba2022-08-08 21:13:33 +010024 embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")]
pineafan63fc5e22022-08-04 22:04:10 +010025 });
pineafan813bdf42022-07-24 10:39:10 +010026 } else {
pineafan3a02ea32022-08-11 21:35:04 +010027 const channel: GuildChannel | null = await member.guild.channels.fetch(config.welcome.channel);
28 if (!channel) return; // TODO: SEN
29 if (!(channel instanceof BaseGuildTextChannel)) return;
pineafan63fc5e22022-08-04 22:04:10 +010030 if (channel.guild.id !== member.guild.id) return;
pineafan813bdf42022-07-24 10:39:10 +010031 try {
pineafan41d93562022-07-30 22:10:15 +010032 await channel.send({
Skyler Grey11236ba2022-08-08 21:13:33 +010033 embeds: [new EmojiEmbed().setDescription(string).setStatus("Success")],
34 content: (config.welcome.ping ? `<@${config.welcome.ping}>` : "") + `<@${member.id}>`
pineafan63fc5e22022-08-04 22:04:10 +010035 });
pineafan813bdf42022-07-24 10:39:10 +010036 } catch (err) {
pineafan63fc5e22022-08-04 22:04:10 +010037 console.error(err); // TODO: SEN
pineafan813bdf42022-07-24 10:39:10 +010038 }
39 }
40 }
41 }
Skyler Grey75ea9172022-08-06 10:22:23 +010042}