Skip to content

Commit

Permalink
Merged branch feature-ticketed-lobbies into dota-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MeLlamoPablo committed Jan 5, 2017
2 parents a31e7b2 + 6b02935 commit 0c5a85e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 41 deletions.
9 changes: 8 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ module.exports = {
// --server flag to the add-inhouse command.
// Go to that command's file (Or type -schedulebot add-ihouse --help)
// to see possible values.
defaultServer: "Luxembourg"
defaultServer: "Luxembourg",

// If enabled is true, the bot will ticket any lobbies using the provided league id.
// Make sure that the steam bot is an admin of that league.
ticketing: {
enabled: false,
league_id: 12345
}
}
};

Expand Down
95 changes: 56 additions & 39 deletions lib/modules/dotahandler/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
const db = require("../dbhandler")
, cfg = require("../../../config")
, Dota2 = require("dota2")
, ELobbyStatus = require("../../structures/enums/ELobbyStatus")
;

// ENUMS
const EServerRegion = Dota2.ServerRegion
, ESeriesType = Dota2.SeriesType
, EGameMode = Dota2.schema.lookupEnum("DOTA_GameMode")
, EGameVersion = Dota2.schema.lookupEnum("DOTAGameVersion")
, ECMPick = Dota2.schema.lookupEnum("DOTA_CM_PICK")
, EDotaTVDelay = Dota2.schema.lookupEnum("LobbyDotaTVDelay")
, EChatChannelType = Dota2.schema.lookupEnum("DOTAChatChannelType_t")
;

class DotaHandler {

constructor(dotaClient) {
Expand Down Expand Up @@ -50,46 +61,46 @@ class DotaHandler {

switch (inhouseProps.server) {
case "uswest":
server = Dota2.ServerRegion.USWEST;
server = EServerRegion.USWEST;
break;
case "useast":
server = Dota2.ServerRegion.USEAST;
server = EServerRegion.USEAST;
break;
case "luxembourg":
server = Dota2.ServerRegion.EUROPE;
server = EServerRegion.EUROPE;
break;
case "australia":
server = Dota2.ServerRegion.AUSTRALIA;
server = EServerRegion.AUSTRALIA;
break;
case "stockholm":
server = Dota2.ServerRegion.STOCKHOLM;
server = EServerRegion.STOCKHOLM;
break;
case "singapore":
server = Dota2.ServerRegion.SINGAPORE;
server = EServerRegion.SINGAPORE;
break;
case "dubai":
server = Dota2.ServerRegion.DUBAI;
server = EServerRegion.DUBAI;
break;
case "austria":
server = Dota2.ServerRegion.AUSTRIA;
server = EServerRegion.AUSTRIA;
break;
case "brazil":
server = Dota2.ServerRegion.BRAZIL;
server = EServerRegion.BRAZIL;
break;
case "southafrica":
server = Dota2.ServerRegion.SOUTHAFRICA;
server = EServerRegion.SOUTHAFRICA;
break;
case "chile":
server = Dota2.ServerRegion.CHILE;
server = EServerRegion.CHILE;
break;
case "peru":
server = Dota2.ServerRegion.PERU;
server = EServerRegion.PERU;
break;
case "india":
server = Dota2.ServerRegion.INDIA;
server = EServerRegion.INDIA;
break;
case "japan":
server = Dota2.ServerRegion.JAPAN;
server = EServerRegion.JAPAN;
break;
default:
return reject(new Error("Unknown server " + inhouseProps.server));
Expand All @@ -99,48 +110,54 @@ class DotaHandler {

switch (inhouseProps.gameMode) {
case "captainsmode":
gamemode = Dota2.schema.DOTA_GameMode.DOTA_GAMEMODE_CM;
gamemode = EGameMode.DOTA_GAMEMODE_CM;
break;
case "allpick":
gamemode = Dota2.schema.DOTA_GameMode.DOTA_GAMEMODE_AP;
gamemode = EGameMode.DOTA_GAMEMODE_AP;
break;
case "captainsdraft":
gamemode = Dota2.schema.DOTA_GameMode.DOTA_GAMEMODE_CD;
gamemode = EGameMode.DOTA_GAMEMODE_CD;
break;
case "randomdraft":
gamemode = Dota2.schema.DOTA_GameMode.DOTA_GAMEMODE_RD;
gamemode = EGameMode.DOTA_GAMEMODE_RD;
break;
case "singledraft":
gamemode = Dota2.schema.DOTA_GameMode.DOTA_GAMEMODE_SD;
gamemode = EGameMode.DOTA_GAMEMODE_SD;
break;
case "allrandom":
gamemode = Dota2.schema.DOTA_GameMode.DOTA_GAMEMODE_AR;
gamemode = EGameMode.DOTA_GAMEMODE_AR;
break;
case "rankedallpick":
gamemode = Dota2.schema.DOTA_GameMode.DOTA_GAMEMODE_ALL_DRAFT;
gamemode = EGameMode.DOTA_GAMEMODE_ALL_DRAFT;
break;
default:
return reject(new Error("Unknown game mode " + inhouseProps.gameMode));
}

let options = {
"game_name": this.currentLobbyName,
"server_region": server,
"game_mode": gamemode,
"game_version": EGameVersion.GAME_VERSION_STABLE,
"series_type": ESeriesType.NONE,
"cm_pick": ECMPick.DOTA_CM_RANDOM,
"allow_cheats": false,
"fill_with_bots": false,
"allow_spectating": true,
"pass_key": this.currentLobbyPassword,
"radiant_series_wins": 0,
"dire_series_wins": 0,
"allchat": false,
"dota_tv_delay": EDotaTVDelay.LobbyDotaTV_120,
};

if (cfg.dota.ticketing.enabled) {
options.leaguid = cfg.dota.ticketing.league_id;
}

this.client.createPracticeLobby(
this.currentLobbyPassword,
{
"game_name": this.currentLobbyName,
"server_region": server,
"game_mode": gamemode,
"game_version": Dota2.schema.DOTAGameVersion.GAME_VERSION_STABLE,
"series_type": Dota2.SeriesType.NONE,
"cm_pick": Dota2.schema.DOTA_CM_PICK.DOTA_CM_RANDOM,
"allow_cheats": false,
"fill_with_bots": false,
"allow_spectating": true,
"pass_key": this.currentLobbyPassword,
"radiant_series_wins": 0,
"dire_series_wins": 0,
"allchat": false,
"dota_tv_delay": Dota2.schema.LobbyDotaTVDelay.LobbyDotaTV_120
},
options,
err => {
if (!err) {
console.log("[DOTA] Created lobby " + this.currentLobbyName);
Expand All @@ -165,13 +182,13 @@ class DotaHandler {
sendMessageToLobby(message) {
this.client.joinChat(
this.currentLobbyChatChannel,
Dota2.schema.DOTAChatChannelType_t.DOTAChannelType_Lobby
EChatChannelType.DOTAChannelType_Lobby
);

this.client.sendMessage(
/*channel*/ this.currentLobbyChatChannel,
/*message*/ message,
/*channel_type*/ Dota2.schema.DOTAChatChannelType_t.DOTAChannelType_Lobby
/*channel_type*/ EChatChannelType.DOTAChannelType_Lobby
);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"clapp": "^1.1.0",
"discord.js": "^10.0.1",
"dota2": "git+https://github.com/tomasmck/node-dota2.git#dc3b70fc3efc575527eafc892346b07416fdfc9b",
"dota2": "git+https://github.com/Arcana/node-dota2.git#3033865a5296579f6deb560d298f6a812a2ec4d4",
"inquirer": "^1.2.2",
"knex": "^0.12.6",
"moment": "^2.15.1",
Expand Down

0 comments on commit 0c5a85e

Please sign in to comment.