2017-02-10 00:04:23 -05:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
2018-02-11 14:54:30 -05:00
|
|
|
const config = require('../config');
|
2017-02-10 00:04:23 -05:00
|
|
|
|
2018-02-11 14:54:30 -05:00
|
|
|
module.exports = bot => {
|
2017-02-10 00:04:23 -05:00
|
|
|
if (! config.enableGreeting) return;
|
|
|
|
|
2018-02-11 14:54:30 -05:00
|
|
|
const greetingGuildId = config.mainGuildId || config.greetingGuildId;
|
|
|
|
|
2017-02-10 00:04:23 -05:00
|
|
|
bot.on('guildMemberAdd', (guild, member) => {
|
2017-02-14 17:57:41 -05:00
|
|
|
if (guild.id !== greetingGuildId) return;
|
2017-02-10 00:04:23 -05:00
|
|
|
|
|
|
|
function sendGreeting(file) {
|
|
|
|
bot.getDMChannel(member.id).then(channel => {
|
|
|
|
if (! channel) return;
|
2018-04-21 07:31:58 -04:00
|
|
|
|
|
|
|
channel.createMessage(config.greetingMessage || '', file)
|
|
|
|
.catch(e => {
|
|
|
|
if (e.code === 50007) return;
|
|
|
|
throw e;
|
|
|
|
});
|
2017-02-10 00:04:23 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.greetingAttachment) {
|
|
|
|
const filename = path.basename(config.greetingAttachment);
|
|
|
|
fs.readFile(config.greetingAttachment, (err, data) => {
|
|
|
|
const file = {file: data, name: filename};
|
|
|
|
sendGreeting(file);
|
|
|
|
});
|
|
|
|
} else {
|
2018-02-11 14:54:30 -05:00
|
|
|
sendGreeting();
|
2017-02-10 00:04:23 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|