-
-
Notifications
You must be signed in to change notification settings - Fork 46
Introduce ext.dota2
- Dota 2 Game Coordinator extension
#460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Aluerie
wants to merge
68
commits into
Gobot1234:main
Choose a base branch
from
Aluerie:introduce-ext.dota2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
de7a99f
🪧Compile protobufs into `.py` mirrors
Aluerie e21b9ef
🐸Initial implementation for Dota2 GC
Aluerie 513ea0c
📃Initial docs for ext.dota2
Aluerie 60e4c39
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 89bdc97
✒️Stealth edit to `fetch_top_source_tv_games` docstring
Aluerie dd0a3b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6355e21
Apply suggestions from code review by Gobot
Aluerie 89b5b01
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ca12e0e
Apply suggestions from code review
Aluerie 728fa0e
⛔Remove Steam NonSense
Aluerie f96967f
🔨Fix bad enum namings
Aluerie 494bd5c
🪓 Total Overhaul of the PR
Aluerie f8bd9b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2e9383f
🖋️Small doc edit
Aluerie da096d4
🆘Apply suggestions from code review by Gobot
Aluerie ab90872
🩺 More feedback corrections
Aluerie c07dff9
🪿Remove `fmt: off` from betterproto Enums
Aluerie dd1b731
🤺Quotes ' -> "
Aluerie db78cd0
🪥 Few more brush ups
Aluerie 8ec073f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3c89f4a
🪥and more
Aluerie e353b49
📺LiveMatchPlayer should subclass Partial user
Aluerie 49ac537
🦸♀️heroes property for LiveMatch
Aluerie 9fd115f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] aa7433b
🤧fix import * abd `__all__`
Aluerie 8561fcb
Merge branch 'introduce-ext.dota2' of https://github.com/Aluerie/stea…
Aluerie 59bf6fd
🔣Doc String + Remove C prefix
Aluerie 037355f
📈 Glicko Rating and Behavior Summary
Aluerie 5a19a1d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7e3ddb1
💥MatchDetails, MM stats, rating - very raw
Aluerie 3b83928
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b4bd089
Merge branch 'Gobot1234:main' into introduce-ext.dota2
Aluerie 69d0c92
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bd12ec8
Merge branch 'Gobot1234:main' into introduce-ext.dota2
Aluerie 517e33f
🏅Implement RankTier Medals
Aluerie 04fcdef
🔬Introduce Match Minimal
Aluerie 5d50888
📂Divide `models.py` into a folder
Aluerie 38a8f39
Create models.py
Aluerie 702f883
🧓Match History
Aluerie f553a8d
📲Social Feed Post Message
Aluerie bfef6bd
🪥Some Brush-ups
Aluerie da9d459
〽️Instantiate Partial Match
Aluerie 8d166c3
🖼️Profile Request
Aluerie 37a8fa7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 55f0486
Doc Edits
Aluerie 87e9220
Merge branch 'introduce-ext.dota2' of https://github.com/Aluerie/stea…
Aluerie 39f907f
🔮Refactor things back to proper state -> models
Aluerie 047da1f
🔝Separate state for TopSource too
Aluerie 6abe799
🦜Separate state for MM stats
Aluerie 12c6df1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e47e624
🌐 `replay_url`, `metadata_url`
Aluerie 4a54ad1
🙂Add Facets to protos
Aluerie f465544
🎶Fix Match History
Aluerie 1a96c93
🆕Add Kez hero
Aluerie f8f9e4a
🪥`timeout` keyword arg for some state methods
Aluerie 5319c4b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 031fef9
Merge branch 'Gobot1234:main' into introduce-ext.dota2
Aluerie 186fe70
Bump typing-extensions from 4.10.0 to 4.12.2
Aluerie 501c0f1
Revert "Bump typing-extensions from 4.10.0 to 4.12.2"
Aluerie e37e82c
Merge branch 'Gobot1234:main' into introduce-ext.dota2
Aluerie dadcebb
⚒️Rename `instantiate` to `create` methods
Aluerie c778eb8
🪥Remove parameter `timeout`
Aluerie bf1ddb1
🪥Names probably should be adjective+noun style
Aluerie a4a8e63
🪥Use `lambda` instead of `partial`
Aluerie 1515ccf
🆕Initial impl for `BaseMatch` and `BasePlayer`
Aluerie 3030bcf
Update models.py
Aluerie ebed275
🔙Revert `partial`->`lambda` change
Aluerie 1acded2
🪥Use `get_partial_user` over direct user constract
Aluerie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.. currentmodule:: steam.ext.dota2 | ||
|
||
API Reference | ||
=============== | ||
|
||
The following section outlines the API of steam.py's Dota 2 extension module. | ||
|
||
|
||
Client | ||
------ | ||
|
||
.. attributetable:: Client | ||
|
||
.. autoclass:: Client | ||
:members: | ||
:inherited-members: | ||
|
||
Bot | ||
---- | ||
|
||
``ext.dota2`` also provides a :class:`Bot` class, which is a subclass of :class:`Client` and :class:`steam.ext.commands.Bot`. | ||
|
||
.. attributetable:: steam.ext.dota2.Bot | ||
|
||
.. autoclass:: steam.ext.dota2.Bot | ||
:members: | ||
:inherited-members: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(steam-ext-dota2)= | ||
|
||
# `steam.ext.dota2` - A Team Fortress 2 Game Coordinator client | ||
|
||
This extension offers the ability to interact with the Dota 2 Game Coordinator (Dota 2 GC) | ||
|
||
```{toctree} | ||
:maxdepth: 2 | ||
|
||
api | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
""" | ||
steam.ext.dota2 | ||
~~~~~~~~~~~~~~ | ||
|
||
A library for interacting with the Dota 2 Game Coordinator. | ||
|
||
Licensed under The MIT License (MIT) - Copyright (c) 2020-present James H-B. See LICENSE | ||
""" | ||
|
||
from .client import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
"""Licensed under The MIT License (MIT) - Copyright (c) 2020-present James H-B. See LICENSE""" | ||
|
||
from __future__ import annotations | ||
|
||
import asyncio | ||
from typing import Final, Literal | ||
|
||
from ..._const import timeout | ||
from ..._gc import Client as Client_ | ||
from ...app import DOTA2 | ||
from ...ext import commands | ||
from ...utils import MISSING | ||
from .protobufs.dota_gcmessages_client_watch import ( | ||
CMsgClientToGCFindTopSourceTVGames, | ||
CMsgGCToClientFindTopSourceTVGamesResponse, | ||
) | ||
from .state import GCState # noqa: TCH001 | ||
|
||
__all__ = ( | ||
"Client", | ||
"Bot", | ||
) | ||
|
||
|
||
class Client(Client_): | ||
"""Represents a client connection that connects to Steam. This class is used to interact with the Steam API, CMs | ||
and the Dota 2 Game Coordinator. | ||
|
||
:class:`Client` is a subclass of :class:`steam.Client`, so whatever you can do with :class:`steam.Client` you can | ||
do with :class:`Client`. | ||
""" | ||
|
||
_APP: Final = DOTA2 | ||
_state: GCState # type: ignore # PEP 705 | ||
|
||
async def fetch_top_source_tv_games( | ||
Aluerie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self, | ||
*, | ||
search_key: str = MISSING, | ||
league_id: int = MISSING, | ||
hero_id: int = MISSING, | ||
start_game: Literal[0, 10, 20, 30, 40, 50, 60, 70, 80, 90] = 0, | ||
game_list_index: int = MISSING, | ||
lobby_ids: list[int] = MISSING, | ||
) -> list[CMsgGCToClientFindTopSourceTVGamesResponse]: | ||
"""Fetch Top Source TV Games. | ||
|
||
This functionality is similar to game list in the Watch Tab of Dota 2 game application. | ||
It fetches summary data for the currently on-going Dota 2 matches from the following categories: | ||
|
||
* tournament games | ||
* highest average mmr games | ||
* specific lobbies, like friends' games by their lobby_ids | ||
|
||
Note | ||
------- | ||
Note that the following documentation for keyword arguments to query against is rather observant | ||
than from official. So, please, if you know more or description is incorrect, contact us. | ||
|
||
Parameters | ||
---------- | ||
search_key : :class: `str`, optional | ||
Unknown purpose. | ||
league_id : :class: `int`, optional | ||
`league_id` for the professional tournament. | ||
hero_id : :class: `int`, optional | ||
`hero_id` to filter results by, just like in-client Watch Tab feature. | ||
start_game : :class: `Literal[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]`, optional, by default 0 | ||
This argument controls how many responses the game coordinator should return. | ||
For example, `start_game=0` returns a list with 1 Response, | ||
`start_game=90` returns a list of 10 Responses. | ||
Game coordinator fills each response in consequent manner with games that satisfy keyword arguments | ||
or with currently live highest average MMR games in case no other argument was given. | ||
game_list_index : :class: `int`, optional | ||
Only get responses matching `game_list_index`. Responses from Game Coordinator change | ||
from time to time. The `game_list_index` indicates that those responses belong to the same chunk. | ||
lobby_ids : :class: `list[int]`, optional | ||
Lobby ids to query against. | ||
Aluerie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Returns | ||
------- | ||
list[dota_gcmessages_client_watch.CMsgGCToClientFindTopSourceTVGamesResponse] | ||
The list of responses from Dota 2 Coordinator. | ||
Those are grouped into grouped into chunks of 10 games. | ||
Aluerie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Raises | ||
------ | ||
asyncio.TimeoutError | ||
Request time-outed. The reason for this might be inappropriate combination of keyword arguments, | ||
inappropriate argument values or simply Dota 2 Game Coordinator being down. | ||
""" | ||
kwargs = locals() | ||
kwargs.pop("self") | ||
kwargs = {key: value for key, value in kwargs.items() if value is not MISSING} | ||
|
||
def start_game_check(start_game: int): | ||
def predicate(msg: CMsgGCToClientFindTopSourceTVGamesResponse) -> bool: | ||
return msg.start_game == start_game | ||
|
||
return predicate | ||
|
||
futures = [ | ||
self._state.ws.gc_wait_for( | ||
CMsgGCToClientFindTopSourceTVGamesResponse, | ||
check=start_game_check(game_counter), | ||
) | ||
for game_counter in list(range(0, start_game + 1, 10)) | ||
] | ||
Aluerie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
await self._state.ws.send_gc_message(CMsgClientToGCFindTopSourceTVGames(**kwargs)) | ||
|
||
try: | ||
async with timeout(30.0): | ||
return await asyncio.gather(*futures) | ||
except asyncio.TimeoutError: | ||
raise asyncio.TimeoutError( | ||
"Request time-outed. The reason might be inappropriate combination of keyword arguments, " | ||
+ "inappropriate argument values or simply Dota 2 Game Coordinator being down." | ||
) | ||
Aluerie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class Bot(commands.Bot, Client): | ||
"""Represents a Steam bot. | ||
|
||
:class:`Bot` is a subclass of :class:`~steam.ext.commands.Bot`, so whatever you can do with | ||
:class:`~steam.ext.commands.Bot` you can do with :class:`Bot`. | ||
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from typing import Final | ||
|
||
import betterproto | ||
|
||
APP_ID: Final = 570 | ||
|
||
from ....protobufs.msg import GCProtobufMessage | ||
from . import dota_gcmessages_client_watch as dota_gcmessages_client_watch, gcsdk_gcmessages as gcsdk_gcmessages | ||
|
||
[setattr(cls, "_betterproto", betterproto.ProtoClassMetadata(cls)) for cls in GCProtobufMessage.__subclasses__()] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.