A SpaceTraders Agent
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 200 lines 6.5 kB view raw
1const std = @import("std"); 2const prettym = @import("pretty"); 3 4pub const accounts = @import("models/accounts.zig"); 5pub const agents = @import("models/agents.zig"); 6pub const contracts = @import("models/contracts.zig"); 7pub const factions = @import("models/factions.zig"); 8pub const ships = @import("models/ships.zig"); 9pub const systems = @import("models/systems.zig"); 10 11pub const inventory = @import("models/inventory.zig"); 12 13pub const Info = @import("models/Info.zig"); 14 15pub const parseSymbol = systems.Symbol.parseSlice; 16 17pub fn Wrapper(comptime T: type) type { 18 return struct { 19 data: ?T = null, 20 meta: ?Meta = null, 21 @"error": ?Error = null, 22 }; 23} 24 25pub const Meta = struct { 26 total: u64 = 0, // [0, ∞) 27 page: u64 = 1, // [1, ∞) 28 limit: u8 = 10, // [1, 20] 29}; 30 31pub const Query = struct { 32 page: u64 = 1, 33 /// How many entries to return per page 34 /// min: 1, max: 20 35 limit: u64 = 20, 36 37 pub fn format(this: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void { 38 try writer.print("?page={}&limit={}", .{ this.page, this.limit }); 39 } 40}; 41 42pub fn SymbolWrapper(comptime T: type) type { 43 return struct { 44 symbol: T, 45 46 pub fn pretty( 47 this: *const @This(), 48 comptime ctx: prettym.Context, 49 run: *const prettym.Runtime, 50 ) error{WriteFailed}!void { 51 return run.pretty(ctx, this.symbol, .{ .skip_type_name = true }); 52 } 53 }; 54} 55 56pub const Error = struct { 57 message: []const u8, 58 code: ErrorCode, 59 data: ?Data = null, 60 requestId: ?[]const u8 = null, 61 62 pub const Data = struct { 63 // Rate Limit 64 type: ?[]const u8 = null, 65 retryAfter: ?u64 = null, 66 limitBurst: ?u64 = null, 67 limitPerSecond: ?u64 = null, 68 remaining: ?u64 = null, 69 reset: ?[]const u8 = null, 70 // Wrong token 71 expectedSubject: ?[]const u8 = null, 72 receivedSubject: ?[]const u8 = null, 73 }; 74}; 75 76pub const Cooldown = struct { 77 shipSymbol: []const u8, 78 totalSeconds: u64, 79 remainingSeconds: u64, 80 expiration: ?[]const u8 = null, 81}; 82 83/// List of Possible Error Codes 84/// 85/// Obtained via [/error-codes](https://spacetraders.io/openapi#tag/global/GET/error-codes) 86pub const ErrorCode = enum(u16) { 87 // Standart Error Codes 88 notFound = 404, 89 tooManyRequests = 429, 90 ddosProtection = 502, 91 92 // SpaceTraders Error Codes 93 responseSerializationError = 3000, 94 unprocessableInputError = 3001, 95 allErrorHandlersFailedError = 3002, 96 systemStatusMaintenanceError = 3100, 97 resetError = 3200, 98 cooldownConflictError = 4000, 99 waypointNoAccessError = 4001, 100 tokenEmptyError = 4100, 101 tokenMissingSubjectError = 4101, 102 tokenInvalidSubjectError = 4102, 103 missingTokenRequestError = 4103, 104 invalidTokenRequestError = 4104, 105 invalidTokenSubjectError = 4105, 106 accountNotExistsError = 4106, 107 agentNotExistsError = 4107, 108 accountHasNoAgentError = 4108, 109 tokenInvalidVersionError = 4109, 110 registerAgentSymbolReservedError = 4110, 111 registerAgentConflictSymbolError = 4111, 112 registerAgentNoStartingLocationsError = 4112, 113 tokenResetDateMismatchError = 4113, 114 invalidAccountRoleError = 4114, 115 invalidTokenError = 4115, 116 missingAccountTokenRequest = 4116, 117 navigateInTransitError = 4200, 118 navigateInvalidDestinationError = 4201, 119 navigateOutsideSystemError = 4202, 120 navigateInsufficientFuelError = 4203, 121 navigateSameDestinationError = 4204, 122 shipExtractInvalidWaypointError = 4205, 123 shipExtractPermissionError = 4206, 124 shipInTransitError = 4214, 125 shipMissingSensorArraysError = 4215, 126 purchaseShipCreditsError = 4216, 127 shipCargoExceedsLimitError = 4217, 128 shipCargoMissingError = 4218, 129 shipCargoUnitCountError = 4219, 130 shipSurveyVerificationError = 4220, 131 shipSurveyExpirationError = 4221, 132 shipSurveyWaypointTypeError = 4222, 133 shipSurveyOrbitError = 4223, 134 shipSurveyExhaustedError = 4224, 135 shipCargoFullError = 4228, 136 waypointChartedError = 4230, 137 shipTransferShipNotFound = 4231, 138 shipTransferAgentConflict = 4232, 139 shipTransferSameShipConflict = 4233, 140 shipTransferLocationConflict = 4234, 141 warpInsideSystemError = 4235, 142 shipNotInOrbitError = 4236, 143 shipInvalidRefineryGoodError = 4237, 144 shipInvalidRefineryTypeError = 4238, 145 shipMissingRefineryError = 4239, 146 shipMissingSurveyorError = 4240, 147 shipMissingWarpDriveError = 4241, 148 shipMissingMineralProcessorError = 4242, 149 shipMissingMiningLasersError = 4243, 150 shipNotDockedError = 4244, 151 purchaseShipNotPresentError = 4245, 152 shipMountNoShipyardError = 4246, 153 shipMissingMountError = 4247, 154 shipMountInsufficientCreditsError = 4248, 155 shipMissingPowerError = 4249, 156 shipMissingSlotsError = 4250, 157 shipMissingMountsError = 4251, 158 shipMissingCrewError = 4252, 159 shipExtractDestabilizedError = 4253, 160 shipJumpInvalidOriginError = 4254, 161 shipJumpInvalidWaypointError = 4255, 162 shipJumpOriginUnderConstructionError = 4256, 163 shipMissingGasProcessorError = 4257, 164 shipMissingGasSiphonsError = 4258, 165 shipSiphonInvalidWaypointError = 4259, 166 shipSiphonPermissionError = 4260, 167 waypointNoYieldError = 4261, 168 shipJumpDestinationUnderConstructionError = 4262, 169 shipScrapInvalidTraitError = 4263, 170 shipRepairInvalidTraitError = 4264, 171 agentInsufficientCreditsError = 4265, 172 shipModuleNoShipyardError = 4266, 173 shipModuleNotInstalledError = 4267, 174 shipModuleInsufficientCreditsError = 4268, 175 cantSlowDownWhileInTransitError = 4269, 176 shipExtractInvalidSurveyLocationError = 4270, 177 shipTransferDockedOrbitConflict = 4271, 178 acceptContractNotAuthorizedError = 4500, 179 acceptContractConflictError = 4501, 180 fulfillContractDeliveryError = 4502, 181 contractDeadlineError = 4503, 182 contractFulfilledError = 4504, 183 contractNotAcceptedError = 4505, 184 contractNotAuthorizedError = 4506, 185 shipDeliverTermsError = 4508, 186 shipDeliverFulfilledError = 4509, 187 shipDeliverInvalidLocationError = 4510, 188 existingContractError = 4511, 189 marketTradeInsufficientCreditsError = 4600, 190 marketTradeNoPurchaseError = 4601, 191 marketTradeNotSoldError = 4602, 192 marketTradeUnitLimitError = 4604, 193 shipNotAvailableForPurchaseError = 4605, 194 waypointNoFactionError = 4700, 195 constructionMaterialNotRequired = 4800, 196 constructionMaterialFulfilled = 4801, 197 shipConstructionInvalidLocationError = 4802, 198 unsupportedMediaTypeError = 5000, 199 _, 200};