Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
更换数据源 [@issue/42](#42)
更新数据键值对
修复了使用 `ghproxy` 作为 github 镜像时无法获取数据的问题
添加了删表重写功能
修复了从 maa 作业站自动推送作业出错的问题
  • Loading branch information
NumberSir committed May 4, 2023
1 parent 7426671 commit 6012b0e
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 35 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ xxx/yyy 代表 xxx 或 yyy
方舟帮助 / arkhelp => 查看指令列表
更新方舟素材 => 手动更新游戏数据(json)与图片
更新方舟数据库 => 手动更新数据库
更新方舟数据库 -D => 删除原数据库各表并重新写入
```
猜干员
```text
Expand Down Expand Up @@ -259,7 +260,6 @@ maa查作业 [关键词1 关键词2 ...] | [热度/最新/访问] => 同上,

# 感谢
- __[yuanyan3060](https://github.com/yuanyan3060)____[明日方舟常用素材库](https://github.com/yuanyan3060/Arknights-Bot-Resource)__
- __[Kengxxiao](https://github.com/Kengxxiao)____[《明日方舟》游戏数据库](https://github.com/Kengxxiao/ArknightsGameData)__
- __[Aceship](https://github.com/Aceship)____[Arknight-Images](https://github.com/Aceship/Arknight-Images)__
- __[AmiyaBot](https://github.com/AmiyaBot)____[Amiya-bot](https://github.com/AmiyaBot/Amiya-Bot)__
- __[Strelizia02](https://github.com/Strelizia02)____[AngelinaBot](https://github.com/Strelizia02/AngelinaBot)__
Expand All @@ -269,6 +269,13 @@ maa查作业 [关键词1 关键词2 ...] | [热度/最新/访问] => 同上,
<details>
<summary>点击展开</summary>

> 2023-05-04 v1.2.0
> - 更换数据源 [@issue/42](https://github.com/NumberSir/nonebot_plugin_arktools/issues/42)
> - 更新数据键值对
> - 修复了使用 `ghproxy` 作为 github 镜像时无法获取数据的问题
> - 添加了删表重写功能
> - 修复了从 maa 作业站自动推送作业出错的问题
>
> 2023-04-15 v1.1.0
> - 公招查询、猜干员、理智提醒现在均可以私聊进行 (不推荐,私聊发消息可能导致风控)
> - 简易修复了与其它同用 Tortoise-ORM 的插件初始化冲突的问题 [@zx-issue/15](https://github.com/NumberSir/zhenxun_arktools/issues/15)
Expand All @@ -286,7 +293,7 @@ maa查作业 [关键词1 关键词2 ...] | [热度/最新/访问] => 同上,
>
> 2023-04-04 v1.0.17
> - 添加数据库初始化检查,不再每次启动bot时重复创建
> - 添加每次启动bot时的数据更新检查开关,默认启用 [@issue/39](https://github.com/NumberSir/nonebot_plugin_arktools/issues/39)
> - 添加每次启动 bot 时的数据更新检查开关,默认启用 [@issue/39](https://github.com/NumberSir/nonebot_plugin_arktools/issues/39)
>
> 2023-03-28 v1.0.15
> - 猜干员与干员信息功能可以使用干员昵称(可自行增删改查)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,5 +531,11 @@
"斯卡蒂": [
"蒂蒂",
"蓝蒂"
],
"缪尔赛思": [
"缪缪"
],
"霍尔海雅": [
"蛇蛇"
]
}
4 changes: 2 additions & 2 deletions nonebot_plugin_arktools/src/core/models_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,15 +1231,15 @@ def level_up_cost_condition(self) -> List["SkillLevelUpCondition"]:
raise NotImplementedError("未输入干员数据!")
return [
SkillLevelUpCondition(skill=self, data=d)
for d in self._extra_data["levelUpCostCond"]
for d in self._extra_data["specializeLevelUpData"]
]

@property
def unlock_condition(self) -> "CharacterUnlockCondition":
"""解锁(phase, level)"""
if not self._extra_data:
raise NotImplementedError("未输入干员数据!")
return CharacterUnlockCondition(data=self._extra_data["unlockCond"])
return CharacterUnlockCondition(data=self._extra_data["initialUnlockCond"])

# 不在 arknights_skill_table 中的
@property
Expand Down
7 changes: 7 additions & 0 deletions nonebot_plugin_arktools/src/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ def __init__(self, msg: str = "没有查询到结果!", details: str = ""):
super().__init__(msg, details)


class NoHandbookInfoException(ArkBaseException):
"""没有档案"""
def __init__(self, msg: str = "干员没有档案!", details: str = ""):
super().__init__(msg, details)


__all__ = [
"NamedCharacterNotExistException",
"NamedPoolNotExistException",
"NoHandbookInfoException",

"MAAFailedResponseException",
"MAANoResultException"
Expand Down
14 changes: 9 additions & 5 deletions nonebot_plugin_arktools/src/misc_operator_birthday/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from io import BytesIO

from ..core.models_v3 import Character
from ..exceptions import NoHandbookInfoException
from ..utils import text_border
from ..configs.path_config import PathConfig

Expand All @@ -26,12 +27,15 @@
async def _():
today = datetime.now().strftime("%m月%d日").strip("0").replace("月0", "月")
characters = await Character.all()
try:
results: List["Character"] = [
cht
for cht in characters
if (await cht.get_handbook_info()).story_text_audio.birthday == today
]
except NoHandbookInfoException as e:
await today_birthday.finish(f"嗯唔……干员的档案数据不全哦")

results: List["Character"] = [
cht
for cht in characters
if (await cht.get_handbook_info()).story_text_audio.birthday == today
]
if not results:
await today_birthday.finish("哦呀?今天没有干员过生日哦……")
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import random
from io import BytesIO
from datetime import datetime
from typing import List, Dict, Tuple, Optional

import httpx
Expand Down Expand Up @@ -58,7 +59,7 @@ async def process_works(works: List[Dict], keyword: str) -> Optional[Tuple[Bytes
work = works[0]
local_data = await MAACopilotSubsModel.filter(sub_keyword=keyword).first()
local_upload_time = local_data.latest_upload_time
latest_upload_time = work["upload_time"]
latest_upload_time = datetime.fromisoformat(work["upload_time"]).timestamp()

if latest_upload_time <= local_upload_time:
return None
Expand Down
8 changes: 7 additions & 1 deletion nonebot_plugin_arktools/src/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from .update import *

from nonebot import on_command, logger
from nonebot.params import CommandArg
from nonebot.plugin import PluginMetadata
from nonebot.adapters.onebot.v11 import Message
import httpx


Expand All @@ -30,8 +32,11 @@ async def _():


@init_db.handle()
async def _():
async def _(args: Message = CommandArg()):
await update_game_resource.send("开始更新游戏数据库,视磁盘读写性能需1分钟左右……")
if args.extract_plain_text().strip() == "-D":
await ArknightsDB.drop_data()
await update_game_resource.send("已彻底删除原表,开始重新写入数据库……")
await ArknightsDB.init_data(force=True)
await update_game_resource.finish("游戏数据库更新完成!")

Expand All @@ -44,6 +49,7 @@ async def _():
"\n 方舟帮助 => 查看指令列表"
"\n 更新方舟素材 => 从Github下载游戏素材(json数据与图片)"
"\n 更新方舟数据库 => 更新本地sqlite数据库"
"\n 更新方舟数据库 -D => 删除原数据库各表并重新写入"
),
extra={
"name": "update_plugin_data",
Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_arktools/src/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def init_data(force: bool = False):
await ArknightsDB._init_skill(force)
await ArknightsDB._init_skin(force)
await ArknightsDB._init_stage(force)
except (tortoise.exceptions.OperationalError, tortoise.exceptions.FieldError) as e:
except tortoise.exceptions.BaseORMException as e:
logger.error(f"数据库初始化出错: {e}")
await ArknightsDB.drop_data()
await ArknightsDB.init_db()
Expand Down Expand Up @@ -292,7 +292,7 @@ async def _init_skill(force: bool = False):
SkillModel.update_or_create(
name=v["levels"][0]["name"],
skillType=v["levels"][0]["skillType"],
durationType=v["levels"][0]["skillType"],
durationType=v["levels"][0]["durationType"],
prefabId=v["levels"][0]["prefabId"],
**v
)
Expand Down
42 changes: 21 additions & 21 deletions nonebot_plugin_arktools/src/utils/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@
scfg = SchedulerConfig.parse_obj(get_driver().config.dict())

REPOSITORIES = {
"gamedata": "/Kengxxiao/ArknightsGameData/master",
"gamedata": "/yuanyan3060/ArknightsGameResource/master",
"gameimage_1": "/yuanyan3060/Arknights-Bot-Resource/master",
"gameimage_2": "/Aceship/Arknight-Images/master",
}

FILES = {
"gamedata": [
"zh_CN/gamedata/excel/building_data.json", # 基建技能,制造配方
"zh_CN/gamedata/excel/char_patch_table.json", # 升变阿米娅
"zh_CN/gamedata/excel/character_table.json", # 干员表
"zh_CN/gamedata/excel/data_version.txt", # 数据版本
"zh_CN/gamedata/excel/gamedata_const.json", # 游戏常数
"zh_CN/gamedata/excel/gacha_table.json", # 公招相关
"zh_CN/gamedata/excel/item_table.json", # 物品表
"zh_CN/gamedata/excel/handbook_info_table.json", # 档案表
"zh_CN/gamedata/excel/skill_table.json", # 技能表
"zh_CN/gamedata/excel/uniequip_table.json", # 模组表、子职业映射
"zh_CN/gamedata/excel/handbook_team_table.json", # 干员阵营
"zh_CN/gamedata/excel/skin_table.json", # 皮肤
"zh_CN/gamedata/excel/stage_table.json", # 关卡
"gamedata/excel/building_data.json", # 基建技能,制造配方
"gamedata/excel/char_patch_table.json", # 升变阿米娅
"gamedata/excel/character_table.json", # 干员表
"gamedata/excel/data_version.txt", # 数据版本
"gamedata/excel/gamedata_const.json", # 游戏常数
"gamedata/excel/gacha_table.json", # 公招相关
"gamedata/excel/item_table.json", # 物品表
"gamedata/excel/handbook_info_table.json", # 档案表
"gamedata/excel/skill_table.json", # 技能表
"gamedata/excel/uniequip_table.json", # 模组表、子职业映射
"gamedata/excel/handbook_team_table.json", # 干员阵营
"gamedata/excel/skin_table.json", # 皮肤
"gamedata/excel/stage_table.json", # 关卡
]
}

Expand Down Expand Up @@ -97,8 +97,8 @@ async def get_local_version(self) -> str:

async def get_latest_version(self) -> str:
"""获取最新版本"""
url = f"{self._url}/zh_CN/gamedata/excel/data_version.txt"
response = await self._client.get(url)
url = f"{self._url}/gamedata/excel/data_version.txt"
response = await self._client.get(url, follow_redirects=True)
return response.text.split(":")[-1].strip("\n").strip() # eg: "31.4.0"

async def is_update_needed(self) -> bool:
Expand All @@ -120,7 +120,7 @@ async def download_files(self):

async def save(self, url: str, file: str, tmp: Path):
"""异步gather用"""
content = (await self._client.get(f"{url}/{file}", timeout=100)).content
content = (await self._client.get(f"{url}/{file}", timeout=100, follow_redirects=True)).content
async with aopen(tmp / file.split('/')[-1], "wb") as fp:
await fp.write(content)
logger.info(f"\t- Arknights-Data downloaded: {file.split('/')[-1]}")
Expand Down Expand Up @@ -209,13 +209,13 @@ async def download_files(self):

async def get_htmls(self, url: str, dir_: str):
"""异步gather用"""
html = (await self._client.get(url, timeout=100)).text
html = (await self._client.get(url, timeout=100, follow_redirects=True)).text
self._htmls[dir_] = (html, url)

async def save(self, url: str, tmp: Path):
"""异步gather用"""
# print(url)
content = (await self._client.get(quote(url, safe="/:"), timeout=100)).content
content = (await self._client.get(quote(url, safe="/:"), timeout=100, follow_redirects=True)).content
if not url.endswith(".png"):
return
async with aopen(tmp / unquote(url).split('/master/')[-1], "wb") as fp:
Expand All @@ -241,7 +241,7 @@ async def download_extra_files(client: httpx.AsyncClient):
path = url.split("/data/")[-1]
if (data_path / path).exists():
continue
response = await client.get(url)
response = await client.get(url, follow_redirects=True)
async with aopen(data_path / path, "wb") as fp:
await fp.write(response.content)
logger.info(f"\t- Extra file downloaded: {path}")
Expand All @@ -260,7 +260,7 @@ async def download_fonts(client: httpx.AsyncClient):
path = url.split("/")[-1]
if (font_path / path).exists():
continue
response = await client.get(url)
response = await client.get(url, follow_redirects=True)
async with aopen(font_path / path, "wb") as fp:
await fp.write(response.content)
logger.info(f"\t- Font file downloaded: {path}")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="nonebot_plugin_arktools",
version="1.1.0",
version="1.2.0",
author="Number_Sir",
author_email="Number_Sir@126.com",
keywords=["pip", "nonebot2", "nonebot", "nonebot_plugin"],
Expand Down

0 comments on commit 6012b0e

Please sign in to comment.