Check type in extra so we don't iterate thru str

This commit is contained in:
Andrew 2023-12-29 12:11:29 -05:00
parent a67f53a4c9
commit 60ac3bf630

View File

@ -12,6 +12,7 @@ from app.classes.minecraft.bedrock_ping import BedrockPing
from app.classes.shared.console import Console from app.classes.shared.console import Console
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
MOTD_CODES = ["bold", "italic", "underlined", "strikethrough"]
class Server: class Server:
@ -37,28 +38,24 @@ class Server:
if "text" in description.keys(): if "text" in description.keys():
lines.append(description["text"]) lines.append(description["text"])
if "extra" in description.keys(): if "extra" in description.keys():
for e in description["extra"]: if isinstance(description["extra"], list):
if not isinstance(e, dict): for e in description["extra"]:
lines.append(e) if not isinstance(e, dict):
continue lines.append(e)
# Conversion format code needed only for Java Version continue
lines.append(get_code_format("reset")) # Conversion format code needed only for Java Version
if "bold" in e.keys(): lines.append(get_code_format("reset"))
lines.append(get_code_format("bold")) for item in MOTD_CODES:
if "italic" in e.keys(): if e.get(item, False):
lines.append(get_code_format("italic")) lines.append(get_code_format(item))
if "underlined" in e.keys(): if "color" in e.keys():
lines.append(get_code_format("underlined")) lines.append(get_code_format(e["color"]))
if "strikethrough" in e.keys(): # Then append the text
lines.append(get_code_format("strikethrough")) if "text" in e.keys():
if "color" in e.keys(): if e["text"] == "\n":
lines.append(get_code_format(e["color"])) lines.append("§§")
# Then append the text else:
if "text" in e.keys(): lines.append(e["text"])
if e["text"] == "\n":
lines.append("§§")
else:
lines.append(e["text"])
total_text = " ".join(lines) total_text = " ".join(lines)
self.description = total_text self.description = total_text