-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,14 @@ | ||
{ | ||
"id": "venture_chat_handler", | ||
"version": "1.0.0", | ||
"name": "VentureChatHandler", | ||
"description": { | ||
"zh_cn": "使MCDReforged能够正常解析由VentureChat修改过后的消息", | ||
"en_us": "Make MCDReforged able to parse VentureChat modified messages" | ||
}, | ||
"dependencies": { | ||
"mcdreforged": ">=2.1.0" | ||
}, | ||
"author": "MC_Nirvana", | ||
"link": "https://github.com/MC-Nirvana/VentureChatHandler" | ||
} |
This file contains 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 @@ | ||
strip_ansi |
This file contains 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,42 @@ | ||
import re | ||
|
||
from strip_ansi import strip_ansi | ||
from typing import List | ||
from typing_extensions import override | ||
from mcdreforged.utils import string_utils | ||
from mcdreforged.info_reactor.info import InfoSource, Info | ||
from mcdreforged.handler.impl import AbstractMinecraftHandler | ||
from venture_chat_handler.config import RegexConfig, load_config | ||
|
||
class VentureChatHandler(AbstractMinecraftHandler): | ||
# 获取处理器的名称 | ||
def get_name(self) -> str: | ||
return 'venturechat_handler' | ||
|
||
# 从服务器标准输出中解析原始结果 | ||
@classmethod | ||
def get_server_stdout_raw_result(cls, text: str) -> Info: | ||
if type(text) is not str: | ||
raise TypeError('The text to parse should be a string') | ||
result = Info(InfoSource.SERVER, text) | ||
result.content = strip_ansi(string_utils.clean_console_color_code(text)) | ||
return result | ||
|
||
# 获取内容解析的正则表达式模式 | ||
@classmethod | ||
@override | ||
def get_content_parsing_formatter(cls) -> re.Pattern: | ||
return re.compile( | ||
r'\[(?P<hour>\d+):(?P<min>\d+):(?P<sec>\d+) (?P<logging>[^]]+)]' | ||
r': (?P<content>.*)' | ||
) | ||
|
||
# 获取玩家消息解析的正则表达式模式列表 | ||
@classmethod | ||
@override | ||
def get_player_message_parsing_formatter(cls) -> List[re.Pattern]: | ||
regex = RegexConfig.chat_prefix_regex | ||
return [re.compile(regex)] | ||
def on_load(server, prev_module): | ||
load_config(server) | ||
server.register_server_handler(VentureChatHandler()) |
This file contains 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,13 @@ | ||
from mcdreforged.api.all import * | ||
|
||
# 定义默认配置 | ||
class RegexConfig(Serializable): | ||
chat_prefix_regex: str = r'(\[.*] )?(?P<name>[^>]+)>>> (?P<message>.*)' | ||
|
||
# 全局配置对象 | ||
config: RegexConfig | ||
|
||
# 加载配置文件 | ||
def load_config(server): | ||
global config | ||
config = server.load_config_simple(target_class=RegexConfig) |