Skip to content

Commit

Permalink
Bugfix - Closes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
MeLlamoPablo committed Jan 4, 2017
1 parent 8f0913e commit 2e74881
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 11 additions & 1 deletion lib/commands/admin/remove-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ module.exports = new Clapp.Command({
let eventName = event.name;
let deleteSummaryPromise = context.summaryHandler.deleteSummary(event);
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) {
context.dotaHandler.closeLobby(true).then(fulfill).catch(reject);
} else {
fulfill();
}
});

Promise.all([deleteSummaryPromise, deleteEventPromise]).then(() => {
Promise.all(
[deleteSummaryPromise, deleteEventPromise, closeLobbyPromise]
).then(() => {
fulfill("The event `" + eventName+ "` was successfully deleted.");
}).catch(err => {
console.error(err);
Expand Down
13 changes: 10 additions & 3 deletions lib/modules/dotahandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,17 @@ class DotaHandler {
});
}

closeLobby() {
/**
* Closes a lobby. This makes the current lobby be null, makes the bot leave the lobby, and
* executes ScheduledEvent.setLobbyEnded();
* @param {boolean} force Force close the lobby. If true, it will be closed immediately. If
* false, the bot will wait 30 seconds, just in case.
* @return {Promise}
*/
closeLobby(force = false) {
return new Promise((fulfill, reject) => {
// Wait a bit before leaving the lobby, just in case.
setTimeout(() => {
this.sendMessageToLobby("The lobby was closed. See you!");
console.log("[DOTA] Closed lobby " + this.currentLobbyName);

this.currentLobbyName = null;
Expand All @@ -284,7 +291,7 @@ class DotaHandler {
this.enoughPeople = false;
this.client.leavePracticeLobby();
this.currentLobbyEvent.setLobbyEnded().then(fulfill).catch(reject);
}, 30000);
}, force ? 0 : 30000);
});
}

Expand Down

0 comments on commit 2e74881

Please sign in to comment.