Skip to content

Verification cleanup #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 29, 2017
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
2 changes: 1 addition & 1 deletion bot/controllers/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = () => {
const util = require('apex-util');

const _run = (message) => {
const disallowedRoles = ['admin', 'armada officers', 'armada officer', 'moderator', 'privateers', 'tester', 'crew', 'fleet officer', '@everyone'];
const disallowedRoles = ['admin', 'armada officers', 'armada officer', 'moderator', 'privateers', 'privateer', 'tester', 'crew', 'fleet officer', '@everyone'];
const ctrls = [
{
cmd: '!roles',
Expand Down
35 changes: 14 additions & 21 deletions bot/controllers/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ module.exports = () => {
allowInDM: false,
resType: 'reply',
action: (message, ctrl, msg) => {
const targetVerifiedRoleName = 'Crew';
const validDomains = ['student.fullsail.edu', 'fullsail.edu', 'fullsail.com'];
const timeoutInMiliseconds = 600000;
const email = msg.parsed[1].toLowerCase();
const emailDomain = email.split('@').pop();
// We can set `codeLength` to whatever length we want the verif code to be.
Expand All @@ -53,14 +55,12 @@ module.exports = () => {
// TODO: Set `time` prop to 600000 (10min)
const collector = message.channel.createMessageCollector(
m => m.content.includes(code),
// 15000ms only for testing!!!
{ time: 600000 });
{ time: timeoutInMiliseconds });
collector.on('collect', (m) => {
const verifyUser = `Thanks, ${message.author.username}! I'll get to work adding you the servers right away!`;
const userAlredyOnSystem = `the user ${message.author.username} is already in our system!`;
const moderatorMsg = 'A moderator is needed to create the crew role.';
models.Member.findOne({ where: { email } }).then((data) => {
if (data === null) {
const verifyUser = 'Welcome aboard, Crewmate!';
const userAlredyOnSystem = 'This email has already been verified to a discord user.';
models.Member.findOne({ where: { email } }).then((matchedUserData) => {
if (matchedUserData === null) {
// no existing record found
models.Member.create({
discorduser: m.author.id,
Expand All @@ -69,15 +69,8 @@ module.exports = () => {
verified: 1,
});
// mapping guild roles to find the crew role id
const guild = message.guild.roles.map(channel => channel);
Object.keys(guild).forEach((el) => {
if (guild[el].name === 'crew') {
m.member.addRole(guild[el].id);
} else {
message.reply(moderatorMsg);
util.log('Moderator Needed', el, 3);
}
});
const targetRole = message.guild.roles.find('name', targetVerifiedRoleName);
message.member.addRole(targetRole).catch(util.log);
message.reply(verifyUser);
} else {
// existing record found
Expand All @@ -87,7 +80,7 @@ module.exports = () => {
util.log('Collected', m.content, 3);
});
collector.on('end', (collected) => {
const verificationTimeout = 'Uh-oh, it looks like you weren\'t able to get the right verification code back to me in time. I\'ve contacted the Armada admins so we can get this straightened out right away.';
const verificationTimeout = `!verify timeout. Clap ${collected.author.username} in irons! Let's see how well they dance on the plank!`;
util.log('Items', collected.size, 3);
if (collected.size === 0) {
// TODO: ping admin team on verification fail
Expand All @@ -105,15 +98,15 @@ module.exports = () => {
// Nodemailer email recipient & message
// TODO: Build email template
const mailOptions = {
from: 'max-bot@apextion.com',
from: process.env.EMAIL_USERNAME,
to: email,
subject: 'Armada Verification Code',
html: `<table><tr><td><p>Copy and paste this into Discord!</p></td></tr><tr><td><p>Verification Code: ${code}</p></td></tr></table>`,
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. Its not you, it\'s me. Please contact a moderator and let them know I have failed.';
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);
Expand All @@ -123,7 +116,7 @@ module.exports = () => {
});

util.log('Code', code, 3);
return `Hi there, ${message.author.username}, it looks like you're trying to verify your email address!\n\nBeep boop... generating verification code... beep boop\n\nI've emailed a ${codeLength}-digit number to _${email}_. Respond back with that number within 10 minutes and I'll automagically verify your email address so you can represent the glorious Full Sail Armada!`;
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!`;
} else {
return `Sorry, ${message.author.username}, I can only verify Full Sail University email addresses.`;
}
Expand Down
Empty file added db/config/.gitkeep
Empty file.
5 changes: 3 additions & 2 deletions db/first_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ gulp pm2
echo "Migrating"
sequelize db:migrate --config db/config/config.json --migrations-path db/migrations/
echo "Seeding"
sequelize db:seed:undo:all --config db/config/config.json --migrations-path db/migrations/ --seeders-path db/seeders
sequelize db:seed:all --config db/config/config.json --migrations-path db/migrations/ --seeders-path db/seeders
# TODO: Seed based upon Environment
# sequelize db:seed:undo:all --config db/config/config.json --migrations-path db/migrations/ --seeders-path db/seeders
# sequelize db:seed:all --config db/config/config.json --migrations-path db/migrations/ --seeders-path db/seeders
echo "Running PM2"
pm2 start max.config.js --no-daemon
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ gulp.task('pm2', () => {
env: {
TOKEN: process.env.DISCORD_BOT_TOKEN,
DEBUG_MODE: '3',
EMAIL_USERNAME: process.env.EMAIL_USERNAME,
EMAIL_PASS: process.env.EMAIL_PASS,
NODE_ENV: process.env.NODE_ENV,
},
}],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"gulp": "^3.9.1",
"mocha": "^3.5.0",
"mocha-eslint": "^4.1.0",
"nodemailer": "^4.3.1",
"mysql2": "^1.4.2",
"nodemailer": "^4.4.0",
"sequelize": "^4.22.5",
"uuid": "^3.1.0"
}
Expand Down
17 changes: 10 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ BOT_PORT_HOST=80
BOT_PORT_GUEST=3000
BOT_PORT_HOST=80
BOT_PORT_GUEST=3000

EMAIL_USERNAME=xxx
EMAIL_PASS=xxx
```

> Update ```DiscordBotToken``` with the token you receive from the next step.
Expand All @@ -60,6 +61,14 @@ As an authorized user of the bot you will need to add it to a server.

> [Source](https://stackoverflow.com/questions/37689289/joining-a-server-with-the-discord-python-api)

### Configure Email Functionality
Max uses [Nodemailer](https://nodemailer.com/about/) to send verification emails to users joining the Armada server. to work proper locally please follow these steps to create a new gmail account to locally test with:

1. Create a new gmail.com account
2. Once logged in with this account enable [less secure application access](https://myaccount.google.com/u/1/lesssecureapps?pageId=none&pli=1).
3. fill in the ```EMAIL_USERNAME``` & ```EMAIL_PASS``` values on the ```.env``` file with this new gmail account's info.


# Running the Bot

## Local
Expand Down Expand Up @@ -141,12 +150,6 @@ You can find more information about the config file `db/config/config.json`

![](https://preview.ibb.co/d07YOG/Screen_Shot_2017_11_10_at_2_49_46_PM.png)

## Nodemailer
Max uses [Nodemailer](https://nodemailer.com/about/) to send verification emails to users joining the Armada server. Install Nodemailer with

```
npm install nodemailer --save
```

# Container Information

Expand Down