Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default tseslint.config(
},
],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-require-imports': 'error',
'import-x/extensions': [
'error',
'ignorePackages',
Expand Down Expand Up @@ -96,23 +96,8 @@ export default tseslint.config(
languageOptions: {
sourceType: 'commonjs',
},
},
{
files: ['src/types/vendor.d.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['tests/**/*.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'import-x/extensions': 'off',
'@typescript-eslint/no-require-imports': 'off',
},
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/reporters/aaci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
GameApiPostBody,
GameApiResponseBody,
} from '../types/game-api'
import type { Reporter } from '../types/reporter'
import type { NightBattleEquip } from './utils'

interface AACIShip {
Expand Down Expand Up @@ -40,7 +41,7 @@ type EquipSelectorResult = Array<[Partial<NightBattleEquip>?, Partial<NightBattl
type GetShipAACIs = (ship: AACIShip, equips: NightBattleEquip[]) => number[]
type AACIModule = typeof aaciModule

export default class AACIReporter extends BaseReporter {
export default class AACIReporter extends BaseReporter implements Reporter {
getShipAACIs: GetShipAACIs | null = null

constructor() {
Expand Down
20 changes: 12 additions & 8 deletions src/reporters/create-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@ import type {
GameApiPostBody,
GameApiResponseBody,
} from '../types/game-api'
import type { Reporter } from '../types/reporter'
import { parseInt10 } from '../types/window-state'

type CreateItemPostBody = Pick<
type CreateItemPostBodyKey = keyof Pick<
APIReqKousyouCreateitemRequest,
'api_item1' | 'api_item2' | 'api_item3' | 'api_item4'
>

type CreateItemPostBody = Record<CreateItemPostBodyKey, string | number>

type CreateItemResponseBody = Pick<APIReqKousyouCreateitemResponse, 'api_get_items'>

const isCreateItemPostBody = (postBody: GameApiPostBody): postBody is CreateItemPostBody =>
['api_item1', 'api_item2', 'api_item3', 'api_item4'].every(
(key) => typeof postBody[key] === 'string',
(['api_item1', 'api_item2', 'api_item3', 'api_item4'] as CreateItemPostBodyKey[]).every((key) =>
['number', 'string'].includes(typeof postBody[key]),
)

const isCreateItemResponseBody = (body: GameApiResponseBody): body is CreateItemResponseBody =>
body != null &&
typeof body === 'object' &&
Array.isArray((body as Partial<CreateItemResponseBody>).api_get_items)

export default class CreateItemReporter extends BaseReporter {
export default class CreateItemReporter extends BaseReporter implements Reporter {
handle(
method: GameApiMethod,
path: GameApiPath,
Expand All @@ -47,10 +51,10 @@ export default class CreateItemReporter extends BaseReporter {
body.api_get_items.forEach((item) => {
void this.report('/api/report/v2/create_item', {
items: [
parseInt(postBody.api_item1),
parseInt(postBody.api_item2),
parseInt(postBody.api_item3),
parseInt(postBody.api_item4),
parseInt10(postBody.api_item1),
parseInt10(postBody.api_item2),
parseInt10(postBody.api_item3),
parseInt10(postBody.api_item4),
],
itemId: item.api_slotitem_id,
teitokuLv: _teitokuLv,
Expand Down
28 changes: 16 additions & 12 deletions src/reporters/create-ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import type {
GameApiPostBody,
GameApiResponseBody,
} from '../types/game-api'
import type { Reporter } from '../types/reporter'
import { parseInt10 } from '../types/window-state'

type CreateShipPostBody = Pick<
type CreateShipPostBodyKey = keyof Pick<
APIReqKousyouCreateshipRequest,
| 'api_highspeed'
| 'api_item1'
Expand All @@ -20,6 +22,8 @@ type CreateShipPostBody = Pick<
| 'api_large_flag'
>

type CreateShipPostBody = Record<CreateShipPostBodyKey, string | number>

type CreateShipKdock = Pick<
APIGetMemberKdockResponse,
'api_created_ship_id' | 'api_item1' | 'api_item2' | 'api_item3' | 'api_item4' | 'api_item5'
Expand All @@ -35,7 +39,7 @@ interface CreateShipReportPayload {
shipId: number
}

const createShipPostBodyKeys: Array<keyof CreateShipPostBody> = [
const createShipPostBodyKeys: CreateShipPostBodyKey[] = [
'api_highspeed',
'api_item1',
'api_item2',
Expand All @@ -47,9 +51,9 @@ const createShipPostBodyKeys: Array<keyof CreateShipPostBody> = [
]

const isCreateShipPostBody = (postBody: GameApiPostBody): postBody is CreateShipPostBody =>
createShipPostBodyKeys.every((key) => typeof postBody[key] === 'string')
createShipPostBodyKeys.every((key) => ['number', 'string'].includes(typeof postBody[key]))

export default class CreateShipReporter extends BaseReporter {
export default class CreateShipReporter extends BaseReporter implements Reporter {
creating: boolean
kdockId: number
info: CreateShipReportPayload | null
Expand All @@ -74,7 +78,7 @@ export default class CreateShipReporter extends BaseReporter {
return
}
this.creating = true
this.kdockId = parseInt(postBody.api_kdock_id) - 1
this.kdockId = parseInt10(postBody.api_kdock_id) - 1
const secretaryIdx = _decks[0]?.api_ship[0]
const secretary = secretaryIdx == null ? undefined : _ships[secretaryIdx]
if (!secretary) {
Expand All @@ -84,15 +88,15 @@ export default class CreateShipReporter extends BaseReporter {
}
this.info = {
items: [
parseInt(postBody.api_item1),
parseInt(postBody.api_item2),
parseInt(postBody.api_item3),
parseInt(postBody.api_item4),
parseInt(postBody.api_item5),
parseInt10(postBody.api_item1),
parseInt10(postBody.api_item2),
parseInt10(postBody.api_item3),
parseInt10(postBody.api_item4),
parseInt10(postBody.api_item5),
],
kdockId: this.kdockId,
largeFlag: parseInt(postBody.api_large_flag) != 0,
highspeed: parseInt(postBody.api_highspeed),
largeFlag: parseInt10(postBody.api_large_flag) != 0,
highspeed: parseInt10(postBody.api_highspeed),
secretary: secretary.api_ship_id,
teitokuLv: _teitokuLv,
shipId: -1,
Expand Down
3 changes: 2 additions & 1 deletion src/reporters/drop-ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
GameApiPostBody,
GameApiResponseBody,
} from '../types/game-api'
import type { Reporter } from '../types/reporter'

interface EnemyReportSource extends PlaneCountData {
api_eParam?: number[][]
Expand Down Expand Up @@ -111,7 +112,7 @@ const makeEnemyReport = (data: EnemyReportSource = {}) => {
}
}

export default class DropShipReporter extends BaseReporter {
export default class DropShipReporter extends BaseReporter implements Reporter {
mapLv: number[]
drop: DropReport | null
ownedShipSnapshot: Record<string, number[]> | null
Expand Down
3 changes: 2 additions & 1 deletion src/reporters/night-battle-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
GameApiPostBody,
GameApiResponseBody,
} from '../types/game-api'
import type { Reporter } from '../types/reporter'

interface NightBattleShip {
api_kyouka: number[]
Expand Down Expand Up @@ -47,7 +48,7 @@ interface NightBattleCIBody {
type ShipSelectorResult = [Partial<NightBattleShip>?, Partial<NightBattleShip>?]
type EquipSelectorResult = Array<[Partial<NightBattleEquip>?, Partial<NightBattleEquip>?, unknown?]>

export default class NightBattleCIReporter extends BaseReporter {
export default class NightBattleCIReporter extends BaseReporter implements Reporter {
processData = (body: NightBattleCIBody, time: number) => {
const state = window.getStore()

Expand Down
3 changes: 2 additions & 1 deletion src/reporters/night-contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
GameApiPostBody,
GameApiResponseBody,
} from '../types/game-api'
import type { Reporter } from '../types/reporter'
import { getWindowShip, getWindowSlotItem } from '../types/window-state'
import type { WindowShip, WindowSlotItem } from '../types/window-state'

Expand All @@ -15,7 +16,7 @@ import type { WindowShip, WindowSlotItem } from '../types/window-state'
// 2. Only one contactable plane equipped.
// 3. Plane level must be equal or larger than 0.
// 4. Plane count must larger than 0.
export default class NightContactReportor extends BaseReporter {
export default class NightContactReportor extends BaseReporter implements Reporter {
VALID_PLANE_ID: number
isValid: boolean | null

Expand Down
3 changes: 2 additions & 1 deletion src/reporters/quest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
GameApiPostBody,
GameApiResponseBody,
} from '../types/game-api'
import type { Reporter } from '../types/reporter'

const createHash = _.memoize((text: string) => crypto.createHash('md5').update(text).digest('hex'))

Expand All @@ -34,7 +35,7 @@ type QuestRewardPostBody = Pick<
> &
Record<`api_select_no${number}`, string | undefined>

export default class QuestReporter extends BaseReporter {
export default class QuestReporter extends BaseReporter implements Reporter {
knownQuests: string[]
enabled: boolean
quests: QuestWithKey[]
Expand Down
3 changes: 2 additions & 1 deletion src/reporters/remodel-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
GameApiPostBody,
GameApiResponseBody,
} from '../types/game-api'
import type { Reporter } from '../types/reporter'

type RemodelItemDetailPostBody = {
api_slot_id: string | number
Expand All @@ -22,7 +23,7 @@ type RemodelItemSlotBody = Pick<APIReqKousyouRemodelSlotResponse, 'api_remodel_i
}

// Stopped at 2016.11.28. We have collected 800k records.
export default class RemodelItemReporter extends BaseReporter {
export default class RemodelItemReporter extends BaseReporter implements Reporter {
itemId: string | number

constructor() {
Expand Down
3 changes: 2 additions & 1 deletion src/reporters/remodel-recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
GameApiPostBody,
GameApiResponseBody,
} from '../types/game-api'
import type { Reporter } from '../types/reporter'
import { parseInt10 } from '../types/window-state'

type RemodelRecipeListItem = Pick<
Expand Down Expand Up @@ -212,7 +213,7 @@ const toCostPayload = (detail: CurrentDetail): ItemImprovementCostPayload => ({
})

// Collecting remodel recipes
export default class RemodelRecipeReporter extends BaseReporter {
export default class RemodelRecipeReporter extends BaseReporter implements Reporter {
id: number
itemId: number
itemLevel: number
Expand Down
3 changes: 2 additions & 1 deletion src/reporters/ship-stat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
GameApiPostBody,
GameApiResponseBody,
} from '../types/game-api'
import type { Reporter } from '../types/reporter'

type ShipStatShip = Pick<
APIShipData,
Expand All @@ -24,7 +25,7 @@ interface ShipStatResponseBody {
api_ship_data?: ShipStatShip[]
}

export default class ShipStatReporter extends BaseReporter {
export default class ShipStatReporter extends BaseReporter implements Reporter {
handle = (
method: GameApiMethod,
path: GameApiPath,
Expand Down
2 changes: 1 addition & 1 deletion src/types/game-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type GameApiMethod = string
export type GameApiPath = string
export type GameApiPostBody = Record<string, string | undefined>
export type GameApiPostBody = Record<string, string | number | undefined>
export type GameApiResponseBody = unknown

export interface GameResponseEventDetail {
Expand Down
2 changes: 1 addition & 1 deletion src/types/vendor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare module '@sentry/electron' {
}

declare module 'electron' {
const electron: any
const electron: unknown
export = electron
}

Expand Down
Loading
Loading