import type { Args } from "./processing/args"; import { callSammoAPI, extractHttpMethod, GET, PATCH, POST, PUT, type APITail, type APICallT, type RawArgType, type ValidResponse, type InvalidResponse, } from "./util/callSammoAPI"; export type { ValidResponse, InvalidResponse }; import { APIPathGen, NumVar, StrVar } from "./util/APIPathGen.js"; import type { BettingDetailResponse, BettingListResponse } from "./defs/API/Betting"; import type { ReserveBulkCommandResponse, ReserveCommandResponse, ReservedCommandResponse } from "./defs/API/Command"; import type { ChiefResponse } from "./defs/API/NationCommand"; import type { inheritBuffType, InheritLogResponse } from "./defs/API/InheritAction"; import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListResponse, NationInfoResponse } from "./defs/API/Nation"; import type { UploadImageResponse } from "./defs/API/Misc"; import type { GeneralLogType, GetGeneralLogResponse, JoinArgs } from "./defs/API/General"; import type { GetConstResponse, GetCurrentHistoryResponse, GetDiplomacyResponse, GetHistoryResponse, GetRecentRecordResponse, } from "./defs/API/Global"; import type { CachedMapResult, GeneralListResponse, ItemTypeKey, MapResult } from "./defs"; import type { VoteDetailResult, VoteListResult } from "./defs/API/Vote"; import type { ActiveResourceAuctionList, OpenAuctionResponse, UniqueItemAuctionDetail, UniqueItemAuctionList } from "./defs/API/Auction"; const apiRealPath = { Auction: { BidBuyRiceAuction: PUT as APICallT<{ auctionID: number; amount: number; }>, BidSellRiceAuction: PUT as APICallT<{ auctionID: number; amount: number; }>, GetActiveResourceAuctionList: GET as APICallT, OpenBuyRiceAuction: POST as APICallT< { amount: number; closeTurnCnt: number; startBidAmount: number; finishBidAmount: number; }, OpenAuctionResponse >, OpenSellRiceAuction: POST as APICallT< { amount: number; closeTurnCnt: number; startBidAmount: number; finishBidAmount: number; }, OpenAuctionResponse >, BidUniqueAuction: PUT as APICallT<{ auctionID: number; amount: number; }>, GetUniqueItemAuctionDetail: GET as APICallT<{ auctionID: number; }, UniqueItemAuctionDetail>, GetUniqueItemAuctionList: GET as APICallT, OpenUniqueAuction: POST as APICallT<{ itemID: string, amount: number, }, OpenAuctionResponse>, }, Betting: { Bet: PUT as APICallT<{ bettingID: number; bettingType: number[]; amount: number; }>, GetBettingDetail: NumVar("betting_id", GET as APICallT), GetBettingList: GET as APICallT< { req?: "bettingNation" | "tournament"; }, BettingListResponse >, }, Command: { GetReservedCommand: GET as APICallT, PushCommand: PUT as APICallT<{ amount: number; }>, RepeatCommand: PUT as APICallT<{ amount: number; }>, ReserveCommand: PUT as APICallT< { turnList: number[]; action: string; arg?: Args; }, ReserveCommandResponse >, ReserveBulkCommand: PUT as APICallT< { turnList: number[]; action: string; arg?: Args; }[], ReserveBulkCommandResponse >, }, General: { Join: POST as APICallT, GetGeneralLog: GET as APICallT< { reqType: GeneralLogType; reqTo?: number; }, GetGeneralLogResponse >, DropItem: PUT as APICallT<{ itemType: ItemTypeKey; }>, DieOnPrestart: POST as APICallT, BuildNationCandidate: POST as APICallT, }, Global: { GeneralList: GET as APICallT, GeneralListWithToken: GET as APICallT, GetConst: GET as APICallT, GetHistory: StrVar("serverID")(NumVar("year", NumVar("month", GET as APICallT))), GetCurrentHistory: GET as APICallT, GetMap: GET as APICallT< { neutralView?: 0 | 1; showMe?: 0 | 1; }, MapResult >, GetCachedMap: GET as APICallT, GetDiplomacy: GET as APICallT, ExecuteEngine: POST as APICallT, GetRecentRecord: GET as APICallT<{ lastGeneralRecordID: number; lastWorldHistoryID: number; } | undefined, GetRecentRecordResponse>, }, InheritAction: { BuyHiddenBuff: PUT as APICallT<{ type: inheritBuffType; level: number; }>, BuyRandomUnique: PUT as APICallT, ResetSpecialWar: PUT as APICallT, ResetTurnTime: PUT as APICallT, SetNextSpecialWar: PUT as APICallT<{ type: string; }>, GetMoreLog: GET as APICallT<{ lastID: number }, InheritLogResponse> }, Misc: { UploadImage: POST as APICallT< { imageData: string; }, UploadImageResponse >, }, NationCommand: { GetReservedCommand: GET as APICallT, PushCommand: PUT as APICallT<{ amount: number; }>, RepeatCommand: PUT as APICallT<{ amount: number; }>, ReserveCommand: PUT as APICallT< { turnList: number[]; action: string; arg?: Args; }, ReserveCommandResponse >, ReserveBulkCommand: PUT as APICallT< { turnList: number[]; action: string; arg?: Args; }[], ReserveBulkCommandResponse >, }, Nation: { GeneralList: GET as APICallT, SetNotice: PUT as APICallT<{ msg: string; }>, SetScoutMsg: PUT as APICallT<{ msg: string; }>, SetBill: PATCH as APICallT<{ amount: number; }>, SetRate: PATCH as APICallT<{ amount: number; }>, SetSecretLimit: PATCH as APICallT<{ amount: number; }>, SetBlockWar: PATCH as APICallT< { value: boolean; }, SetBlockWarResponse >, SetBlockScout: PATCH as APICallT<{ value: boolean; }>, GetGeneralLog: GET as APICallT< { generalID: number; reqType: GeneralLogType; reqTo?: number; }, GetGeneralLogResponse >, /** @deprecated */ SetTroopName: PATCH as APICallT<{ troopID: number; troopName: string; }>, GetNationInfo: GET as APICallT<{full?: boolean}, NationInfoResponse>, }, Troop: { NewTroop: POST as APICallT<{ troopName: string; }>, JoinTroop: PATCH as APICallT<{ troopID: number; }>, ExitTroop: PATCH as APICallT, SetTroopName: PATCH as APICallT<{ troopID: number; troopName: string; }>, KickFromTroop: PATCH as APICallT<{ troopID: number; generalID: number; }> }, Vote: { AddComment: POST as APICallT<{ voteID: number; text: string; }>, GetVoteList: GET as APICallT, GetVoteDetail: GET as APICallT< { voteID: number; }, VoteDetailResult >, NewVote: POST as APICallT<{ title: string; multipleOptions?: number; endDate?: string; options: string[]; keepOldVote?: boolean; }>, Vote: POST as APICallT< { voteID: number; selection: number[]; }, ValidResponse & { wonLottery: boolean } >, }, } as const; export const SammoAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => { const method = extractHttpMethod(tail); return (args?: RawArgType, returnError?: boolean) => { if (returnError) { return callSammoAPI(method, path.join("/"), args, pathParam, true); } return callSammoAPI(method, path.join("/"), args, pathParam); }; });