Skip to content

Release Day III #92

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
15 commits merged into from
Nov 16, 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
30 changes: 25 additions & 5 deletions bot/controllers/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ const nodemailer = require('nodemailer');
// Modified to fit style guide from this SO answer:
// https://stackoverflow.com/a/39774334
const generateCode = (n) => {
// Workaround method for Math.pow() and ** operator
const pow = (base, exp) => {
let result = 1;
for (let i = 0; i < exp; i += 1) {
result *= base;
}
return result;
};
const add = 1;
let max = 12 - add;
let min = 0;
if (n > max) {
return generateCode(max) + generateCode(n - max);
}
max = 10000000;
max = pow(10, n + add);
min = max / 10;
const number = Math.floor(Math.random() * (max - (min + 1))) + min;
return ('' + number).substring(add);
Expand Down Expand Up @@ -41,23 +49,35 @@ module.exports = () => {
if (validDomains.includes(emailDomain)) {
const codeLength = 6;
const code = generateCode(codeLength);
util.log('code', code, 3);
// TODO: Set `time` prop to 600000 (10min)
const collector = message.channel.createMessageCollector(
m => m.content.includes(code),
// 15000ms only for testing!!!
{ time: 150000 });
{ time: 600000 });
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) {
// no existing record found
models.Member.create({
discorduser: m.author.username,
discorduser: m.author.id,
email,
uuid: uuidv4(),
verified: 1,
}).then(util.log).catch(util.error);
});
// 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);
}
});
message.reply(verifyUser);
} else {
// existing record found
Expand Down Expand Up @@ -88,7 +108,7 @@ module.exports = () => {
from: 'discord.maxbot@gmail.com',
to: email,
subject: 'Armada Verification Code',
html: `<p>Verification Code: ${code}</p>`,
html: `<table><tr><td><p>Copy and paste this into Discord!</p></td></tr><tr><td><p>Verification Code: ${code}</p></td></tr></table>`,
};
// Call sendMail on sendVerifyCode
// Pass mailOptions & callback function
Expand Down
21 changes: 18 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Max Bot
## The Official Bot of the Full Sail Armada

Interested in learning how to use Max? See the [Usage documentation here](usage.md).

# Installation

### Prerequisites
Expand Down Expand Up @@ -39,7 +44,7 @@ module.exports = () => {

Obtain a [Discord App Bot Token](https://discordapp.com/developers/applications/me) from your registered app (or register a new one) to proceed or contact a Release Manager for Max's Dev Bot token.

Replace the ```{DiscordBotToken}``` within the ```.env``` file with the token provided to you.
Replace the ```{DiscordBotToken}``` within the ```max.config.js``` file with the token provided to you.

### Adding the Bot to a Server

Expand Down Expand Up @@ -125,12 +130,22 @@ of this particular output should be. Reference the **Debug Level Chart**
4. Highly Fine Grained Detailed and in-depth Output.


# Database
### how to connect using `SEQUEL PRO`
# Modules & integrations

## Database
### How to connect using Sequel Pro

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

## Node Container
Expand Down
60 changes: 60 additions & 0 deletions usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Using Max

As the official bot of the Full Sail Armada, Max offers simple but powerful automated user management tools that empower Armada members to verify membership eligibility and set roles for themselves within the server, freeing up admins, moderators, and officers for more important tasks.

## Commands

Each of the commands that Max offers can be invoked from inside a text channel by using an exclamation point followed by the command keyword (like `!command`). Individual commands are not case-sensitive, but some of the information needed for each command may be.

### !help

Example: `!help`

Displays all of Max's available commands.

### !verify

Example: `!verify <email_address>`

Verifies that the user has a valid Full Sail University email address and adds the user to the Discord server. This command also adds the user's username and FS email address to the Armada database so Armada officers can match users to real-life students.

### !roles

Example: `!roles`

Sends a DM to the user with a list of all available Armada roles.

### !addRole

Example: `!addRole <role_name>`

Adds the specified role to the user. Role names _are_ case-sensitive. Note that not all roles can be added this way—no promoting yourself to Fleet Officer, for example.

### !addRoles

Example: `!addRoles <role_name>,<role_name>,<role_name>`

Adds multiple specified roles to the user all at once. The same caveat as above applies.

### !removeRole

Example: `!removeRole <role_name>`

Removes a single specified role from the user.

### !addAllRoles

Example: `!addAllRoles`

Adds all available Armada roles to the user. Suitable for masochists and chat room junkies.

### !removeAllRoles

Example: `!removeAllRoles`

Removes all roles from the user. _Tabula rasa_, baby.


## Administrative commands

Max also includes a couple of special commands just for Officers and above for making announcements to multiple channels.