Skip to content

Commit

Permalink
SupportRawJsonText
Browse files Browse the repository at this point in the history
  • Loading branch information
GLDYM committed Dec 6, 2023
1 parent 7d6e81a commit fe11a5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions join_motd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import collections
import json
import os
from datetime import datetime
from typing import List, Optional, Callable, Any, Union, Dict
Expand All @@ -22,12 +23,6 @@ class WebInfo(Serializable):
URL: str = ''
description: Optional[str] = None

@classmethod
def from_object(cls, obj) -> 'WebInfo':
if isinstance(obj, cls):
return obj
return WebInfo(name=str(obj))

class Config(Serializable):
serverName: str = 'Survival Server'
mainServerName: str = 'My Server'
Expand All @@ -47,14 +42,28 @@ class Config(Serializable):
WebInfo(name='MCDR文档', description='点击前往MCDR文档!', URL='https://mcdreforged.readthedocs.io/zh_CN/latest/')
]
announcements: List[str] = [
'§b在游玩复读世界的时候,请不要忘了阅读与更新复读百科哦~也请遵守复读公约的规定~§r'
'§b在游玩复读世界的时候,请不要忘了阅读与更新复读百科哦~也请遵守复读公约的规定~§r',
'{\"text\":\"在游玩复读世界的时候,请不要忘了阅读与更新复读百科哦~也请遵守复读公约的规定~\", \"color\":\"blue\"}'
'[{\"text\":\"在游玩复读世界的时候,请不要忘了阅读与更新复读百科哦~也请遵守复读公约的规定~\", \"color\":\"blue\"}, {\"text\":\" 在游玩复读世界的时候,请不要忘了阅读与更新复读百科哦~也请遵守复读公约的规定~\", \"color\":\"blue\"}]'
]


Prefix = '!!joinMOTD'
config: Config
ConfigFilePath = os.path.join('config', 'joinMOTD.json')

def to_message_text(message: str) -> Union[str, RTextBase]:
try:
json_object = json.loads(message)
except ValueError:
return message
if type(json_object) is list:
messages = []
for object in json_object:
messages.append(RTextBase.from_json_object(object))
return RTextBase.join(' ', messages)
else:
return RTextBase.from_json_object(json_object)

def get_day(server: ServerInterface) -> str:
try:
Expand Down Expand Up @@ -110,7 +119,7 @@ def display_motd(server: ServerInterface, reply: Callable[[Union[str, RTextBase]
reply(RTextBase.join(' ', messages))

for announment in config.announcements:
reply(announment)
reply(to_message_text(announment))

def on_player_joined(server: ServerInterface, player, info):
display_motd(server, lambda msg: server.tell(player, msg))
Expand Down
2 changes: 1 addition & 1 deletion mcdreforged.plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "join_motd",
"version": "1.4.0",
"version": "1.4.1",
"name": "Join MOTD FDCraft Ver.",
"description": {
"en_us": "Send player a MOTD when he joins",
Expand Down

0 comments on commit fe11a5e

Please sign in to comment.