Skip to content

Commit

Permalink
fix #21
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Jun 30, 2024
1 parent 4361309 commit 8ee9b34
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ Telegram:[@lgc2333](https://t.me/lgc2333)

## 📝 更新日志

### 0.6.1

- fix [#21](https://github.com/lgc-NB2Dev/nonebot-plugin-picmcstat/issues/21)

### 0.6.0

- 适配 Pydantic V1 & V2
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_picmcstat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from . import __main__ as __main__ # noqa: E402
from .config import ConfigClass # noqa: E402

__version__ = "0.6.0"
__version__ = "0.6.1"
__plugin_meta__ = PluginMetadata(
name="PicMCStat",
description="将一个 Minecraft 服务器的 MOTD 信息绘制为一张图片",
Expand Down
6 changes: 5 additions & 1 deletion nonebot_plugin_picmcstat/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Literal

from mcstatus.motd.components import Formatting, MinecraftColor
Expand Down Expand Up @@ -49,7 +50,11 @@
"m": ["[del]", "[/del]"],
"n": ["[u]", "[/u]"],
"o": ["[i]", "[/i]"],
"k": ["[obfuscated]", "[/obfuscated]"], # placeholder
}
OBFUSCATED_PLACEHOLDER_REGEX = re.compile(
r"\[obfuscated\](?P<inner>.*?)\[/obfuscated\]",
)

ENUM_CODE_COLOR = {MinecraftColor(k): v for k, v in CODE_COLOR.items()}
ENUM_STROKE_COLOR = {MinecraftColor(k): v for k, v in STROKE_COLOR.items()}
Expand All @@ -59,6 +64,5 @@
}
ENUM_STYLE_BBCODE = {Formatting(k): v for k, v in STYLE_BBCODE.items()}


GAME_MODE_MAP = {"Survival": "生存", "Creative": "创造", "Adventure": "冒险"}
FORMAT_CODE_REGEX = r"§[0-9abcdefgklmnor]"
9 changes: 7 additions & 2 deletions nonebot_plugin_picmcstat/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ENUM_STROKE_COLOR_BEDROCK,
ENUM_STYLE_BBCODE,
FORMAT_CODE_REGEX,
OBFUSCATED_PLACEHOLDER_REGEX,
STROKE_COLOR,
)

Expand Down Expand Up @@ -180,7 +181,12 @@ def transform(self, motd_components: Sequence[ParsedMotdComponent]) -> str:
return super().transform(motd_components)

def _format_output(self, results: list[str]) -> str:
return super()._format_output(results) + "".join(self.on_reset)
text = super()._format_output(results) + "".join(self.on_reset)
return re.sub(
OBFUSCATED_PLACEHOLDER_REGEX,
lambda m: (random_char(len(i)) if (i := m.group("inner")) else ""),
text,
)

def _handle_minecraft_color(self, element: MinecraftColor, /) -> str:
stroke_map = ENUM_STROKE_COLOR_BEDROCK if self.bedrock else ENUM_STROKE_COLOR
Expand All @@ -197,7 +203,6 @@ def _handle_formatting(self, element: Formatting, /) -> str:
to_return = "".join(self.on_reset)
self.on_reset = []
return to_return

start, end = ENUM_STYLE_BBCODE[element]
self.on_reset.append(end)
return start

0 comments on commit 8ee9b34

Please sign in to comment.