blob: 5b80fbd944c6bc57b0e2e26832456d59691754b4 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import log from '../utils/log.js'
pineafan32767212022-03-14 21:27:39 +00002import convertCurlyBracketString from '../utils/convertCurlyBracketString.js'
pineafan6702cef2022-06-13 17:52:37 +01003import client from '../utils/client.js';
pineafan32767212022-03-14 21:27:39 +00004
5export async function callback(_, member) {
pineafane625d782022-05-09 18:04:32 +01006 if (member.bot) return
pineafan4edb7762022-06-26 19:21:04 +01007 let config = await client.database.guilds.read(member.guild.id);
pineafan32767212022-03-14 21:27:39 +00008 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
pineafan32767212022-03-14 21:27:39 +000020 if (!config.welcome.verificationRequired.message && config.welcome.channel) {
21 let string = config.welcome.message
22 if (string) {
23 string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members)
24
25 if (config.welcome.channel === 'dm') {
26 try {
27 await member.send(string)
28 } catch (err) {
29 console.error(err)
30 }
31 } else {
32 let channel = await member.client.channels.fetch(config.welcome.channel)
33 if (channel.guild.id !== member.guild.id) return
pineafan377794f2022-04-18 19:01:01 +010034 if (!channel) return
pineafan32767212022-03-14 21:27:39 +000035 try {
36 await channel.send(string)
37 } catch (err) {
38 console.error(err)
39 }
40 }
41 }
42 }
43}