Skip to content

Commit 0ca0922

Browse files
Merge pull request #95 from reactivepixel/verificationCleanup
Verification cleanup
2 parents b48a6cd + a51f7bd commit 0ca0922

File tree

7 files changed

+31
-32
lines changed

7 files changed

+31
-32
lines changed

bot/controllers/roles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = () => {
22
const util = require('apex-util');
33

44
const _run = (message) => {
5-
const disallowedRoles = ['admin', 'armada officers', 'armada officer', 'moderator', 'privateers', 'tester', 'crew', 'fleet officer', '@everyone'];
5+
const disallowedRoles = ['admin', 'armada officers', 'armada officer', 'moderator', 'privateers', 'privateer', 'tester', 'crew', 'fleet officer', '@everyone'];
66
const ctrls = [
77
{
88
cmd: '!roles',

bot/controllers/verify.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ module.exports = () => {
4141
allowInDM: false,
4242
resType: 'reply',
4343
action: (message, ctrl, msg) => {
44+
const targetVerifiedRoleName = 'Crew';
4445
const validDomains = ['student.fullsail.edu', 'fullsail.edu', 'fullsail.com'];
46+
const timeoutInMiliseconds = 600000;
4547
const email = msg.parsed[1].toLowerCase();
4648
const emailDomain = email.split('@').pop();
4749
// We can set `codeLength` to whatever length we want the verif code to be.
@@ -53,14 +55,12 @@ module.exports = () => {
5355
// TODO: Set `time` prop to 600000 (10min)
5456
const collector = message.channel.createMessageCollector(
5557
m => m.content.includes(code),
56-
// 15000ms only for testing!!!
57-
{ time: 600000 });
58+
{ time: timeoutInMiliseconds });
5859
collector.on('collect', (m) => {
59-
const verifyUser = `Thanks, ${message.author.username}! I'll get to work adding you the servers right away!`;
60-
const userAlredyOnSystem = `the user ${message.author.username} is already in our system!`;
61-
const moderatorMsg = 'A moderator is needed to create the crew role.';
62-
models.Member.findOne({ where: { email } }).then((data) => {
63-
if (data === null) {
60+
const verifyUser = 'Welcome aboard, Crewmate!';
61+
const userAlredyOnSystem = 'This email has already been verified to a discord user.';
62+
models.Member.findOne({ where: { email } }).then((matchedUserData) => {
63+
if (matchedUserData === null) {
6464
// no existing record found
6565
models.Member.create({
6666
discorduser: m.author.id,
@@ -69,15 +69,8 @@ module.exports = () => {
6969
verified: 1,
7070
});
7171
// mapping guild roles to find the crew role id
72-
const guild = message.guild.roles.map(channel => channel);
73-
Object.keys(guild).forEach((el) => {
74-
if (guild[el].name === 'crew') {
75-
m.member.addRole(guild[el].id);
76-
} else {
77-
message.reply(moderatorMsg);
78-
util.log('Moderator Needed', el, 3);
79-
}
80-
});
72+
const targetRole = message.guild.roles.find('name', targetVerifiedRoleName);
73+
message.member.addRole(targetRole).catch(util.log);
8174
message.reply(verifyUser);
8275
} else {
8376
// existing record found
@@ -87,7 +80,7 @@ module.exports = () => {
8780
util.log('Collected', m.content, 3);
8881
});
8982
collector.on('end', (collected) => {
90-
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.';
83+
const verificationTimeout = `!verify timeout. Clap ${collected.author.username} in irons! Let's see how well they dance on the plank!`;
9184
util.log('Items', collected.size, 3);
9285
if (collected.size === 0) {
9386
// TODO: ping admin team on verification fail
@@ -105,15 +98,15 @@ module.exports = () => {
10598
// Nodemailer email recipient & message
10699
// TODO: Build email template
107100
const mailOptions = {
108-
from: 'max-bot@apextion.com',
101+
from: process.env.EMAIL_USERNAME,
109102
to: email,
110103
subject: 'Armada Verification Code',
111-
html: `<table><tr><td><p>Copy and paste this into Discord!</p></td></tr><tr><td><p>Verification Code: ${code}</p></td></tr></table>`,
104+
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>`,
112105
};
113106
// Call sendMail on sendVerifyCode
114107
// Pass mailOptions & callback function
115108
sendVerifyCode.sendMail(mailOptions, (err, info) => {
116-
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.';
109+
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.';
117110
if (err) {
118111
message.reply(errorMsg);
119112
util.log('Email not sent', err, 3);
@@ -123,7 +116,7 @@ module.exports = () => {
123116
});
124117

125118
util.log('Code', code, 3);
126-
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!`;
119+
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!`;
127120
} else {
128121
return `Sorry, ${message.author.username}, I can only verify Full Sail University email addresses.`;
129122
}

db/config/.gitkeep

Whitespace-only changes.

db/first_run.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ gulp pm2
77
echo "Migrating"
88
sequelize db:migrate --config db/config/config.json --migrations-path db/migrations/
99
echo "Seeding"
10-
sequelize db:seed:undo:all --config db/config/config.json --migrations-path db/migrations/ --seeders-path db/seeders
11-
sequelize db:seed:all --config db/config/config.json --migrations-path db/migrations/ --seeders-path db/seeders
10+
# TODO: Seed based upon Environment
11+
# sequelize db:seed:undo:all --config db/config/config.json --migrations-path db/migrations/ --seeders-path db/seeders
12+
# sequelize db:seed:all --config db/config/config.json --migrations-path db/migrations/ --seeders-path db/seeders
1213
echo "Running PM2"
1314
pm2 start max.config.js --no-daemon

gulpfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ gulp.task('pm2', () => {
2424
env: {
2525
TOKEN: process.env.DISCORD_BOT_TOKEN,
2626
DEBUG_MODE: '3',
27+
EMAIL_USERNAME: process.env.EMAIL_USERNAME,
28+
EMAIL_PASS: process.env.EMAIL_PASS,
2729
NODE_ENV: process.env.NODE_ENV,
2830
},
2931
}],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"gulp": "^3.9.1",
2828
"mocha": "^3.5.0",
2929
"mocha-eslint": "^4.1.0",
30-
"nodemailer": "^4.3.1",
3130
"mysql2": "^1.4.2",
31+
"nodemailer": "^4.4.0",
3232
"sequelize": "^4.22.5",
3333
"uuid": "^3.1.0"
3434
}

readme.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ BOT_PORT_HOST=80
3434
BOT_PORT_GUEST=3000
3535
BOT_PORT_HOST=80
3636
BOT_PORT_GUEST=3000
37-
37+
EMAIL_USERNAME=xxx
38+
EMAIL_PASS=xxx
3839
```
3940

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

6162
> [Source](https://stackoverflow.com/questions/37689289/joining-a-server-with-the-discord-python-api)
6263
64+
### Configure Email Functionality
65+
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:
66+
67+
1. Create a new gmail.com account
68+
2. Once logged in with this account enable [less secure application access](https://myaccount.google.com/u/1/lesssecureapps?pageId=none&pli=1).
69+
3. fill in the ```EMAIL_USERNAME``` & ```EMAIL_PASS``` values on the ```.env``` file with this new gmail account's info.
70+
71+
6372
# Running the Bot
6473

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

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

144-
## Nodemailer
145-
Max uses [Nodemailer](https://nodemailer.com/about/) to send verification emails to users joining the Armada server. Install Nodemailer with
146-
147-
```
148-
npm install nodemailer --save
149-
```
150153

151154
# Container Information
152155

0 commit comments

Comments
 (0)