From cbfa2933850a8f31069079f02611ef0645565473 Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Thu, 29 Sep 2022 08:58:07 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E8=A1=A5=E5=85=85`ysa`=E8=A7=92?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/utils/typing.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/LittlePaimon/utils/typing.py b/LittlePaimon/utils/typing.py index b6eebd3..e7bb7a0 100644 --- a/LittlePaimon/utils/typing.py +++ b/LittlePaimon/utils/typing.py @@ -1,4 +1,10 @@ -from typing import Literal +from typing import Literal, List +from pydantic import BaseModel, parse_raw_as +try: + import ujson as json +except ImportError: + import json + ElementType = Literal['火', '水', '冰', '雷', '风', '岩', '草', '物理'] WeaponType = Literal['单手剑', '双手剑', '长柄武器', '弓', '法器'] @@ -15,15 +21,15 @@ CN_NUMBER = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九 CHARACTERS = ['神里绫华', '琴', '丽莎', '芭芭拉', '凯亚', '迪卢克', '雷泽', '安柏', '温迪', '香菱', '北斗', '行秋', '魈', '凝光', '可莉', '钟离', '菲谢尔', '班尼特', '达达利亚', '诺艾尔', '七七', '重云', '甘雨', '阿贝多', '迪奥娜', '莫娜', '刻晴', '砂糖', '辛焱', '罗莎莉亚', '胡桃', '枫原万叶', '烟绯', '宵宫', '托马', '优菈', '雷电将军', '早柚', '珊瑚宫心海', '五郎', '九条裟罗', '荒泷一斗', '八重神子', '夜兰', '埃洛伊', - '申鹤', '云堇', '久岐忍', '神里绫人', '鹿野院平藏', '提纳里', '柯莱', '多莉'] + '申鹤', '云堇', '久岐忍', '神里绫人', '鹿野院平藏', '提纳里', '柯莱', '多莉', '赛诺', '坎蒂丝'] """全角色""" MALE_CHARACTERS = ['凯亚', '迪卢克', '钟离', '达达利亚', '托马', '荒泷一斗', '神里绫人'] """成男角色""" -FEMALE_CHARACTERS = ['琴', '丽莎', '北斗', '凝光', '罗莎莉亚', '优菈', '雷电将军', '九条裟罗', '八重神子', '夜兰', '申鹤'] +FEMALE_CHARACTERS = ['琴', '丽莎', '北斗', '凝光', '罗莎莉亚', '优菈', '雷电将军', '九条裟罗', '八重神子', '夜兰', '申鹤', '坎蒂丝'] """成女角色""" GIRL_CHARACTERS = ['神里绫华', '芭芭拉', '安柏', '香菱', '菲谢尔', '诺艾尔', '甘雨', '莫娜', '刻晴', '砂糖', '辛焱', '胡桃', '烟绯', '宵宫', '珊瑚宫心海', '埃洛伊', '云堇', '久岐忍', '柯莱'] """少女角色""" -BOY_CHARACTERS = ['雷泽', '温迪', '行秋', '魈', '班尼特', '重云', '阿贝多', '枫原万叶', '五郎', '鹿野院平藏', '提纳里'] +BOY_CHARACTERS = ['雷泽', '温迪', '行秋', '魈', '班尼特', '重云', '阿贝多', '枫原万叶', '五郎', '鹿野院平藏', '提纳里', '赛诺'] """少男角色""" LOLI_CHARACTERS = ['七七', '可莉', '迪奥娜', '早柚', '多莉'] """萝莉""" @@ -31,3 +37,13 @@ LOLI_CHARACTERS = ['七七', '可莉', '迪奥娜', '早柚', '多莉'] CHARA_RE = '|'.join(CHARACTERS) +class PydanticListModel(BaseModel): + @classmethod + def encoder(cls, models: List['PydanticListModel']): + return json.dumps(models, default=cls.dict) + + @classmethod + def decoder(cls, json_data: str): + return parse_raw_as(List[cls], json_data) + +