|
11 | 11 | from prime_backup.db.access import DbAccess |
12 | 12 | from prime_backup.mcdr import mcdr_globals |
13 | 13 | from prime_backup.mcdr.command.commands import CommandManager |
| 14 | +from prime_backup.mcdr.command.disabled_command_helper import DisabledCommandHelper |
14 | 15 | from prime_backup.mcdr.crontab_manager import CrontabManager |
15 | 16 | from prime_backup.mcdr.online_player_counter import OnlinePlayerCounter |
16 | 17 | from prime_backup.mcdr.task_manager import TaskManager |
17 | | -from prime_backup.mcdr.text_components import TextComponents |
18 | | -from prime_backup.utils import misc_utils, mcdr_utils |
| 18 | +from prime_backup.utils import misc_utils |
19 | 19 |
|
20 | 20 | config: Optional[Config] = None |
21 | 21 | task_manager: Optional[TaskManager] = None |
@@ -72,27 +72,18 @@ def init(): |
72 | 72 | init_ok = is_enabled() |
73 | 73 | server.logger.debug('{} init done, init_ok={}'.format(self_name, init_ok)) |
74 | 74 |
|
75 | | - def register_disabled_command(): |
76 | | - from mcdreforged.api.all import SimpleCommandBuilder, CommandSource, RColor |
77 | | - builder = SimpleCommandBuilder() |
78 | | - |
79 | | - @builder.command(config.command.prefix) |
80 | | - def handle_root(source: CommandSource): |
81 | | - with source.preferred_language_context(): |
82 | | - doc_url = mcdr_utils.tr('command.disabled.doc_url').to_plain_text() |
83 | | - mcdr_utils.reply_message(source, mcdr_utils.tr('command.disabled.disabled_by_config', self_name).set_color(RColor.yellow)) |
84 | | - mcdr_utils.reply_message(source, mcdr_utils.tr('command.disabled.read_doc', self_name, TextComponents.url(doc_url))) |
85 | | - |
86 | | - builder.register(server) |
87 | | - |
88 | 75 | global config, task_manager, command_manager, crontab_manager, online_player_counter |
89 | 76 | with handle_init_error(): |
90 | 77 | config = server.load_config_simple(target_class=Config, failure_policy='raise') |
91 | 78 | set_config_instance(config) |
| 79 | + |
| 80 | + disabled_command_helper = DisabledCommandHelper(server, self_name) |
92 | 81 | if not is_enabled(): |
93 | 82 | server.logger.warning('{} is disabled by config'.format(self_name)) |
94 | | - register_disabled_command() |
| 83 | + disabled_command_helper.on_disabled() |
95 | 84 | return |
| 85 | + else: |
| 86 | + disabled_command_helper.on_enabled() |
96 | 87 |
|
97 | 88 | task_manager = TaskManager() |
98 | 89 | crontab_manager = CrontabManager(task_manager) |
|
0 commit comments