dota2

A node-steam plugin for Dota 2.

Usage no npm install needed!

<script type="module">
  import dota2 from 'https://cdn.skypack.dev/dota2';
</script>

README

node-dota2

NPM version Build Status Dependency Status Greenkeeper badge

A node-steam plugin for Dota 2, consider it in alpha state.

Contributing

Check out @RJacksonm1's blog post (his only blog post), Extending node-dota2, for a rough overview of adding new functionality to the library. A fair warning, while the way you search for new functionality is still the same, quite a lot has changed (and been simplified) implementation wise. It is now easier to implement new functionality than it was back when this blog was written.

Be careful, you'll need SVN if you want to work on the project! Executing an npm install inside the project directory has node-steam fetch the most recent node-steam-resources, which needs SVN to obtain the protobufs.

Installation and setup

  • npm install dota2 in your repository root
  • Copy node_modules/dota2/examples/config.js.example to config.js in your project root and edit appropriately
  • Copy node_modules/dota2/examples/example.js in your project root and change line 5 to dota2 = require("dota2"),
  • Run the example script: node example.js
  • If you receive Error 63 you need to provide a Steam Guard code by setting the Steam Guard code in config.js and launching again.
  • Make sure to use at least version 4.4.5 of node js

WARNING

At the moment the serverlist that is kept internally by node-steam contains IP addresses which are no longer responsive. This causes timeouts and makes node-dota2 seem unresponsive. The examples contain a fix for this behaviour. In short, node-steam emits a servers event that will always contain the latest version of the server list. You need to make sure that your bot handles this event and saves its contents so that upon next startup you can initialize node-steam with a more up to date list. The examples folder contains a (as of the beginning of October 2018) working list that is read by the example bots. You can use this list to bootstrap your bot until node-steam updates their embedded list.

Initializing

Parameters:

  • steamClient - Pass a SteamClient instance to use to send & receive GC messages.
  • debug - A boolean noting whether to print information about operations to console.
  • debugMore - A boolean noting whether to print extended debug information. Activating this will log messages for each proto message exchanged with the GC.
var Steam = require('steam'),
    steamClient = new Steam.SteamClient(),
    dota2 = require('dota2'),
    Dota2 = new dota2.Dota2Client(steamClient, true, false);

Disclaimer

We do not in any way encourage people to use their own accounts when using this library. This library tries to mimic the behavior of the Dota 2 client to allow people to programmatically interact with the Dota 2 GC, however we make no efforts to hide this fact and it's pretty easy for Valve to detect clients using this library based on the generated traffic. While Valve has not yet expressed a dislike regarding reverse engineering projects like this one, it's not unimaginable that this might one day change and result in VAC bans.

Examples

The examples directory contains two Dota2 bots as an example. One contains commented-out dota2 methods, the other has boolean activated methods. Both examples show how to interact with the library.

Testing

There is a partial automated test suite for node-dota2, which is located in the test directory. You need to configure the STEAM_USERNAME and STEAM_PASSWORD environment variables to be able to run it. You can launch the tests by running the file with mocha.

API

The API doc can be consulted here or at doclets.io

Dota2

Dota 2 module

Dota2.Dota2Client ⇐ EventEmitter

Kind: static class of Dota2
Extends: EventEmitter
Emits: ready, unhandled, hellotimeout, popup, sourceTVGamesData, inventoryUpdate, practiceLobbyUpdate, practiceLobbyCleared, lobbyInviteUpdate, lobbyInviteCleared, practiceLobbyJoinResponse, practiceLobbyListData, practiceLobbyResponse, lobbyDestroyed, friendPracticeLobbyListData, inviteCreated, partyUpdate, partyCleared, partyInviteUpdate, partyInviteCleared, joinableCustomGameModes, chatChannelsData, chatJoin, chatJoined, chatLeave, chatMessage, profileCardData, playerMatchHistoryData, playerInfoData, playerStatsData, trophyListData, hallOfFameData, playerCardRoster, playerCardDrafted, liveLeagueGamesUpdate, topLeagueMatchesData, teamData, matchesData, matchDetailsData, matchMinimalDetailsData, matchmakingStatsData, topFriendMatchesData, tipResponse, tipped

new Dota2.Dota2Client(steamClient, debug, debugMore)

The Dota 2 client that communicates with the GC

Param Type Description
steamClient Object Node-steam client instance
debug boolean Print debug information to console
debugMore boolean Print even more debug information to console

dota2Client.Logger : winston.Logger

The logger used to write debug messages. This is a WinstonJS logger, feel free to configure it as you like

Kind: instance property of Dota2Client

dota2Client.Inventory : Array.<CSOEconItem>

The current state of the bot's inventory. Contains cosmetics, player cards, ...

Kind: instance property of Dota2Client

dota2Client.chatChannels : Array.<CMsgDOTAJoinChatChannelResponse>

The chat channels the bot has joined

Kind: instance property of Dota2Client

dota2Client.Lobby : CSODOTALobby

The lobby the bot is currently in. Falsy if the bot isn't in a lobby.

Kind: instance property of Dota2Client

Lobby.Options : Object

Kind: static typedef of Lobby
Properties

Name Type Default Description
game_name string Name of the lobby
pass_key string Lobby password
[server_region] ServerRegion module:Dota2.ServerRegion.UNSPECIFIED Server region where the lobby will be created
[game_mode] DOTA_GameMode DOTA_GameMode.DOTA_GAMEMODE_AP Game mode
[game_version] DOTAGameVersion DOTAGameVersion.GAME_VERSION_STABLE Version of the game
[cm_pick] DOTA_CM_PICK DOTA_CM_PICK.DOTA_CM_RANDOM Who gets first pick
[allow_cheats] boolean false Whether or not to allow cheats
[fill_with_bots] boolean false Whether or not to fill empty slots with bots
[bot_difficulty_radiant] BotDifficulty module:Dota2.schema.DOTABotDifficulty.BOT_DIFFICULTY_PASSIVE The bot difficulty for radiant bots, if fill_with_bots is true.
[bot_difficulty_dire] BotDifficulty module:Dota2.schema.DOTABotDifficulty.BOT_DIFFICULTY_PASSIVE The bot difficulty for dire bots, if fill_with_bots is true.
[bot_radiant] number Presumably the ID of the custom AI to be applied to radiant bots.
[bot_dire] number Presumably the ID of the custom AI to be applied to dire bots.
[allow_spectating] boolean true Whether or not to allow spectating
[series_type] SeriesType NONE Whether or not the game is part of a series (Bo3, Bo5).
[radiant_series_wins] number 0 # of games won so far, e.g. for a Bo3 or Bo5.
[dire_series_wins] number 0 # of games won so far, e.g. for a Bo3 or Bo5.
[previous_match_override] number In a series, the match ID of the previous game. If not supplied, the GC will try to find it automatically based on the teams and the players.
[allchat] boolean false Whether or not it's allowed to all-chat
[dota_tv_delay] LobbyDotaTVDelay LobbyDotaTV_120 How much time the game should be delayed for DotaTV.
[leagueid] number The league this lobby is being created for. The bot should be a league admin for this to work.
[custom_game_mode] string Name of the custom game
[custom_map_name] string Which map the custom game should be played on
[custom_difficulty] number Difficulty of the custom game
[custom_game_id] Long 64bit ID of the custom game mode
[pause_setting] LobbyDotaPauseSetting 0 Pause setting: 0 - unlimited, 1 - limited, 2 - disabled

dota2Client.LobbyInvite : CSODOTALobbyInvite

The currently active lobby invitation. Falsy if the bot has not been invited.

Kind: instance property of Dota2Client

dota2Client.Party : CSODOTAParty

The party the bot is currently in. Falsy if the bot isn't in a party.

Kind: instance property of Dota2Client

dota2Client.PartyInvite : CSODOTAPartyInvite

The currently active party invitation. Falsy if the bot has not been invited.

Kind: instance property of Dota2Client

dota2Client.launch()

Reports to Steam that you're playing Dota 2, and then initiates communication with the Game Coordinator.

Kind: instance method of Dota2Client

dota2Client.exit()

Stop sending a heartbeat to the GC and report to steam you're no longer playing Dota 2

Kind: instance method of Dota2Client

dota2Client.joinChat(channel_name, [channel_type])

Joins a chat channel. If the chat channel with the given name doesn't exist, it is created. Listen for the chatMessage event for other people's chat messages. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Default Description
channel_name string Name of the chat channel
[channel_type] DOTAChatChannelType_t DOTAChatChannelType_t.DOTAChatChannelType_Custom The type of the channel being joined

dota2Client.leaveChat(channel_name, [channel_type])

Leaves a chat channel. If you've joined different channels with the same name, specify the type to prevent unexpected behaviour. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
channel_name string Name of the chat channel
[channel_type] DOTAChatChannelType_t The type of the channel being joined

dota2Client.sendMessage(message, channel_name, [channel_type])

Sends a message to the specified chat channel. Won't send if you're not in the channel you try to send to. If you've joined different channels with the same name, specify the type to prevent unexpected behaviour. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
message string The message you want to send
channel_name string Name of the chat channel
[channel_type] DOTAChatChannelType_t The type of the channel being joined

dota2Client.shareLobby(channel_name, [channel_type])

Shares the lobby you're currently in with the chat so other people can join. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
channel_name string Name of the chat channel
[channel_type] DOTAChatChannelType_t The type of the channel being joined

dota2Client.flipCoin(channel_name, [channel_type])

Sends a coin flip to the specified chat channel. Won't send if you're not in the channel you try to send to. If you've joined different channels with the same name, specify the type to prevent unexpected behaviour. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
channel_name string Name of the chat channel
[channel_type] DOTAChatChannelType_t The type of the channel being joined

dota2Client.rollDice(min, max, channel_name, [channel_type])

Sends a dice roll to the specified chat channel. Won't send if you're not in the channel you try to send to. If you've joined different channels with the same name, specify the type to prevent unexpected behaviour. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
min number Lower bound of the dice roll
max number Upper bound of the dice roll
channel_name string Name of the chat channel
[channel_type] DOTAChatChannelType_t The type of the channel being joined

dota2Client.requestChatChannels()

Requests a list of chat channels from the GC. Listen for the chatChannelsData event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

dota2Client.requestPlayerMatchHistory(account_id, [options], [callback])

Requests the given player's match history. The responses are paginated, but you can use the start_at_match_id and matches_requested options to loop through them. Provide a callback or listen for the playerMatchHistoryData event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Default Description
account_id number Dota 2 account ID of the player whose match history the bot should fetch
[options] Object Filtering options
[options.start_at_match_id] number Which match ID to start searching at (pagination)
[options.matches_requested] number How many matches to retrieve
[options.hero_id] number Show only matches where player played the given hero
[options.request_id] number account_id A unique identifier that identifies this request
[options.include_practice_matches] boolean Whether or not to include practice matches in the results
[options.include_custom_games] boolean Whether or not to include custom games in the results
[callback] requestCallback Called with err, CMsgDOTAGetPlayerMatchHistoryResponse

dota2Client.requestProfileCard(account_id, [callback])

Sends a message to the Game Coordinator requesting account_id's profile card. This method is heavily rate limited. When abused, the GC just stops responding. Even the regular client runs into this limit when you check too many profiles. Provide a callback or listen for profileCardData event for Game Coordinator's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
account_id number Dota 2 account ID of the player whose profile card the bot should fetch
[callback] requestCallback Called with err, CMsgDOTAProfileCard

dota2Client.requestProfile(account_id, [callback])

Sends a message to the Game Coordinator requesting account_id's profile page. This method is heavily rate limited. When abused, the GC just stops responding. Even the regular client runs into this limit when you check too many profiles. Provide a callback or listen for profileData event for Game Coordinator's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
account_id number Dota 2 account ID of the player whose profile page the bot should fetch
[callback] requestCallback Called with err, CMsgDOTAProfileResponse

dota2Client.requestHallOfFame(week, [callback])

Sends a message to the Game Coordinator requesting the Hall of Fame data for week. Provide a callback or listen for the hallOfFameData event for the Game Coordinator's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
week number The week of which you wish to know the Hall of Fame members; will return latest week if omitted. Weeks are counted from start of unix epoch with a lower bound of 2233 (2012-10-18)
[callback] requestCallback Called with err, CMsgDOTAHallOfFameResponse

dota2Client.requestPlayerInfo(account_ids)

Sends a message to the Game Coordinator requesting one or multiple account_ids player information. This includes their display name, country code, team info and sponsor, fantasy role, official information lock status, and if the user is marked as a pro player. Listen for the playerInfoData event for the Game Coordinator's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
account_ids number | Array.<number> Either a single or array of Account IDs (lower 32-bits of a 64-bit Steam ID) of desired user(s) player info.

dota2Client.requestTrophyList(account_id, [callback])

Sends a message to the Game Coordinator requesting account_id's trophy data. Provide a callback or listen for trophyListData event for Game Coordinator's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
account_id number Dota 2 account ID of the player whose trophy data the bot should fetch
[callback] requestCallback Called with err, CMsgClientToGCGetTrophyListResponse

dota2Client.requestPlayerStats(account_id, [callback])

Sends a message to the Game Coordinator requesting account_id's player stats. Provide a callback or listen for playerStatsData event for Game Coordinator's response. This data contains all stats shown on a player's profile page. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
account_id number Dota 2 account ID of the player whose player stats the bot should fetch
[callback] requestCallback Called with err, CMsgGCToClientPlayerStatsResponse

dota2Client.tipPlayer(account_id, steam_id, steam_id)

Attempts to tip a player for his performance during a match. Listen for the tipResponse event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
account_id number The Dota2 ID of the player you want to tip.
steam_id Long The match ID for which you want to tip a player.
steam_id number The event ID during which you want to tip a player.

dota2Client.requestJoinableCustomGameModes([server_region])

Requests a list of custom game modes for which there are currently lobbies available. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Default Description
[server_region] ServerRegion ServerRegion.UNSPECIFIED The server region for which you'd like to obtain the joinable custom game modes

dota2Client.requestPlayerCardsByPlayer() ⇒ Array.<FantasyPlayer>

Requests the player stats for each of the players for which you have one or multiple player cards. All requests are staggered in 200ms intervals and time out after 2s. Requires the GC to be ready.

Kind: instance method of Dota2Client

requestPlayerCardsByPlayer.FantasyPlayer : Object

Player with player cards

Kind: static typedef of requestPlayerCardsByPlayer
Properties

Name Type Description
account_id number Dota2 account ID of the player
cards Array.<Object> Player cards of this player in the bot's inventory
cards[].id number ID of the card
cards[].bonuses Array.<Object> Array of bonuses that apply to this card
cards[].bonuses[].type FantasyStats The stat that gets a bonus
cards[].bonuses[].value number Percentage bonus for the stat
stats CMsgGCToClientPlayerStatsResponse Player stats

dota2Client.requestPlayerCardRoster(league_id, timestamp, [callback])

Sends a message to the Game Coordinator requesting your fantasy line-up for a specific day of a given tournament. Provide a callback or listen for the playerCardRoster event for the Game Coordinator's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
league_id number ID of the league
timestamp number Date in timeframe of the league
[callback] requestCallback Called with err, CMsgClientToGCGetPlayerCardRosterResponse

dota2Client.draftPlayerCard(league_id, timestamp, slot, player_card_id, [callback])

Sends a message to the Game Coordinator requesting to draft a certain player card in a specific slot, for a given day in a tournament. Provide a callback or listen for the playerCardDrafted event for the Game Coordinator's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
league_id number ID of the league for which you're drafting a player card
timestamp number Timestamp of the day for which you want to draft a player card
slot number Slot in the draft which you want to fill
player_card_id number Item ID of the player card you want to draft
[callback] requestCallback Called with err, CMsgClientToGCSetPlayerCardRosterResponse

dota2Client.setItemPositions(item_positions)

Attempts to change the position of one or more items in your inventory. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
item_positions Array.<Object> The new positions of the items
item_positions[].item_id number ID of the item
item_positions[].position number New position of the item

dota2Client.deleteItem(item_id)

Attempts to delete an item in your inventory. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
item_id number ID of the item

dota2Client.requestTopLeagueMatches()

Sends a message to the Game Coordinator requesting the top league matches. Listen for the topLeagueMatchesData event for the Game Coordinator's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

dota2Client.createPracticeLobby(options, [callback])

Sends a message to the Game Coordinator requesting to create a lobby. This will automatically make the bot join the first slot on radiant team. Listen for practiceLobbyUpdate response for a snapshot-update of the newly created lobby. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
options Options Configuration options for the lobby
[callback] requestCallback Called with err, CMsgPracticeLobbyJoinResponse

dota2Client.configPracticeLobby(lobby_id, options, [callback])

Sends a message to the Game Coordinator requesting to configure some options of the active lobby. Listen for practiceLobbyUpdate response for a snapshot-update of the newly created lobby. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
lobby_id Long ID of the lobby
options Options The new option values
[callback] requestCallback Called with err, CMsgPracticeLobbyJoinResponse

dota2Client.requestPracticeLobbyList([callback])

Requests a lists of joinable practice lobbies. Provide a callback or listen for the practiceLobbyListData event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
[callback] requestCallback Called with err, CMsgPracticeLobbyListResponse

dota2Client.requestFriendPracticeLobbyList([callback])

Requests a lists of joinable practice lobbies which have one of your friends in them. Provide a callback or listen for the friendPracticeLobbyListData event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
[callback] requestCallback Called with err, CMsgFriendPracticeLobbyListResponse

dota2Client.balancedShuffleLobby([callback])

Shuffles the lobby based on skill level. Requires you to be in a lobby and to be the host. Provide a callback or listen for the practiceLobbyResponse event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
[callback] requestCallback Called with err, CMsgPracticeLobbyJoinResponse

dota2Client.flipLobbyTeams([callback])

Flips the radiant and dire team players. Requires you to be in a lobby and to be the host. Provide a callback or listen for the practiceLobbyResponse event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
[callback] requestCallback Called with err, CMsgPracticeLobbyJoinResponse

dota2Client.inviteToLobby(steam_id)

Asks to invite a player to your lobby. This creates a new default lobby when you are not already in one. Listen for the inviteCreated event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
steam_id Long The Steam ID of the player you want to invite.

dota2Client.practiceLobbyKick(account_id, [callback])

Asks to kick someone from your current practice lobby. Requires you to be in a lobby and to be the host. Provide a callback or listen for the practiceLobbyResponse event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
account_id number The Dota2 account ID of the player you want to kick.
[callback] requestCallback Called with err, CMsgPracticeLobbyJoinResponse

dota2Client.practiceLobbyKickFromTeam(account_id, [callback])

Asks to kick someone from his chosen team in your current practice lobby. The player will be added to the player pool Provide a callback or listen for the practiceLobbyResponse event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
account_id number The Dota2 account ID of the player you want to kick from his team.
[callback] requestCallback Called with err, CMsgPracticeLobbyJoinResponse

dota2Client.joinPracticeLobby(id, password, [callback])

Sends a message to the Game Coordinator requesting to join a lobby. Provide a callback or listen for the practiceLobbyJoinResponse event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
id externalLong The ID of the lobby
password number The password of the lobby
[callback] requestCallback Called with err, CMsgPracticeLobbyJoinResponse

dota2Client.leavePracticeLobby([callback])

Sends a message to the Game Coordinator requesting to leave the current lobby. Provide a callback or listen for the practiceLobbyResponse event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
[callback] requestCallback Called with err, CMsgPracticeLobbyJoinResponse

dota2Client.destroyLobby([callback])

Destroy the current lobby. Requires you to be the host. Provide a callback or listen for the lobbyDestroyed event for the GC's response. Requires the GC to be ready.

Kind: instance method of Dota2Client

Param Type Description
[callback] requestCallback Called with err, CMsgDOTADestroyLobbyResponse

dota2Client.abandonCurrentGame([callback])

Abandons the current game. Provide a call