ramirez/src/modules/greeting.js

36 lines
913 B
JavaScript
Raw Normal View History

2017-02-10 00:04:23 -05:00
const path = require('path');
const fs = require('fs');
const config = require('../config');
2017-02-10 00:04:23 -05:00
module.exports = bot => {
2017-02-10 00:04:23 -05:00
if (! config.enableGreeting) return;
const greetingGuilds = config.mainGuildId;
2017-02-10 00:04:23 -05:00
bot.on('guildMemberAdd', (guild, member) => {
if (! greetingGuilds.includes(guild.id)) return;
2017-02-10 00:04:23 -05:00
function sendGreeting(file) {
bot.getDMChannel(member.id).then(channel => {
if (! channel) return;
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 {
sendGreeting();
2017-02-10 00:04:23 -05:00
}
});
};