Skip to content

Commit

Permalink
refactor(bot): ♻️ add constants
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Jul 1, 2022
1 parent ed357de commit 5afe188
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
16 changes: 16 additions & 0 deletions bot/bot/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CONFIG_FILE_NAME = 'config.json'
DATA_FILE_NAME = 'botList.json'

DIMENSIONS = {
'0': 'minecraft:overworld',
'-1': 'minecraft:the_nether',
'1': 'minecraft:the_end',
'overworld': 'minecraft:overworld',
'the_nether': 'minecraft:the_nether',
'the_end': 'minecraft:the_end',
'nether': 'minecraft:the_nether',
'end': 'minecraft:the_end',
'minecraft:overworld': 'minecraft:overworld',
'minecraft:the_nether': 'minecraft:the_nether',
'minecraft:the_end': 'minecraft:the_end'
}
20 changes: 4 additions & 16 deletions bot/bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,8 @@
from mcdreforged.api.rtext import *

from bot.config import Config
from bot.constants import CONFIG_FILE_NAME, DATA_FILE_NAME, DIMENSIONS

DIMENSIONS = {
'0': 'minecraft:overworld',
'-1': 'minecraft:the_nether',
'1': 'minecraft:the_end',
'overworld': 'minecraft:overworld',
'the_nether': 'minecraft:the_nether',
'the_end': 'minecraft:the_end',
'nether': 'minecraft:the_nether',
'end': 'minecraft:the_end',
'minecraft:overworld': 'minecraft:overworld',
'minecraft:the_nether': 'minecraft:the_nether',
'minecraft:the_end': 'minecraft:the_end'
}
HELP_MESSAGE = '''§6!!bot §7显示机器人列表
§6!!bot spawn <name> §7生成机器人
§6!!bot kill <name> §7移除机器人
Expand All @@ -32,11 +20,11 @@ def __init__(self, server: PluginServerInterface):

def init(self):
self.__config = self.__server.load_config_simple(
'config.json',
CONFIG_FILE_NAME,
target_class=Config
)
self.__data = self.__server.load_config_simple(
'data.json',
DATA_FILE_NAME,
default_config={},
echo_in_console=False
)
Expand Down Expand Up @@ -160,4 +148,4 @@ def remove(src, ctx):
)

def __save_data(self):
self.__server.save_config_simple(self.__data, 'data.json')
self.__server.save_config_simple(self.__data, DATA_FILE_NAME)

0 comments on commit 5afe188

Please sign in to comment.