blob: 6505265b1b7d067a1514f0dd4687567ded81959a [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import log from '../utils/log.js'
2import readConfig from '../utils/readConfig.js'
3import convertCurlyBracketString from '../utils/convertCurlyBracketString.js'
4
5export async function callback(_, member) {
6 if (member.bot) return
7 let config = await readConfig(member.guild.id);
8 if (!config.welcome.enabled) return
9
10 if (!config.welcome.verificationRequired.role) {
11 if (config.welcome.welcomeRole) {
12 try {
13 await member.roles.add(config.welcome.welcomeRole)
14 } catch (err) {
15 console.error(err)
16 }
17 }
18 }
19
20
21 if (!config.welcome.verificationRequired.message && config.welcome.channel) {
22 let string = config.welcome.message
23 if (string) {
24 string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members)
25
26 if (config.welcome.channel === 'dm') {
27 try {
28 await member.send(string)
29 } catch (err) {
30 console.error(err)
31 }
32 } else {
33 let channel = await member.client.channels.fetch(config.welcome.channel)
34 if (channel.guild.id !== member.guild.id) return
35 if (!channel) return // TODO: Notify mods
36 try {
37 await channel.send(string)
38 } catch (err) {
39 console.error(err)
40 }
41 }
42 }
43 }
44}