add guard against improperly structured json
This commit is contained in:
parent
b7c8f011dc
commit
328d697873
20
package-lock.json
generated
20
package-lock.json
generated
@ -1,17 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "notmudae",
|
"name": "2023collectabot",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "notmudae",
|
"name": "2023collectabot",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.8.0",
|
"discord.js": "^14.8.0",
|
||||||
"sequelize": "^6.30.0",
|
"sequelize": "^6.30.0",
|
||||||
"sqlite3": "^5.1.6"
|
"sqlite3": "^5.1.6",
|
||||||
|
"zod": "^3.21.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.15.11",
|
"@types/node": "^18.15.11",
|
||||||
@ -1600,6 +1601,14 @@
|
|||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
||||||
|
},
|
||||||
|
"node_modules/zod": {
|
||||||
|
"version": "3.21.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz",
|
||||||
|
"integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -2770,6 +2779,11 @@
|
|||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
||||||
|
},
|
||||||
|
"zod": {
|
||||||
|
"version": "3.21.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz",
|
||||||
|
"integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.8.0",
|
"discord.js": "^14.8.0",
|
||||||
"sequelize": "^6.30.0",
|
"sequelize": "^6.30.0",
|
||||||
"sqlite3": "^5.1.6"
|
"sqlite3": "^5.1.6",
|
||||||
|
"zod": "^3.21.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import charactersJSON from './characters.json'
|
|
||||||
import { Collection } from 'discord.js'
|
import { Collection } from 'discord.js'
|
||||||
|
import charactersJSON from './characters.json';
|
||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
export enum Target {
|
export enum Target {
|
||||||
Self = "self",
|
Self = "self",
|
||||||
@ -10,41 +11,53 @@ export enum Target {
|
|||||||
TrueRandomOpponent = "trueRandomOpponent"
|
TrueRandomOpponent = "trueRandomOpponent"
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PotencyStatus {
|
const TargetEnum = z.nativeEnum(Target);
|
||||||
duration: number
|
type TargetEnum = z.infer<typeof TargetEnum>;
|
||||||
potency: number
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Effect {
|
const PotencyStatus = z.object({
|
||||||
target: Target
|
duration: z.number().int(),
|
||||||
accuracy?: number
|
potency: z.number().int()
|
||||||
damage?: number
|
});
|
||||||
heal?: number
|
export type PotencyStatus = z.infer<typeof PotencyStatus>;
|
||||||
poison?: number
|
|
||||||
regeneration?: number
|
|
||||||
burn?: number
|
|
||||||
confusion?: number
|
|
||||||
stun?: number
|
|
||||||
resistanceChange?: PotencyStatus
|
|
||||||
accuracyChange?: PotencyStatus
|
|
||||||
speedChange?: PotencyStatus
|
|
||||||
function?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Skill {
|
const Effect = z.object({
|
||||||
name: string
|
target: TargetEnum,
|
||||||
accuracy?: number
|
accuracy: z.number().int(),
|
||||||
effects: Effect[]
|
damage: z.optional(z.number().int()),
|
||||||
}
|
heal: z.optional(z.number().int()),
|
||||||
|
poison: z.optional(z.number().int()),
|
||||||
|
regeneration: z.optional(z.number().int()),
|
||||||
|
burn: z.optional(z.number().int()),
|
||||||
|
confusion: z.optional(z.number().int()),
|
||||||
|
stun: z.optional(z.number().int()),
|
||||||
|
resistanceChange: z.optional(z.number().int()),
|
||||||
|
accuracyChange: z.optional(z.number().int()),
|
||||||
|
speedChange: z.optional(z.number().int()),
|
||||||
|
function: z.string()
|
||||||
|
});
|
||||||
|
type Effect = z.infer<typeof Effect>;
|
||||||
|
|
||||||
export interface Character {
|
const Skill = z.object({
|
||||||
id: number
|
name: z.string(),
|
||||||
name: string
|
accuracy: z.number().int(),
|
||||||
nameShort: string
|
effects: z.array(Effect)
|
||||||
img: string
|
});
|
||||||
health: number
|
type Skill = z.infer<typeof Skill>;
|
||||||
speed: number
|
|
||||||
skills: [Skill, Skill, Skill]
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CHARACTERS: Collection<number, Character> = new Collection(charactersJSON.map((element, index) => {return [index, element as Character]}));
|
const Character = z.object({
|
||||||
|
id: z.number().int(),
|
||||||
|
name: z.string(),
|
||||||
|
nameShort: z.string(),
|
||||||
|
img: z.string(),
|
||||||
|
health: z.number().int(),
|
||||||
|
speed: z.number().int(),
|
||||||
|
skills: z.array(Skill)
|
||||||
|
});
|
||||||
|
export type Character = z.infer<typeof Character>;
|
||||||
|
|
||||||
|
const CharacterJSON = z.array(Character);
|
||||||
|
type CharacterJSON = z.infer<typeof CharacterJSON>;
|
||||||
|
|
||||||
|
export const CHARACTERS: Collection<number, Character> = (() => {
|
||||||
|
return new Collection(CharacterJSON.parse(charactersJSON).map((element, index) => {return [index, element]}));
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user