Skip to content

Commit

Permalink
The bot is able to retrieve the Match ID
Browse files Browse the repository at this point in the history
  • Loading branch information
MeLlamoPablo committed Jan 20, 2017
1 parent 47f41fe commit b69cc92
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 8 deletions.
8 changes: 5 additions & 3 deletions lib/commands/admin/force-lobby-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const Clapp = require("../../modules/clapp-discord")
, ECloseLobbyError = require("../../structures/enums/ECloseLobbyError")
, db = require("../../modules/dbhandler").events
, db = require("../../modules/dbhandler")
;

module.exports = new Clapp.Command({
Expand All @@ -13,8 +13,10 @@ module.exports = new Clapp.Command({
db.events.get(argv.args.event).then(event => {
if (event !== null) {
db.events.getLobbyBotId(event)
.then(botID => context.dotaHandler.forceLobbyStart(botID))
.then(() => fulfill(`Forced lobby start for the event ${event.id}.`))
.then(botID => {
fulfill(`Forced lobby start for the event ${event.id}.`);
context.dotaHandler.forceLobbyStart(botID).catch(reject);
})
.catch(reject);
} else {
fulfill("Error: the specified event `" + argv.args.event + "` doesn't exist.");
Expand Down
34 changes: 33 additions & 1 deletion lib/modules/dbhandler/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const events = {
},

/**
* Gets the "lobby ended" property of a specific event.
* Gets the "lobby status" property of a specific event.
* @param {ScheduledEvent} event
* @return {Promise<ELobbyStatus>}
*/
Expand All @@ -103,6 +103,21 @@ const events = {
});
},

/**
* Gets the dota_match_id property of a specific event.
* @param {ScheduledEvent} event
* @return {Promise<string>}
*/
getDotaMatchId: function(event) {
return new Promise((fulfill, reject) => {
db("events").select("dota_match_id").where({
id: event.id
}).then(rows => {
fulfill(rows[0] ? rows[0].dota_match_id : null);
}).catch(reject);
});
},

/**
* Gets the lobby_bot_id property of a specific event.
* @param {ScheduledEvent} event
Expand Down Expand Up @@ -240,6 +255,23 @@ const events = {
});
},

/**
* Updates the dota_match_id property of an event
*
* @param {ScheduledEvent} event
* @param {string} matchId
* @return {Promise}
*/
updateDotaMatchId: function(event, matchId) {
return new Promise((fulfill, reject) => {
db("events").update({
dota_match_id: matchId
}).where({
id: event.id
}).then(fulfill).catch(reject);
});
},

/**
* Updates the lobby_bot_id property of an event.
*
Expand Down
4 changes: 3 additions & 1 deletion lib/modules/dbhandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ module.exports = {
},

getWaiting: core.events.getWaiting,
getLobbyEnded: core.events.getLobbyStatus,
getLobbyStatus: core.events.getLobbyStatus,
getDotaMatchId: core.events.getDotaMatchId,
getLobbyBotId: core.events.getLobbyBotId,
getInhouse: core.events.getInhouse,
add: core.events.add,
addInstant: core.events.addInstant,
addInhouse: core.events.addInhouse,
updateWaiting: core.events.updateWaiting,
updateLobbyStatus: core.events.updateLobbyStatus,
updateDotaMatchId: core.events.updateDotaMatchId,
updateLobbyBotId: core.events.updateLobbyBotId,
deleteEvent: core.events.deleteEvent
},
Expand Down
22 changes: 21 additions & 1 deletion lib/modules/dotahandler/DotaClientX.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const EServerRegion = Dota2.ServerRegion
, ECMPick = Dota2.schema.lookupEnum("DOTA_CM_PICK")
, EDotaTVDelay = Dota2.schema.lookupEnum("LobbyDotaTVDelay")
, EChatChannelType = Dota2.schema.lookupEnum("DOTAChatChannelType_t")

, ELobbyStatus = require("../../structures/enums/ELobbyStatus")
;

Expand All @@ -33,6 +32,7 @@ const EServerRegion = Dota2.ServerRegion
* @property {boolean} currentLobby.starting
* @property {boolean} currentLobby.enoughPeople
* @property {boolean} currentLobby.autoBalance
* @property {boolean} currentLobby.matchIdSaved
*/
class DotaClientX extends Dota2.Dota2Client {

Expand Down Expand Up @@ -63,6 +63,15 @@ class DotaClientX extends Dota2.Dota2Client {
if (this.currentLobby.enoughPeople && !this.currentLobby.starting) {
this.start();
}

if (lobby.match_id > 0 && cfg.dota.ticketing.enabled) {
if (!this.currentLobby.matchIdSaved && this.currentLobby.event !== null) {
db.events.updateDotaMatchId(this.currentLobby.event, lobby.match_id.toString())
.then(() => {
this.currentLobby.matchIdSaved = true
}).catch(console.error);
}
}
});
}

Expand Down Expand Up @@ -197,6 +206,16 @@ class DotaClientX extends Dota2.Dota2Client {
}
});

/*setTimeout(() => {
this.joinPracticeLobbyBroadcastChannel(1, (err, res) => {
if (err) {
reject(err);
} else {
console.log(res);
}
});
}, 1000);*/

this.inviteAll().catch(reject);
fulfill();
} else {
Expand Down Expand Up @@ -380,6 +399,7 @@ class DotaClientX extends Dota2.Dota2Client {
this.currentLobby.starting = false;
this.currentLobby.enoughPeople = false;
this.currentLobby.autoBalance = false;
this.currentLobby.matchIdSaved = false;
}

_log(msg) {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/dotahandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ECreateLobbyError = require("../../structures/enums/ECreateLobbyError")
*
* @property {SteamBot[]} bots An array with all steam bots.
*/
class DotaHandler { // TODO !!!! make sure that all commands use the correct api of this
class DotaHandler {

/**
* @param {SteamBot[]} bots
Expand Down
9 changes: 9 additions & 0 deletions lib/modules/opendotaclient/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class OpenDotaClient {
return request(BASE_URL + "/players/" + sID.accountid);
}

/**
* @param {string} id The game's match ID. For example: 2927308329.
* @example
* See https://docs.opendota.com/#tag/matches%2Fpaths%2F~1matches~1%7Bmatch_id%7D%2Fget
*/
static getMatch(id) {
return request(BASE_URL + "/matches/" + id);
}

}

module.exports = OpenDotaClient;
12 changes: 11 additions & 1 deletion lib/modules/summaryhandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ class SummaryHandler {
let getConfirmsPromise = event.getConfirms();
let getInhousePropsPromise = event.getInhouseProperties();
let getLobbyStatusPromise = event.getLobbyStatus();
let getMatchIdPromise = event.getMatchId();

Promise.all([
getConfirmsPromise, getInhousePropsPromise, getLobbyStatusPromise
getConfirmsPromise,
getInhousePropsPromise,
getLobbyStatusPromise,
getMatchIdPromise
]).then(values => {
let people = values[0];
let inhouseProps = values[1];
let lobbyStatus = values[2];
let matchId = values[3];

let summary = "";
let status = event.getStatus();
Expand Down Expand Up @@ -184,6 +189,11 @@ class SummaryHandler {
break;
case ELobbyStatus.CLOSED:
summary += "The lobby for this event is closed.";

if (matchId) {
summary += ` Match ID: \`${matchId}\``;
}

break;
case ELobbyStatus.NO_AVAILABLE_BOT:
summary += "All Steam bots are currently busy. Please wait " +
Expand Down
9 changes: 9 additions & 0 deletions lib/structures/ScheduledEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ class ScheduledEvent {
return db.events.getLobbyStatus(this);
}

/**
* Determines the match id associated with this event.
*
* @return {Promise.<string>}
*/
getMatchId() {
return db.events.getDotaMatchId(this);
}

/**
* @param {string} msgId
* @return {Promise} Resolves on success, or rejects with the error.
Expand Down
1 change: 1 addition & 0 deletions scripts/sql/next_version.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ ALTER TABLE public.config DROP steam_guard_code;
ALTER TABLE public.config DROP steam_sentry_file;

ALTER TABLE public.events ADD lobby_bot_id INT DEFAULT NULL NULL;
ALTER TABLE public.events ADD dota_match_id TEXT DEFAULT NULL NULL;

ALTER TABLE public.users ADD solo_mmr INT DEFAULT NULL NULL;

0 comments on commit b69cc92

Please sign in to comment.