blob: 36a93fbd668a4f123522a5674a53ac8c2ff0eb02 [file] [log] [blame]
pineafan3a02ea32022-08-11 21:35:04 +01001// @ts-expect-error
2import type { HaikuClient } from "jshaiku";
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";
pineafan813bdf42022-07-24 10:39:10 +01007
pineafan3a02ea32022-08-11 21:35:04 +01008export async function callback(_client: HaikuClient, member: GuildMember) {
9 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 {
pineafan3a02ea32022-08-11 21:35:04 +010028 const channel: GuildChannel | null = await member.guild.channels.fetch(config.welcome.channel);
29 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) {
pineafan63fc5e22022-08-04 22:04:10 +010038 console.error(err); // TODO: SEN
pineafan813bdf42022-07-24 10:39:10 +010039 }
40 }
41 }
42 }
Skyler Grey75ea9172022-08-06 10:22:23 +010043}