diff options
author | Kyomotoi <[email protected]> | 2020-11-08 17:46:06 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2020-11-08 17:46:06 +0800 |
commit | 1198545d5927c1645b25a9810aba302b42faa838 (patch) | |
tree | d2d31323102d1db64c8eecaeee94501c36af9412 | |
parent | 6c36a3daafeafe2f2fab6c83c09e1d3f998a490e (diff) | |
download | ATRI-1198545d5927c1645b25a9810aba302b42faa838.tar.gz ATRI-1198545d5927c1645b25a9810aba302b42faa838.tar.bz2 ATRI-1198545d5927c1645b25a9810aba302b42faa838.zip |
[Update]
-rw-r--r-- | .env.dev | 1 | ||||
-rw-r--r-- | ATRI/plugins/plugin_utils/__init__.py | 53 | ||||
-rw-r--r-- | ATRI/plugins/plugin_utils/generate.py | 47 | ||||
-rw-r--r-- | bot.py | 14 | ||||
-rw-r--r-- | check.py | 4 |
5 files changed, 64 insertions, 55 deletions
diff --git a/.env.dev b/.env.dev deleted file mode 100644 index 719ba19..0000000 --- a/.env.dev +++ /dev/null @@ -1 +0,0 @@ -COMMAND_START=["", "/"]
\ No newline at end of file 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 : [email protected] +@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 @@ -31,7 +31,6 @@ time.sleep(1) # 检查是否符合条件运行 checkATRI() -time.sleep(1) # 读取配置 CONFIG_PATH = Path('.') / 'config.yml' @@ -39,10 +38,11 @@ config = load_yaml(CONFIG_PATH) config = config['bot'] # 初始化 -nonebot.init(DEBUG=config['debug'], - SUPERUSSERS=config['superusers'], - NICKNAME=config['nickname'], - COMMAND_SEP=config['command_sep']) +nonebot.init(debug=bool(config['debug']), + superusers=set(config['superusers']), + nickname=set(config['nickname']), + command_start=set(config['command_start']), + command_sep=set(config['command_sep'])) app = nonebot.get_asgi() # 读取插件目录 @@ -71,6 +71,4 @@ logger.add(LOGGER_ERROR_PATH, format=default_format) if __name__ == '__main__': - nonebot.run(app='bot:app', - host=config['host'], - port=config['port']) + nonebot.run(app='bot:app', host=config['host'], port=config['port']) @@ -42,8 +42,8 @@ class checkATRI(): bot = config['bot'] for key in bot: if key == 'debug': - if bot['debug'] != False: - logger.warring('DEBUG open.') + if bot['debug'] != 0: + logger.warning('DEBUG open.') progress.update(task, advance=1) time.sleep(0.2) else: |