Skip to content
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

Rewrite Query response class to #306's style #536

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
90337a7
Rename `status_response` to `responses`
PerchunPak May 14, 2023
482cd59
Rewrite Query response class to 306's style
PerchunPak May 14, 2023
0a8b293
Merge branch 'master' into rewrite-query-answer-class
PerchunPak Aug 14, 2023
8d74db9
Ignore pyright's warning about wildcard import
PerchunPak Aug 14, 2023
11727d6
Merge remote-tracking branch 'upstream/master' into rewrite-query-ans…
PerchunPak Oct 1, 2023
aa9fec2
Merge remote-tracking branch 'origin/master' into rewrite-query-answe…
PerchunPak Oct 11, 2023
7a883e7
Rename `transform_connection_to_objects` to `_parse_response`
PerchunPak Oct 11, 2023
8e7fed4
Do not use star import
PerchunPak Oct 11, 2023
67a516e
Merge remote-tracking branch 'origin/master' into rewrite-query-answe…
PerchunPak Dec 4, 2023
3a531d0
Merge branch 'master' into rewrite-query-answer-class
PerchunPak Jan 7, 2024
e78a9a8
Return `utils.deprecated` import
PerchunPak Jan 7, 2024
1580c6c
Replace usage of deprecated `QueryResponse.map` to `.map_name` in CLI
PerchunPak Jan 7, 2024
c1de661
Rename `responses` back to `status_response`
PerchunPak Feb 19, 2024
252855a
Merge branch 'master' into rewrite-query-answer-class
PerchunPak Feb 19, 2024
4a3f5d6
Freeze all dataclasses
PerchunPak Feb 19, 2024
8f34ffb
Merge branch 'master' into rewrite-query-answer-class
PerchunPak May 26, 2024
8003e7c
Merge branch 'master' into rewrite-query-answer-class
PerchunPak May 28, 2024
d8b2053
Merge branch 'master' into rewrite-query-answer-class
PerchunPak Jun 3, 2024
3f55640
Merge branch 'master' into rewrite-query-answer-class
PerchunPak Jul 18, 2024
923a083
Replace all usages of `status_response` with `responses`
PerchunPak Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 24 additions & 86 deletions docs/api/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,132 +34,70 @@ These are the classes that you get back after making a request.
For Java Server
***************

.. module:: mcstatus.status_response
.. module:: mcstatus.responses

.. autoclass:: mcstatus.status_response.JavaStatusResponse()
.. autoclass:: mcstatus.responses.JavaStatusResponse()
:members:
:undoc-members:
:inherited-members:
:exclude-members: build

.. autoclass:: mcstatus.status_response.JavaStatusPlayers()
.. autoclass:: mcstatus.responses.JavaStatusPlayers()
:members:
:undoc-members:
:inherited-members:
:exclude-members: build

.. autoclass:: mcstatus.status_response.JavaStatusPlayer()
.. autoclass:: mcstatus.responses.JavaStatusPlayer()
:members:
:undoc-members:
:inherited-members:
:exclude-members: build

.. autoclass:: mcstatus.status_response.JavaStatusVersion()
.. autoclass:: mcstatus.responses.JavaStatusVersion()
:members:
:undoc-members:
:inherited-members:
:exclude-members: build

.. module:: mcstatus.querier

.. class:: QueryResponse
:canonical: mcstatus.querier.QueryResponse

The response object for :meth:`JavaServer.query() <mcstatus.server.JavaServer.query>`.

.. class:: Players
:canonical: mcstatus.querier.QueryResponse.Players

Class for storing information about players on the server.

.. attribute:: online
:type: int
:canonical: mcstatus.querier.QueryResponse.Players.online

The number of online players.

.. attribute:: max
:type: int
:canonical: mcstatus.querier.QueryResponse.Players.max

The maximum allowed number of players (server slots).

.. attribute:: names
:type: list[str]
:canonical: mcstatus.querier.QueryResponse.Players.names

The list of online players.

.. class:: Software
:canonical: mcstatus.querier.QueryResponse.Software

Class for storing information about software on the server.

.. attribute:: version
:type: str
:canonical: mcstatus.querier.QueryResponse.Software.version

The version of the software.

.. attribute:: brand
:type: str
:value: "vanilla"
:canonical: mcstatus.querier.QueryResponse.Software.brand

The brand of the software. Like `Paper <https://papermc.io>`_ or `Spigot <https://www.spigotmc.org>`_.

.. attribute:: plugins
:type: list[str]
:canonical: mcstatus.querier.QueryResponse.Software.plugins

The list of plugins. Can be empty if hidden.

.. attribute:: motd
:type: ~mcstatus.motd.Motd
:canonical: mcstatus.querier.QueryResponse.motd

The MOTD of the server. Also known as description.

.. seealso:: :doc:`/api/motd_parsing`.

.. attribute:: map
:type: str
:canonical: mcstatus.querier.QueryResponse.map

The name of the map.

.. attribute:: players
:type: ~QueryResponse.Players
:canonical: mcstatus.querier.QueryResponse.players

The players information.
.. autoclass:: mcstatus.responses.QueryResponse()
:members:
:undoc-members:
:inherited-members:
:exclude-members: build

.. attribute:: software
:type: ~QueryResponse.Software
:canonical: mcstatus.querier.QueryResponse.software
.. autoclass:: mcstatus.responses.QueryPlayers()
:members:
:undoc-members:
:inherited-members:
:exclude-members: build

The software information.
.. autoclass:: mcstatus.responses.QuerySoftware()
:members:
:undoc-members:
:inherited-members:
:exclude-members: build


For Bedrock Servers
*******************

.. module:: mcstatus.status_response
.. module:: mcstatus.responses
:noindex:

.. autoclass:: mcstatus.status_response.BedrockStatusResponse()
.. autoclass:: mcstatus.responses.BedrockStatusResponse()
:members:
:undoc-members:
:inherited-members:
:exclude-members: build

.. autoclass:: mcstatus.status_response.BedrockStatusPlayers()
.. autoclass:: mcstatus.responses.BedrockStatusPlayers()
:members:
:undoc-members:
:inherited-members:
:exclude-members: build

.. autoclass:: mcstatus.status_response.BedrockStatusVersion()
.. autoclass:: mcstatus.responses.BedrockStatusVersion()
:members:
:undoc-members:
:inherited-members:
Expand Down
6 changes: 3 additions & 3 deletions docs/api/internal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ versions. They are only documented here for linkable reference to them.
:undoc-members:
:show-inheritance:

.. autoclass:: mcstatus.status_response.BaseStatusResponse
.. autoclass:: mcstatus.responses.BaseStatusResponse
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: mcstatus.status_response.BaseStatusPlayers
.. autoclass:: mcstatus.responses.BaseStatusPlayers
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: mcstatus.status_response.BaseStatusVersion
.. autoclass:: mcstatus.responses.BaseStatusVersion
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/examples/code/ping_as_java_and_bedrock_in_one_time.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio

from mcstatus import BedrockServer, JavaServer
from mcstatus.status_response import BedrockStatusResponse, JavaStatusResponse
from mcstatus.responses import BedrockStatusResponse, JavaStatusResponse


async def status(host: str) -> JavaStatusResponse | BedrockStatusResponse:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
server = JavaServer.lookup("play.hypixel.net")
query = server.query()

if query.players.names:
print("Players online:", ", ".join(query.players.names))
if query.players.list:
print("Players online:", ", ".join(query.players.list))
else:
status = server.status()

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/ping_as_java_and_bedrock_in_one_time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ You can easily ping a server as a Java server and as a Bedrock server in one tim

.. literalinclude:: code/ping_as_java_and_bedrock_in_one_time.py

As you can see in the code, ``status`` function returns :class:`~mcstatus.status_response.JavaStatusResponse`
or :class:`~mcstatus.status_response.BedrockStatusResponse` object. You can use
As you can see in the code, ``status`` function returns :class:`~mcstatus.responses.JavaStatusResponse`
or :class:`~mcstatus.responses.BedrockStatusResponse` object. You can use
:func:`isinstance` checks to access attributes that are only in one of the
objects.

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ How to get server image?

On Bedrock, only official servers have a server image. There is no way to get
or set an icon to a custom server. For Java servers, you can use
:attr:`status.icon <mcstatus.status_response.JavaStatusResponse.icon>`
:attr:`status.icon <mcstatus.responses.JavaStatusResponse.icon>`
attribute. It will return `Base64 <https://en.wikipedia.org/wiki/Base64>`_
encoded PNG image. If you wish to save this image into a file, this is how:

Expand Down
2 changes: 1 addition & 1 deletion mcstatus/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def query(server: JavaServer) -> None:
print(f"software: v{response.software.version} {response.software.brand}")
print(f"plugins: {response.software.plugins}")
print(f'motd: "{response.motd}"')
print(f"players: {response.players.online}/{response.players.max} {response.players.names}")
print(f"players: {response.players.online}/{response.players.max} {', '.join(response.players.list)}")


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion mcstatus/bedrock_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import asyncio_dgram

from mcstatus.address import Address
from mcstatus.status_response import BedrockStatusResponse
from mcstatus.responses import BedrockStatusResponse

# TODO Remove this useless __all__ after 2023-08
__all__ = ("BedrockServerStatus", "BedrockStatusResponse")
Expand Down
2 changes: 1 addition & 1 deletion mcstatus/motd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if t.TYPE_CHECKING:
from typing_extensions import Self

from mcstatus.status_response import RawJavaResponseMotd, RawJavaResponseMotdWhenDict # circular import
from mcstatus.responses import RawJavaResponseMotd, RawJavaResponseMotdWhenDict # circular import
else:
RawJavaResponseMotdWhenDict = dict

Expand Down
2 changes: 1 addition & 1 deletion mcstatus/pinger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from mcstatus.address import Address
from mcstatus.protocol.connection import Connection, TCPAsyncSocketConnection, TCPSocketConnection
from mcstatus.status_response import JavaStatusResponse
from mcstatus.responses import JavaStatusResponse

if TYPE_CHECKING:
from typing_extensions import TypeAlias
Expand Down
Loading
Loading