pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import log from '../utils/log.js' |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 2 | import convertCurlyBracketString from '../utils/convertCurlyBracketString.js' |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 3 | import client from '../utils/client.js'; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 4 | |
| 5 | export async function callback(_, member) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | if (member.bot) return |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 7 | let config = await client.database.guilds.read(member.guild.id); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 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 | |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 20 | 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 |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 34 | if (!channel) return |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 35 | try { |
| 36 | await channel.send(string) |
| 37 | } catch (err) { |
| 38 | console.error(err) |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |