Skip to content

Commit

Permalink
Enforce inhouse event limit to be >= 10
Browse files Browse the repository at this point in the history
Also fixes a bug where events without inhouses couldn't be removed.
  • Loading branch information
MeLlamoPablo committed Jan 4, 2017
1 parent 2e74881 commit 47b9050
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
5 changes: 4 additions & 1 deletion lib/commands/admin/remove-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module.exports = new Clapp.Command({
let deleteEventPromise = event.deleteEvent();
let closeLobbyPromise = new Promise((fulfill, reject) => {
// If the event has an active lobby, close it
if (context.dotaHandler.currentLobbyEvent.id === event.id) {
if (
context.dotaHandler.currentLobbyEvent &&
context.dotaHandler.currentLobbyEvent.id === event.id
) {
context.dotaHandler.closeLobby(true).then(fulfill).catch(reject);
} else {
fulfill();
Expand Down
62 changes: 35 additions & 27 deletions lib/commands/general/add-inhouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,45 @@ module.exports = new Clapp.Command({
return new Promise((fulfill, reject) => {
db.events.get(argv.args.id).then(event => {
if (event !== null) {
let inhouseProps = {};
if (event.limit >= 10) {
let inhouseProps = {};

inhouseProps.gameMode = argv.flags.gamemode.toLowerCase().replace(" ", "");
inhouseProps.server = argv.flags.server.toLowerCase().replace(" ", "");
inhouseProps.autoBalance = !argv.flags["no-balance"];
inhouseProps.gameMode = argv.flags.gamemode.toLowerCase().replace(" ", "");
inhouseProps.server = argv.flags.server.toLowerCase().replace(" ", "");
inhouseProps.autoBalance = !argv.flags["no-balance"];

db.events.addInhouse(event, inhouseProps).then(() => {
// Kick every user that hasn't linked their Steam from the event
db.confirms.getByEvent(event).then(confirms => {
let people = confirms.map(e => { return e.user });
db.events.addInhouse(event, inhouseProps).then(() => {
// Kick every user that hasn't linked their Steam from the event
db.confirms.getByEvent(event).then(confirms => {
let people = confirms.map(e => {
return e.user
});

for (let i = 0; i < people.length; i++) {
db.users.getByDiscord(people[i]).then(user => {
if (user === null || user.steam_id === null) {
db.confirms.deleteByUserAndEvent(
people[i], event.id
).then(() => {
context.summaryHandler.updateSummary(event)
.catch(reject);
}).catch(reject);
}
}).catch(reject);
}
}).catch(reject);
context.summaryHandler.updateSummary(event).catch(reject);
for (let i = 0; i < people.length; i++) {
db.users.getByDiscord(people[i]).then(user => {
if (user === null || user.steam_id === null) {
db.confirms.deleteByUserAndEvent(
people[i], event.id
).then(() => {
context.summaryHandler.updateSummary(event)
.catch(reject);
}).catch(reject);
}
}).catch(reject);
}
}).catch(reject);
context.summaryHandler.updateSummary(event).catch(reject);

fulfill("The inhouse has been added to the event `#"
+ argv.args.id + "`\n" +
"If there were any people who confirmed their attendance, but didn't" +
" have their Steam account linked, they have been removed.");
}).catch(reject);
fulfill("The inhouse has been added to the event `#"
+ argv.args.id + "`\n" +
"If there were any people who confirmed their attendance, but " +
"didn't have their Steam account linked, they have been removed.");
}).catch(reject);
} else {
fulfill("The event's player limit must be 10 or greater in order to add" +
" an inhouse."); // TODO once edit command gets implemented, modify
// this to tell the user to edit the event.
}
} else {
fulfill("The event `#" + argv.args.id + "` doesn't exist.");
}
Expand Down
1 change: 1 addition & 0 deletions lib/structures/ScheduledEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const db = require('../modules/dbhandler/core.js'); /* Please see the file d
* @property {number} id The event id
* @property {string} name The event name
* @property {Moment} time The event time
* @property {number} limit The limit of people who can attend the event
*/
class ScheduledEvent {

Expand Down

0 comments on commit 47b9050

Please sign in to comment.