Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MeLlamoPablo committed Jan 17, 2017
1 parent 10ebaff commit 47f41fe
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion lib/commands/admin/remove-event.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict"; // TODO TEST
"use strict";

const Clapp = require('../../modules/clapp-discord/index');
const db = require('../../modules/dbhandler/index').events;
Expand Down
3 changes: 1 addition & 2 deletions lib/commands/general/add-inhouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ module.exports = new Clapp.Command({
}).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.
" an inhouse.");
}
} else {
fulfill("The event `#" + argv.args.id + "` doesn't exist.");
Expand Down
11 changes: 9 additions & 2 deletions lib/commands/general/confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ module.exports = new Clapp.Command({
// Don't let people confirm yes if the event is full, but do let
// people confirm no even if the event is full.
if (
(argv.args.attendance === "yes" && attendanceConfirms.length < event.limit)
(
argv.args.attendance === "yes" &&
attendanceConfirms.length < event.limit
)
||
argv.args.attendance === "no"
) {
Expand All @@ -58,7 +61,11 @@ module.exports = new Clapp.Command({
.then(() => event.getLobbyStatus())
.then(status => {
if (status === ELobbyStatus.CREATED) {
context.dotaHandler.invite(context.msg.author.id)
db.events.getLobbyBotId(event)
.then(botID =>
context.dotaHandler.invite(
botID, context.msg.author.id
))
.catch(reject);
}
})
Expand Down
1 change: 1 addition & 0 deletions lib/commands/general/quick-inhouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = new Clapp.Command({
let inhouseProps = {
gameMode: "captainsmode",
server: cfg.dota.defaultServer.toLowerCase().replace(" ", ""),
cmPick: "random",
autoBalance: true
};

Expand Down
30 changes: 17 additions & 13 deletions lib/commands/general/resend-invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,29 @@ module.exports = new Clapp.Command({
db.get(argv.args.id).then(event => {
if (event !== null) {
event.getConfirms().then(people => {
let confirmed = false;
let confirms = people.confirmed.map(e => e.user); // Array with Discord IDs.

for (let i = 0; i < people.confirmed.length; i++) {
let discordID = people.confirmed[i];
if (confirms.indexOf(context.msg.author.id) !== -1) {
db.getLobbyBotId(event).then(botID => {
if (botID === null) {
fulfill("Error: the specified event doesn't have an inhouse " +
"associated or the lobby hasn't been created yet.");
} else {
if (context.dotaHandler.isBotInLobby(botID)) {
context.dotaHandler.invite(botID, context.msg.author.id);
fulfill("The invite has been resent. " +
"Accept it inside Dota 2.");
} else {
fulfill("Error: the bot is not yet in a lobby. Please " +
"wait for the lobby to be created first.");
}
}

if (context.msg.author.id === discordID) {
confirmed = true;
}
}

if (confirmed) { // TODO handle if not in lobby
db.getLobbyBotId(event).then(botID => context.dotaHandler.invite(
botID, context.msg.author.id
)).then(() => {
fulfill("The invite has been resent. Accept it inside Dota 2.");
}).catch(reject);
} else {
fulfill("Error: you haven't confirmed attendance to the event `#" +
context.dotaHandler.currentLobbyEvent.id + "`.\n" +
event.id + "`.\n" +
"You need to do so before requesting to be invited to the lobby");
}
}).catch(reject);
Expand Down
5 changes: 1 addition & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,4 @@ Promise.all(startupPromises).then(values => {
}).catch(err => {
console.error(err);
process.exit(1);
});

// TODO bug - create events creates two summaries sometimes
// TODO bug - not autoinivited on confirming a quick inhouse
});
2 changes: 1 addition & 1 deletion lib/modules/dbhandler/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const confirms = {
* @returns {Promise<confirm[]>} Resolves on success with the table rows, or with null if no
* confirms are found, or rejects with the error.
*
* @typedef {Object} confirm
* @typedef {Object} userConfirm
* @property {number} id
* @property {number} event The event id
* @property {string} user The user Discord's snowflake id. Should not be converted to
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/dotahandler/DotaClientX.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class DotaClientX extends Dota2.Dota2Client {
let pendingInvites = [];

for (let i = 0; i < people.confirmed.length; i++) {
let discordID = people.confirmed[i];
let discordID = people.confirmed[i].user;

pendingInvites.push(this.invite(discordID));
}
Expand Down
22 changes: 11 additions & 11 deletions lib/modules/summaryhandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class SummaryHandler {
let inhouseProps = values[1];
let lobbyStatus = values[2];

console.log(inhouseProps);

let summary = "";
let status = event.getStatus();

Expand Down Expand Up @@ -169,8 +167,6 @@ class SummaryHandler {

inhouseProps.autoBalance = inhouseProps.autoBalance ? "Enabled" : "Disabled";

console.log(inhouseProps);

switch (status) {
case "pending":
summary += "That's " + event.time.fromNow() + ".\n\n";
Expand Down Expand Up @@ -295,15 +291,19 @@ class SummaryHandler {
let summary = values[1];

message.edit(summary).then(msg => {
if (!msg.pinned) {
msg.pin().then(() => {
fulfill(msg.id);
}, reject);
if (event.getStatus() === "expired") {
// The event has expired, remove the pin
if (msg.pinned) {
msg.unpin().then(() => fulfill(msg.id)).catch(reject);
}
} else {
fulfill(msg.id);
// The event is still active, keep it pinned.
if (!msg.pinned) {
msg.pin().then(() => fulfill(msg.id)).catch(reject);
}
}
}, reject);
}, reject);
}).catch(reject);
}).catch(reject);

}
}, reject
Expand Down
12 changes: 5 additions & 7 deletions lib/structures/ScheduledEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,11 @@ class ScheduledEvent {
* @returns {Promise<people>} Resolves on success with the people object, or rejects
* with the error.
*
* @typedef {Object} people
* @property {confirm[]} confirmed An array with the Discord's snowflake user ids of
* confirmed people.
* @property {confirm[]} rejected An array with the Discord's snowflake user ids of
* people who have declined the event.
* @property {string[]} waiting An array with the Discord's snowflake user ids of
* people who are waiting to confirm or reject.
* @typedef {Object} people
*
* @property {userConfirm[]} confirmed
* @property {userConfirm[]} rejected
* @property {string[]} waiting
*/
getConfirms() {
return new Promise((fulfill, reject) => {
Expand Down

0 comments on commit 47f41fe

Please sign in to comment.