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

Allow strings in extra Motd #715

Merged
merged 2 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion mcstatus/motd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ def _parse_as_dict(
auto_add = list(filter(lambda e: type(e) is Formatting and e != Formatting.RESET, parsed_motd))

for element in item["extra"]:
parsed_motd.extend(cls._parse_as_dict(element, auto_add=auto_add.copy()))
parsed_motd.extend(
cls._parse_as_dict(element, auto_add=auto_add.copy())
if isinstance(element, dict)
else auto_add + cls._parse_as_str(element, bedrock=bedrock)
)

return parsed_motd

Expand Down
4 changes: 2 additions & 2 deletions mcstatus/status_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RawJavaResponseVersion(TypedDict):
class RawJavaResponseMotdWhenDict(TypedDict, total=False):
text: str # only present if `translate` is set
translate: str # same to the above field
extra: list[RawJavaResponseMotdWhenDict]
extra: list[RawJavaResponseMotdWhenDict | str]

color: str
bold: bool
Expand All @@ -34,7 +34,7 @@ class RawJavaResponseMotdWhenDict(TypedDict, total=False):
underlined: bool
obfuscated: bool

RawJavaResponseMotd: TypeAlias = "RawJavaResponseMotdWhenDict | list[RawJavaResponseMotdWhenDict] | str"
RawJavaResponseMotd: TypeAlias = "RawJavaResponseMotdWhenDict | list[RawJavaResponseMotdWhenDict | str] | str"

class RawJavaResponse(TypedDict):
description: RawJavaResponseMotd
Expand Down
13 changes: 13 additions & 0 deletions tests/motd/test_motd.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ def test_top_level_formatting_can_be_overwrote(self) -> None:
Formatting.RESET,
]

def test_top_level_formatting_applies_to_string_inside_extra(self) -> None:
"""Although, it is probably a bug in some modded cores, Minecraft supports it, and we should as well.

See `#711 <https://github.com/py-mine/mcstatus/issues/711>`_.
"""
assert Motd.parse({"text": "top", "bold": True, "extra": ["not top"]}).parsed == [
Formatting.BOLD,
"top",
Formatting.RESET,
Formatting.BOLD,
"not top",
]

def test_formatting_key_set_to_false_here_without_it_being_set_to_true_before(self) -> None:
"""Some servers set the formatting keys to false here, even without it ever being set to true before.

Expand Down
Loading