diff options
| author | Kyomotoi <1172294279@qq.com> | 2020-11-08 17:46:06 +0800 | 
|---|---|---|
| committer | Kyomotoi <1172294279@qq.com> | 2020-11-08 17:46:06 +0800 | 
| commit | 1198545d5927c1645b25a9810aba302b42faa838 (patch) | |
| tree | d2d31323102d1db64c8eecaeee94501c36af9412 /ATRI/plugins/plugin_utils | |
| parent | 6c36a3daafeafe2f2fab6c83c09e1d3f998a490e (diff) | |
| download | ATRI-1198545d5927c1645b25a9810aba302b42faa838.tar.gz ATRI-1198545d5927c1645b25a9810aba302b42faa838.tar.bz2 ATRI-1198545d5927c1645b25a9810aba302b42faa838.zip  | |
[Update]
Diffstat (limited to 'ATRI/plugins/plugin_utils')
| -rw-r--r-- | ATRI/plugins/plugin_utils/__init__.py | 53 | ||||
| -rw-r--r-- | ATRI/plugins/plugin_utils/generate.py | 47 | 
2 files changed, 56 insertions, 44 deletions
diff --git a/ATRI/plugins/plugin_utils/__init__.py b/ATRI/plugins/plugin_utils/__init__.py index 4435b81..9d29a82 100644 --- a/ATRI/plugins/plugin_utils/__init__.py +++ b/ATRI/plugins/plugin_utils/__init__.py @@ -10,14 +10,9 @@  '''  __author__ = 'kyomotoi' -import os  import re -import json  import random -from pathlib import Path  from time import strftime -from zipfile import PyZipFile -from typing import Tuple, Dict, List  from datetime import datetime, timedelta  from nonebot.plugin import on_command @@ -27,44 +22,9 @@ from utils.utils_error import errorRepo  from utils.utils_rule import check_banlist, check_switch  from .roll import roll_dice +from .generate import infoID, numberID  from .genshin import GetInfo, JsonAnalysis -file = Path('.') / 'ATRI' / 'data' / 'data_IDcard' / 'main.bin' - - -def infoID() -> Tuple[Dict[str, List[str]], Dict[str, str]]: -    with PyZipFile(os.path.abspath(file), "r") as zipFile: -        with zipFile.open("name.json", "r") as f: -            name = json.loads(f.read().decode()) -        with zipFile.open("area.json", "r") as f: -            area = json.loads(f.read().decode()) -    return name, area - - -NAME, AREA = infoID() - -BIRTH_BEGIN = datetime(*[1980, 10, 10])  # type: ignore -BIRTH_END = datetime(*[2002, 10, 10])  # type: ignore - - -def numberID(area: int, sex: int, birth: int) -> str: -    def checkSum(fullCode: str) -> int or str: -        assert len(fullCode) == 17 -        checkSum = sum([((1 << (17 - i)) % 11) * int(fullCode[i]) -                        for i in range(0, 17)]) -        checkDigit = (12 - (checkSum % 11)) % 11 -        if checkDigit < 10: -            return checkDigit -        else: -            return "X" - -    orderCode = str(random.randint(10, 99)) -    sexCode = str(random.randrange(sex, 10, step=2)) -    fullCode = str(area) + str(birth) + str(orderCode) + str(sexCode) -    fullCode += str(checkSum(fullCode)) -    return fullCode - -  plugin_name_0 = "one-key-adult"  generateID = on_command("我要转大人,一天打25小时游戏",                          rule=check_banlist() & check_switch(plugin_name_0)) @@ -72,6 +32,11 @@ generateID = on_command("我要转大人,一天打25小时游戏",  @generateID.handle()  # type: ignore  async def _(bot: Bot, event: Event, state: dict) -> None: +    NAME, AREA = infoID() + +    BIRTH_BEGIN = datetime(*[1980, 10, 10])  # type: ignore +    BIRTH_END = datetime(*[2002, 10, 10])  # type: ignore +      id_card_area = int(random.choice(list(AREA.keys())))      id_card_area_name = AREA[str(id_card_area)]      id_card_year_old = timedelta( @@ -80,7 +45,7 @@ async def _(bot: Bot, event: Event, state: dict) -> None:                                   (BIRTH_BEGIN + id_card_year_old).timetuple())      id_card_sex = random.choice([0, 1])      id_card_name = random.choice(NAME[{0: "female", 1: "male"}[id_card_sex]]) -    id_card_id = numberID(id_card_area, id_card_sex, id_card_birth_day) +    id_card_id = numberID(id_card_area, id_card_sex, id_card_birth_day) # type: ignore      msg0 = "恭喜,你已经成大人了!\n"      msg0 += "这是你一天25h游戏的通行证:\n" @@ -133,14 +98,14 @@ async def _(bot: Bot, event: Event, state: dict) -> None:  async def _(bot: Bot, event: Event, state: dict) -> None:      uid = str(state['uid']) -    if (len(uid) == 9 and uid[0] == '1'): +    if (len(uid) == 9):          await bot.send(event, '别急,在搜索了!')          uid_info = ''          try:              uid_info = JsonAnalysis(GetInfo(uid))          except: -            await genshinInfo.finish(errorRepo("数据请求错误,原因可能为ID输入错误或不存在")) +            await genshinInfo.finish(errorRepo("数据请求错误,原因可能为ID输入错误或不存在\n暂时只支持国服查询("))          msg0 = f'{uid} Genshin Info:\n'          msg0 += uid_info diff --git a/ATRI/plugins/plugin_utils/generate.py b/ATRI/plugins/plugin_utils/generate.py new file mode 100644 index 0000000..9472f93 --- /dev/null +++ b/ATRI/plugins/plugin_utils/generate.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8 -*- +''' +@File    :   generateID.py +@Time    :   2020/11/08 10:35:09 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi' + +import os +import json +import random +from pathlib import Path +from zipfile import PyZipFile +from typing import Tuple, Dict, List + +file = Path('.') / 'ATRI' / 'data' / 'data_IDcard' / 'main.bin' + + +def infoID() -> Tuple[Dict[str, List[str]], Dict[str, str]]: +    with PyZipFile(os.path.abspath(file), "r") as zipFile: +        with zipFile.open("name.json", "r") as f: +            name = json.loads(f.read().decode()) +        with zipFile.open("area.json", "r") as f: +            area = json.loads(f.read().decode()) +    return name, area + + +def numberID(area: int, sex: int, birth: int) -> str: +    def checkSum(fullCode: str) -> int or str: +        assert len(fullCode) == 17 +        checkSum = sum([((1 << (17 - i)) % 11) * int(fullCode[i]) +                        for i in range(0, 17)]) +        checkDigit = (12 - (checkSum % 11)) % 11 +        if checkDigit < 10: +            return checkDigit +        else: +            return "X" # type: ignore + +    orderCode = str(random.randint(10, 99)) +    sexCode = str(random.randrange(sex, 10, step=2)) +    fullCode = str(area) + str(birth) + str(orderCode) + str(sexCode) +    fullCode += str(checkSum(fullCode)) +    return fullCode  | 
