Skip to content

Dynamic Role Restrictions + No Docker #195

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 6 commits into from
Nov 13, 2019
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: 0 additions & 37 deletions .circleci/config.yml

This file was deleted.

1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion bot/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ client.on('message', (message) => {
util.log('Command message received', message.content, 0);

// Build basic help string
let helpString = 'v1.6.0 Discovered Commands:\n\n\t**<> - Required Item\t\t[] - Optional Item**';
let helpString = 'v1.7.0 Discovered Commands:\n\n\t**<> - Required Item\t\t[] - Optional Item**';

// Process message against every controller
Object.keys(controllers).forEach((key) => {
Expand Down
47 changes: 25 additions & 22 deletions bot/controllers/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,21 @@ class RoleController extends BaseController {

// User roles commands cannot change
this.disallowedRoles = [
'Admin', 'Armada Officers', 'Armada Officer', 'Fleet Officer',
'Moderator', 'Tester', 'Team Captain', 'Full Sail Staff', 'Privateers',
'Team Liaison', 'Armada Athlete', '@everyone', 'Crew',
'Overwatch_V', 'Overwatch_JV',
'CS:GO_V', 'CS:GO_JV',
'Smite_V', 'Smite_JV',
'Fortnite_V', 'Fortnite_JV',
'Madden_V', 'Madden_JV',
'LoL_V', 'LoL_JV',
'SuperSmashBros_V', 'SuperSmashBros_JV',
'HeroesOfTheStorm_V', 'HeroesOfTheStorm_JV',
'RocketLeague_V', 'RocketLeague_JV',
'DragonBall_V', 'DragonBall_JV',
'Hearthstone_V', 'Hearthstone_JV',
'Admin', '@everyone',
];
}

// Lists all roles
rolesAction() {
const { message, disallowedRoles } = this;
const roles = [];


const dividerRoleName = 'MAX_SELF_ASSIGN_ROLE';
const maxRole = message.guild.roles.find(role => role.name === dividerRoleName);
message.guild.roles.map((role) => {
if (!disallowedRoles.includes(role.name)) {
if(role.position < maxRole.position && !disallowedRoles.includes(role.name))
return roles.push(role.name);
}
return role.name;
});
return 'List of all Armada Roles: \n\n' + roles.join('\n');
Expand All @@ -92,11 +82,14 @@ class RoleController extends BaseController {
// Adds a role to the user
addRoleAction() {
const { message, disallowedRoles } = this;

const dividerRoleName = 'MAX_SELF_ASSIGN_ROLE';
const maxRole = message.guild.roles.find(role => role.name === dividerRoleName);
const targetRole = message.guild.roles.find('name', message.parsed[1]);
if (targetRole === null) {
util.log('No role matched', message.parsed[1], 2);
return '"' + message.parsed[1] + '" is not a known role. Try `!roles` to get a list of all Roles (They are case-sensitive)';
} else if (disallowedRoles.includes(targetRole.name)) {
} else if (disallowedRoles.includes(targetRole.name) || targetRole.position >= maxRole.position) {
util.log('User Tried to add a restricted/dissalowed role', targetRole.name, 2);
return 'You are not worthy of the role ' + message.parsed[1] + '.';
} else {
Expand All @@ -109,15 +102,18 @@ class RoleController extends BaseController {
// Adds multiple roles to the user
addRolesAction() {
const { message, disallowedRoles } = this;

const dividerRoleName = 'MAX_SELF_ASSIGN_ROLE';
const maxRole = message.guild.roles.find(role => role.name === dividerRoleName);
const roles = message.parsed[1].split(',');
util.log('Multiple Roles Parsing', roles, 4);

roles.map((role) => {
if (!disallowedRoles.includes(role)) {
const targetRole = message.guild.roles.find('name', role);
util.log('Asking API for Role', targetRole, 4);

if (targetRole === null) {
if (targetRole === null || targetRole.position >= maxRole.position) {
return '"' + role + '" is not a known role. Try `!roles` to get a list of all Roles (They are case-sensitive)';
}
return message.member.addRole(targetRole).catch(util.log);
Expand All @@ -131,12 +127,14 @@ class RoleController extends BaseController {
// Removes role from user
removeRoleAction() {
const { message, disallowedRoles } = this;
const dividerRoleName = 'MAX_SELF_ASSIGN_ROLE';
const maxRole = message.guild.roles.find(role => role.name === dividerRoleName);
const targetRole = message.guild.roles.find('name', message.parsed[1]);
if (targetRole === null) {
util.log('No role matched', message.parsed[1], 2);
return '"' + message.parsed[1] + '" is not a known role. Try `!roles` to get a list of all Roles (They are case-sensitive)';
}
if (disallowedRoles.includes(targetRole.name)) {
if (disallowedRoles.includes(targetRole.name) || targetRole.position >= maxRole.position) {
util.log('User Tried to add a restricted/dissalowed role', targetRole.name, 2);
return 'You have not the power or the will to control this power.';
}
Expand All @@ -149,8 +147,11 @@ class RoleController extends BaseController {
// Adds all roles to user
addAllRolesAction() {
const { message, disallowedRoles } = this;
const dividerRoleName = 'MAX_SELF_ASSIGN_ROLE';
const maxRole = message.guild.roles.find(role => role.name === dividerRoleName);

message.guild.roles.map((role) => {
if (!disallowedRoles.includes(role.name)) {
if (!disallowedRoles.includes(role.name) && role.position < maxRole.position) {
return message.member.addRole(role).catch(util.log);
}
return role.name;
Expand All @@ -162,8 +163,10 @@ class RoleController extends BaseController {
// Removes all roles from user
removeAllRolesAction() {
const { message, disallowedRoles } = this;
const dividerRoleName = 'MAX_SELF_ASSIGN_ROLE';
const maxRole = message.guild.roles.find(role => role.name === dividerRoleName);
message.guild.roles.map((role) => {
if (!disallowedRoles.includes(role.name)) {
if (!disallowedRoles.includes(role.name) && role.position < maxRole.position) {
return message.member.removeRole(role).catch(util.log);
}
return role.name;
Expand Down
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [v1.7.0](https://github.com/reactivepixel/Max-Bot/releases/tag/v1.7.0)

* Roles are now dynamically blocked by the role `MAX_SELF_ASSIGN_ROLE`. Only roles below this are valid for self assignment.

## [v1.6.0](https://github.com/reactivepixel/Max-Bot/releases/tag/v1.6.0)

Max has been moved from a VPS on Digital Ocean running on Docker and a Docker Maria DB Container onto Heroku using a JawsMariaDB resource. Additional enhancements have been made to the fs.armada.bot@gmail.com gmail account to enable 2-factor Auth and a bypass key for Max has been generated.

## [v1.2.2](https://github.com/reactivepixel/Max-Bot/releases/tag/v1.2.2)

Initial feedback from Crewmates prompted some quality of life features to be released early.
Expand Down
14 changes: 0 additions & 14 deletions db/first_run.sh

This file was deleted.

9 changes: 0 additions & 9 deletions db/test_data.js

This file was deleted.

26 changes: 0 additions & 26 deletions docker-compose.yml

This file was deleted.

34 changes: 0 additions & 34 deletions gulpfile.js

This file was deleted.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "max",
"version": "1.6.0",
"version": "1.7.0",
"description": "",
"main": "bot/client.js",
"engines": {
"node": "v10.16.3",
"npm": "6.9.0"
},
"scripts": {
"start": "node bot/client.js",
"test": "mocha"
"start": "node bot/client.js"
},
"keywords": [],
"author": "Chapman - Chapman@Apextion.com",
Expand All @@ -18,7 +17,7 @@
"discord.js": "^11.5.1",
"mysql2": "^1.6.5",
"nodemailer": "^6.3.1",
"sequelize": "^5.15.2",
"sequelize": "^5.21.2",
"uuid": "^3.3.3"
}
}
Loading