コード例 #1
0
 def __raise_error(self, source, error: CommandError, context: dict):
     handler = self.error_handlers.get(type(error))
     if handler is not None:
         if handler.handled:
             error.set_handled()
         self.__smart_callback(handler.callback, source, error, context)
     raise error
コード例 #2
0
 def __handle_error(self, error: CommandError, context: CommandContext,
                    error_handlers: _ERROR_HANDLER_TYPE):
     for error_type, handler in error_handlers.items():
         if isinstance(error, error_type):
             if handler.handled:
                 error.set_handled()
             self.__smart_callback(handler.callback, context.source, error,
                                   context)
コード例 #3
0
 def on_mcdr_command_unknown_argument(self, source: CommandSource,
                                      error: CommandError):
     command = error.get_parsed_command()
     source.reply(
         RText(self.tr('mcdr_command.command_not_found', command)).h(
             self.tr('mcdr_command.command_not_found_suggest',
                     command)).c(RAction.run_command, command))
     error.set_handled()
コード例 #4
0
	def __translate_command_error_header(self, translation_key: str, error: CommandError):
		if isinstance(error, RequirementNotMet):
			if error.get_reason() is not RequirementNotMet.DEFAULT_REASON:
				return error.get_reason()
			args = ()
		else:
			args = error.get_error_data()
		return self.mcdr_server.tr(translation_key, *args, allow_failure=False)
コード例 #5
0
 def __translate_command_error_header(translation_key_: str,
                                      error_: CommandError) -> str:
     if isinstance(error_, RequirementNotMet):
         if error_.has_custom_reason():
             return error_.get_reason()
         args = ()
     else:
         args = error_.get_error_data()
     return self.mcdr_server.tr(
         translation_key_,
         *args,
         allow_failure=False,
         language=source.get_preference().language)
コード例 #6
0
 def on_mcdr_command_unknown_argument(self, source: CommandSource,
                                      error: CommandError):
     if source.has_permission(PermissionLevel.MCDR_CONTROL_LEVEL):
         command = error.get_parsed_command().rstrip(' ')
         source.reply(
             RText(self.tr('mcdr_command.command_not_found', command)).h(
                 self.tr('mcdr_command.command_not_found_suggest',
                         command)).c(RAction.run_command, command))
     else:
         self.on_mcdr_command_permission_denied(source, error)
コード例 #7
0
 def on_mcdr_command_permission_denied(self, source: CommandSource,
                                       error: CommandError):
     if not error.is_handled():
         source.reply(
             RText(self.mcdr_server.tr('mcdr_command.permission_denied'),
                   color=RColor.red))