Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions bot/botUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Member } = require('../db/models');
const nodemailer = require('nodemailer');
const util = require('apex-util');

exports.generateCode = (n) => {
Expand Down Expand Up @@ -80,4 +81,40 @@ exports.welcomeCommand = async (member) => {
await member.send(welcomeString);
};

// Nodemailer email function
// Set up Nodemailer to send emails through gmail
exports.sendEmail = async (message, toEmailAdd, emailSubject,
emailBody, emailSendType, callback) => {
const sendInvite = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASS,
},
});
// Nodemailer email recipient & message
// the email template
const mailOptions = {
from: process.env.EMAIL_USERNAME,
to: toEmailAdd,
subject: emailSubject,
html: emailBody,
};
// Call sendMail on sendInvite
// Pass mailOptions & callback function
sendInvite.sendMail(mailOptions, (err, info) => {
let messageTypeString = 'send an invite.';
emailSendType === 'verify' ? messageTypeString = 'verify' : '';
const errorMsg = `Oops, looks like the email can not be sent. It's not you, it's me. Please reach out to a moderator to help you ${messageTypeString}.`;
if (err) {
message.reply(errorMsg);
util.log('Email not sent', err, 3);
callback(false);
} else {
util.log('Email details', info, 3);
callback(true);
}
});
return null;
};
exports.validDomains = ['student.fullsail.edu', 'fullsail.edu', 'fullsail.com'];
38 changes: 7 additions & 31 deletions bot/controllers/invite.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const BaseController = require('../baseController.js');
const Command = require('../baseCommand.js');
const nodemailer = require('nodemailer');
const util = require('apex-util');
const { getUserPointsandUpdate, validDomains } = require('../botUtils');
const { getUserPointsandUpdate, sendEmail, validDomains } = require('../botUtils');

class inviteController extends BaseController {
constructor(message) {
Expand Down Expand Up @@ -42,43 +41,20 @@ class inviteController extends BaseController {
}

if (validDomains.includes(emailDomain)) {
// Set up Nodemailer to send emails through gmail
const sendInvite = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASS,
},
});
// Nodemailer email recipient & message
// the email template
const mailOptions = {
from: process.env.EMAIL_USERNAME,
to: email,
subject: 'Armada Invite',
html: `<table><tr><td><p>Please follow this link to be included in the Discord server <a href=${invite.url}>link</a> Thank you for your interest for wanting to be in the Discord server. Enjoy!</p></td></tr></table>`,
};
// Call sendMail on sendInvite
// Pass mailOptions & callback function
sendInvite.sendMail(mailOptions, (err, info) => {
const errorMsg = 'Oops, looks like the email can not be sent. It\'s not you, it\'s me. Please reach out to a moderator to help you send a invite.';
if (err) {
message.reply(errorMsg);
util.log('Email not sent', err, 3);
message.author.send('Invite not sent.');
} else {
util.log('Email details', info, 3);
// for every invite sent the user will receive 1 point
const emailType = 'invite';
const emailSubject = 'Armada Invite';
const emailBodyString = `<table><tr><td><p>Please follow this link to be included in the discord <a href=${invite.url}>link</a> Thank you for your interest for wanting to be in the Discord enjoy.</p></td></tr></table>`;
sendEmail(message, email, emailSubject, emailBodyString, emailType, (sendStatus) => {
if (sendStatus) {
getUserPointsandUpdate(message.author.id, invitePointsAwarded);
// notify the user that the message has been sent
message.author.send(`You've received ${invitePointsAwarded} point(s) for sending this invite.`);
}
});
} else {
message.author.send('Sorry the invite could not be sent please contact a admin for assistance.');
}
});
return `${message.author}, Invite Status: `;
return `${message.author}, invite status:`;
}
}

Expand Down
37 changes: 6 additions & 31 deletions bot/controllers/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ const Command = require('../baseCommand.js');
const util = require('apex-util');
const models = require('../../db/models');
const uuidv4 = require('uuid/v4');
const nodemailer = require('nodemailer');
const { generateCode, validDomains } = require('../botUtils.js');

const { generateCode, validDomains, sendEmail } = require('../botUtils.js');

class VerifyController extends BaseController {
constructor(message) {
Expand Down Expand Up @@ -58,7 +56,7 @@ class VerifyController extends BaseController {
email,
uuid: uuidv4(),
verified: 1,
points: 0,
points: 1,
});
// mapping guild roles to find the crew role id
const targetRole = message.guild.roles.find('name', targetVerifiedRoleName);
Expand All @@ -79,33 +77,10 @@ class VerifyController extends BaseController {
message.reply(verificationTimeout);
}
});
// Set up Nodemailer to send emails through gmail
const sendVerifyCode = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASS,
},
});
// Nodemailer email recipient & message
// TODO: Build email template
const mailOptions = {
from: process.env.EMAIL_USERNAME,
to: email,
subject: 'Armada Verification Code',
html: `<table><tr><td><p>Enter the code below into Discord, in the same channel on the Armada Server. Verification will timeout after ${(timeoutInMiliseconds / 1000) / 60} minutes from first entering the !verify command.</p></td></tr><tr><td><h2>Verification Code: ${code}</h2></td></tr></table>`,
};
// Call sendMail on sendVerifyCode
// Pass mailOptions & callback function
sendVerifyCode.sendMail(mailOptions, (err, info) => {
const errorMsg = 'Oops, looks like the email can not be sent. It\'s not you, it\'s me. Please reach out to a moderator to help you verify.';
if (err) {
message.reply(errorMsg);
util.log('Email not sent', err, 3);
} else {
util.log('Email details', info, 3);
}
});
const emailType = 'verify';
const emailSubject = 'Armada Verification Code';
const emailBodyString = `<table><tr><td><p>Enter the code below into Discord, in the same channel on the Armada Server. Verification will timeout after ${(timeoutInMiliseconds / 1000) / 60} minutes from first entering the !verify command.</p></td></tr><tr><td><h2>Verification Code: ${code}</h2></td></tr></table>`;
sendEmail(message, email, emailSubject, emailBodyString, emailType, sendStatus => sendStatus);

util.log('Code', code, 3);
return `...What's the passcode? \n\n *eyes you suspicously*\n\n I just sent it to your email, just respond back to this channel within ${(timeoutInMiliseconds / 1000) / 60} minutes, with the code, and I won't treat you like a scurvy cur!`;
Expand Down