diff --git a/nonebot_plugin_ocgbot_v2/__init__.py b/nonebot_plugin_ocgbot_v2/__init__.py index 57dd0b9..7f6b977 100644 --- a/nonebot_plugin_ocgbot_v2/__init__.py +++ b/nonebot_plugin_ocgbot_v2/__init__.py @@ -1,12 +1,12 @@ import asyncio import json import os.path +from pathlib import Path from threading import Thread import httpx from nonebot import logger, get_driver from nonebot_plugin_ocgbot_v2.libraries.forbideGet import forbiddenGet -from nonebot_plugin_ocgbot_v2.libraries.globalMessage import json_path, pics_path, static_path_abso, deck_path, \ - font_path +from nonebot_plugin_ocgbot_v2.libraries.globalMessage import json_path, pics_path, deck_path, font_path from nonebot_plugin_ocgbot_v2.libraries.staticvar import nick_name_0, nick_name_1, forbidden, daily_card from nonebot.plugin import PluginMetadata import nonebot_plugin_ocgbot_v2.data_update @@ -62,7 +62,7 @@ def save(wj_path: str, img: bytes): async def download(base_url, folder_path, file_name): - file_path = folder_path + file_name + file_path = folder_path / file_name byte = await download_url(base_url + file_name) save(file_path, byte) logger.info(f"文件{file_name}下载成功") @@ -70,38 +70,39 @@ async def download(base_url, folder_path, file_name): # 卡运专用 async def download_img(files_path, file_name, deck): - wj_path = files_path + "/" + file_name - if not os.path.exists(wj_path): + wj_path = files_path / file_name + if not wj_path.exists(): byte = await download_url(deck_url + f"{deck}/{file_name}") save(wj_path, byte) logger.info(f"图片{file_name}下载成功") def deckDownloadInit(): - deck_json = deck_path + "deck_list.json" - if not os.path.exists(deck_json): + deck_json = Path(deck_path) / "deck_list.json" + if not deck_json.exists(): return with open(deck_json, 'r', encoding='utf-8') as f: js = json.loads(f.read()) for deck in js['list']: - wjs_path = deck_path + deck - if not os.path.exists(wjs_path): + wjs_path = Path(deck_path) / deck + if not wjs_path.exists(): logger.info("文件夹decks/" + deck + " 不存在,已经创建") - os.mkdir(wjs_path) + wjs_path.mkdir(parents=True, exist_ok=True) for wj in js['list'][deck]: asyncio.run(download_img(wjs_path, wj, deck)) def fontDownloadInit(): for font in fonts: - if not os.path.exists(font_path + font): + if not (Path(font_path) / font).exists(): logger.info(f"字体文件{font}缺失,正在下载") - asyncio.run(download(font_url, font_path, font)) + asyncio.run(download(font_url, Path(font_path), font)) font_init() + logger.info(f"字体初始化完成") async def nickNameInit(): - nick_path = json_path + "nickname.json" + nick_path = Path(json_path) / "nickname.json" try: # 尝试读取 with open(nick_path, 'r', encoding='utf-8') as f: @@ -118,7 +119,7 @@ async def nickNameInit(): async def forbideInit(): - forbide_path = json_path + "forbidden.json" + forbide_path = Path(json_path) / "forbidden.json" try: # 尝试读取 with open(forbide_path, 'r', encoding='utf-8') as f: @@ -133,7 +134,7 @@ async def forbideInit(): async def dailyInit(): - nick_path = json_path + "daily_card.json" + nick_path = Path(json_path) / "daily_card.json" try: # 尝试读取 with open(nick_path, 'r', encoding='utf-8') as f: @@ -155,9 +156,9 @@ async def download_init(): async def init(): logger.info("开始初始化") - if not os.path.exists(pics_path): + if not Path(pics_path).exists(): logger.info("未发现图片文件夹,已经创建") - os.mkdir(pics_path + "pics") + (Path(pics_path) / "pics").mkdir(parents=True, exist_ok=True) await download_init() await nickNameInit() await forbideInit() diff --git a/nonebot_plugin_ocgbot_v2/cardPieChart.py b/nonebot_plugin_ocgbot_v2/cardPieChart.py index 310ab3b..e5b2e66 100644 --- a/nonebot_plugin_ocgbot_v2/cardPieChart.py +++ b/nonebot_plugin_ocgbot_v2/cardPieChart.py @@ -1,4 +1,5 @@ import io +from pathlib import Path import numpy import httpx @@ -18,7 +19,7 @@ # json2 = '[{"name":"俱舍怒威族","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"1656","tags":["俱舍怒威族-魔里","俱舍怒威族-壹世坏","俱舍怒威族-次元场"],"matchup":{"first":{"decka":"俱舍怒威族","win":"1979","draw":"0","lose":"1273"},"second":{"deckb":"俱舍怒威族","win":"1593","draw":"0","lose":"1590"}}},{"name":"纯爱妖精","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"1633","tags":["纯爱妖精-拯救的桥梁","纯爱妖精-次元场","纯爱妖精-魔里"],"matchup":{"first":{"decka":"纯爱妖精","win":"1751","draw":"0","lose":"1231"},"second":{"deckb":"纯爱妖精","win":"1431","draw":"0","lose":"1449"}}},{"name":"救祓少女","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"1033","tags":["救祓少女-次元场","救祓少女-同调系","救祓少女-深渊之兽"],"matchup":{"first":{"decka":"救祓少女","win":"1081","draw":"0","lose":"768"},"second":{"deckb":"救祓少女","win":"928","draw":"0","lose":"864"}}},{"name":"地属性","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"1005","tags":["地属性-超重武者","地属性-割草","地属性-神殿守卫者"],"matchup":{"first":{"decka":"地属性","win":"1054","draw":"0","lose":"585"},"second":{"deckb":"地属性","win":"794","draw":"0","lose":"722"}}},{"name":"阿不思","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"958","tags":["阿不思-死狱乡","阿不思-深渊之兽","阿不思-教导"],"matchup":{"first":{"decka":"阿不思","win":"1075","draw":"0","lose":"802"},"second":{"deckb":"阿不思","win":"942","draw":"0","lose":"832"}}},{"name":"深渊之兽","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"935","tags":["深渊之兽-卫星闪灵","深渊之兽-同调士","深渊之兽-朋克"],"matchup":{"first":{"decka":"深渊之兽","win":"913","draw":"0","lose":"748"},"second":{"deckb":"深渊之兽","win":"901","draw":"0","lose":"723"}}},{"name":"神碑","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"896","tags":["神碑-削命","神碑-次元场","神碑-杯面"],"matchup":{"first":{"decka":"神碑","win":"996","draw":"0","lose":"689"},"second":{"deckb":"神碑","win":"855","draw":"0","lose":"728"}}},{"name":"超重武者","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"692","tags":["超重武者-深渊之兽","超重武者-PSY","超重武者-自奏圣乐"],"matchup":{"first":{"decka":"超重武者","win":"738","draw":"0","lose":"506"},"second":{"deckb":"超重武者","win":"609","draw":"0","lose":"521"}}},{"name":"拉比林斯迷宫","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"679","tags":["拉比林斯迷宫-强金","拉比林斯迷宫-病毒","拉比林斯迷宫-教导"],"matchup":{"first":{"decka":"拉比林斯迷宫","win":"663","draw":"0","lose":"548"},"second":{"deckb":"拉比林斯迷宫","win":"678","draw":"0","lose":"502"}}},{"name":"弹丸","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"664","tags":["弹丸-深渊之兽","弹丸-黑白龙","弹丸-割草"],"matchup":{"first":{"decka":"弹丸","win":"696","draw":"0","lose":"489"},"second":{"deckb":"弹丸","win":"578","draw":"0","lose":"547"}}},{"name":"魔救","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"569","tags":["魔救-割草","魔救-超重武者","魔救-杯面"],"matchup":{"first":{"decka":"魔救","win":"540","draw":"0","lose":"384"},"second":{"deckb":"魔救","win":"470","draw":"0","lose":"413"}}},{"name":"闪刀姬","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"518","tags":["闪刀姬-魔导","闪刀姬-神碑","闪刀姬-滤抽"],"matchup":{"first":{"decka":"闪刀姬","win":"335","draw":"0","lose":"491"},"second":{"deckb":"闪刀姬","win":"585","draw":"0","lose":"418"}}},{"name":"世坏","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"511","tags":["世坏-俱舍怒威族","世坏-卫星闪灵","世坏-深渊之兽"],"matchup":{"first":{"decka":"世坏","win":"511","draw":"0","lose":"471"},"second":{"deckb":"世坏","win":"529","draw":"0","lose":"420"}}},{"name":"电子界","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"475","tags":["电子界-斩机","电子界-诱发型"],"matchup":{"first":{"decka":"电子界","win":"447","draw":"0","lose":"372"},"second":{"deckb":"电子界","win":"439","draw":"0","lose":"313"}}},{"name":"铁兽","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"451","tags":["铁兽-卫星闪灵","铁兽-毒蛾"],"matchup":{"first":{"decka":"铁兽","win":"529","draw":"0","lose":"350"},"second":{"deckb":"铁兽","win":"412","draw":"0","lose":"391"}}},{"name":"相剑","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"437","tags":["相剑-超重武者","相剑-教导","相剑-杯面"],"matchup":{"first":{"decka":"相剑","win":"376","draw":"0","lose":"360"},"second":{"deckb":"相剑","win":"389","draw":"0","lose":"309"}}},{"name":"英雄","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"326","tags":["英雄-凤凰人","英雄-假面","英雄-神召"],"matchup":{"first":{"decka":"英雄","win":"218","draw":"0","lose":"294"},"second":{"deckb":"英雄","win":"295","draw":"0","lose":"172"}}},{"name":"EM魔术师","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"286","tags":["EM魔术师-杯面","EM魔术师-魔里","EM魔术师-毒蛾"],"matchup":{"first":{"decka":"EM魔术师","win":"265","draw":"0","lose":"275"},"second":{"deckb":"EM魔术师","win":"310","draw":"0","lose":"203"}}},{"name":"虫惑魔","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"284","tags":["虫惑魔-神碑","虫惑魔-超重武者","虫惑魔-兽带"],"matchup":{"first":{"decka":"虫惑魔","win":"261","draw":"0","lose":"243"},"second":{"deckb":"虫惑魔","win":"259","draw":"0","lose":"222"}}},{"name":"随风旅鸟","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"265","tags":["随风旅鸟-强金","随风旅鸟-次元场","随风旅鸟-天空龙"],"matchup":{"first":{"decka":"随风旅鸟","win":"293","draw":"0","lose":"226"},"second":{"deckb":"随风旅鸟","win":"315","draw":"1","lose":"222"}}},{"name":"恐啡肽狂龙","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"253","tags":["恐啡肽狂龙-病毒","恐啡肽狂龙-扎克","恐啡肽狂龙-削命"],"matchup":{"first":{"decka":"恐啡肽狂龙","win":"201","draw":"2","lose":"202"},"second":{"deckb":"恐啡肽狂龙","win":"199","draw":"0","lose":"146"}}},{"name":"影依","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"208","tags":["影依-白雪","影依-壹世坏","影依-割草"],"matchup":{"first":{"decka":"影依","win":"199","draw":"0","lose":"226"},"second":{"deckb":"影依","win":"244","draw":"0","lose":"181"}}},{"name":"双子","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"197","tags":["双子-AF","双子-毒蛾"],"matchup":{"first":{"decka":"双子","win":"196","draw":"0","lose":"168"},"second":{"deckb":"双子","win":"166","draw":"0","lose":"120"}}},{"name":"勇者同调系","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"180","tags":["勇者同调系-朋克","勇者同调系-白雪","勇者同调系-深渊之兽"],"matchup":{"first":{"decka":"勇者同调系","win":"162","draw":"0","lose":"149"},"second":{"deckb":"勇者同调系","win":"186","draw":"0","lose":"113"}}},{"name":"王战","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"165","tags":["王战-召唤兽","王战-源数","王战-强金"],"matchup":{"first":{"decka":"王战","win":"177","draw":"0","lose":"154"},"second":{"deckb":"王战","win":"189","draw":"0","lose":"142"}}},{"name":"雷龙","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"154","tags":["雷龙-深渊之兽","雷龙-朋克","雷龙-白雪"],"matchup":{"first":{"decka":"雷龙","win":"98","draw":"0","lose":"104"},"second":{"deckb":"雷龙","win":"118","draw":"0","lose":"80"}}},{"name":"海晶少女","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"152","tags":["海晶少女-冰水","海晶少女-御巫","海晶少女-灰篮"],"matchup":{"first":{"decka":"海晶少女","win":"147","draw":"0","lose":"122"},"second":{"deckb":"海晶少女","win":"125","draw":"0","lose":"114"}}},{"name":"迷之卡组","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"149","tags":[],"matchup":{"first":{"decka":"迷之卡组","win":"161","draw":"0","lose":"110"},"second":{"deckb":"迷之卡组","win":"162","draw":"0","lose":"145"}}},{"name":"御巫","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"142","tags":["御巫-坏兽","御巫-强金","御巫-勇者"],"matchup":{"first":{"decka":"御巫","win":"70","draw":"0","lose":"69"},"second":{"deckb":"御巫","win":"245","draw":"0","lose":"214"}}},{"name":"卫星闪灵","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"137","tags":["卫星闪灵-深渊之兽","卫星闪灵-勇者","卫星闪灵-幻魔"],"matchup":{"first":{"decka":"卫星闪灵","win":"141","draw":"0","lose":"116"},"second":{"deckb":"卫星闪灵","win":"125","draw":"0","lose":"129"}}},{"name":"电脑堺","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"132","tags":["电脑堺-勇者","电脑堺-白雪","电脑堺-朋克"],"matchup":{"first":{"decka":"电脑堺","win":"163","draw":"0","lose":"152"},"second":{"deckb":"电脑堺","win":"169","draw":"0","lose":"107"}}},{"name":"龙剑士","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"121","tags":["龙剑士-威风妖怪","龙剑士-雾动机龙","龙剑士-超重武者"],"matchup":{"first":{"decka":"龙剑士","win":"108","draw":"0","lose":"110"},"second":{"deckb":"龙剑士","win":"92","draw":"0","lose":"84"}}},{"name":"旋风黑羽","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"118","tags":["旋风黑羽-深渊之兽","旋风黑羽-病毒"],"matchup":{"first":{"decka":"旋风黑羽","win":"82","draw":"0","lose":"92"},"second":{"deckb":"旋风黑羽","win":"108","draw":"0","lose":"79"}}},{"name":"自奏圣乐","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"111","tags":["自奏圣乐-废铁","自奏圣乐-朋克","自奏圣乐-深渊之兽"],"matchup":{"first":{"decka":"自奏圣乐","win":"104","draw":"0","lose":"101"},"second":{"deckb":"自奏圣乐","win":"129","draw":"0","lose":"98"}}},{"name":"六花","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"103","tags":["六花-圣天树","六花-兽带"],"matchup":{"first":{"decka":"六花","win":"129","draw":"0","lose":"96"},"second":{"deckb":"六花","win":"119","draw":"0","lose":"101"}}},{"name":"自然","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"100","tags":["自然-割草","自然-白雪","自然-神碑"],"matchup":{"first":{"decka":"自然","win":"163","draw":"0","lose":"149"},"second":{"deckb":"自然","win":"168","draw":"0","lose":"135"}}},{"name":"黄金国","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"92","tags":["黄金国-强金","黄金国-割草","黄金国-教导"],"matchup":{"first":{"decka":"黄金国","win":"93","draw":"0","lose":"101"},"second":{"deckb":"黄金国","win":"128","draw":"0","lose":"56"}}},{"name":"地中族","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"91","tags":["地中族-强金"],"matchup":{"first":{"decka":"地中族","win":"104","draw":"0","lose":"101"},"second":{"deckb":"地中族","win":"77","draw":"0","lose":"84"}}},{"name":"神数","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"89","tags":["神数-龙星","神数-恩底弥翁","神数-超重武者"],"matchup":{"first":{"decka":"神数","win":"89","draw":"0","lose":"71"},"second":{"deckb":"神数","win":"100","draw":"0","lose":"46"}}},{"name":"妮穆蕾莉娅","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"88","tags":["妮穆蕾莉娅-暴食","妮穆蕾莉娅-强金","妮穆蕾莉娅-红莲魔兽"],"matchup":{"first":{"decka":"妮穆蕾莉娅","win":"47","draw":"0","lose":"73"},"second":{"deckb":"妮穆蕾莉娅","win":"76","draw":"0","lose":"56"}}},{"name":"忍者","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"87","tags":["忍者-杯面","忍者-强金","忍者-斩机"],"matchup":{"first":{"decka":"忍者","win":"64","draw":"0","lose":"62"},"second":{"deckb":"忍者","win":"72","draw":"0","lose":"50"}}},{"name":"转生炎兽","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"84","tags":["转生炎兽-斩机"],"matchup":{"first":{"decka":"转生炎兽","win":"57","draw":"0","lose":"81"},"second":{"deckb":"转生炎兽","win":"82","draw":"0","lose":"53"}}},{"name":"未界域暗黑界","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"84","tags":["未界域暗黑界-白雪","未界域暗黑界-病毒","未界域暗黑界-假面"],"matchup":{"first":{"decka":"未界域暗黑界","win":"46","draw":"0","lose":"75"},"second":{"deckb":"未界域暗黑界","win":"72","draw":"0","lose":"51"}}},{"name":"秘旋谍","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"79","tags":["秘旋谍-割草","秘旋谍-勇者","秘旋谍-朋克"],"matchup":{"first":{"decka":"秘旋谍","win":"82","draw":"0","lose":"55"},"second":{"deckb":"秘旋谍","win":"86","draw":"0","lose":"71"}}},{"name":"群豪","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"78","tags":["群豪-魔里","群豪-超重武者","群豪-神数"],"matchup":{"first":{"decka":"群豪","win":"69","draw":"0","lose":"60"},"second":{"deckb":"群豪","win":"52","draw":"0","lose":"42"}}},{"name":"火灵天星","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"77","tags":["火灵天星-斩机"],"matchup":{"first":{"decka":"火灵天星","win":"55","draw":"0","lose":"53"},"second":{"deckb":"火灵天星","win":"67","draw":"0","lose":"46"}}},{"name":"虹皇","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"75","tags":["虹皇-hero","虹皇-凤凰人","虹皇-假面"],"matchup":{"first":{"decka":"虹皇","win":"17","draw":"0","lose":"37"},"second":{"deckb":"虹皇","win":"77","draw":"0","lose":"38"}}},{"name":"星骑士","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"74","tags":["星骑士-次元场"],"matchup":{"first":{"decka":"星骑士","win":"54","draw":"0","lose":"46"},"second":{"deckb":"星骑士","win":"47","draw":"0","lose":"37"}}},{"name":"遗式","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"72","tags":["遗式-卫星闪灵","遗式-杯面"],"matchup":{"first":{"decka":"遗式","win":"64","draw":"0","lose":"54"},"second":{"deckb":"遗式","win":"68","draw":"0","lose":"52"}}},{"name":"抒情歌鸲","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"71","tags":["抒情歌鸲-七皇剑","抒情歌鸲-金华猫"],"matchup":{"first":{"decka":"抒情歌鸲","win":"79","draw":"0","lose":"57"},"second":{"deckb":"抒情歌鸲","win":"77","draw":"0","lose":"74"}}},{"name":"Metabeat","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"71","tags":["Metabeat-削命","Metabeat-强金","Metabeat-红莲魔兽"],"matchup":{"first":{"decka":"Metabeat","win":"72","draw":"0","lose":"56"},"second":{"deckb":"Metabeat","win":"78","draw":"0","lose":"59"}}},{"name":"龙辉巧","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"66","tags":["龙辉巧-电子化天使","龙辉巧-神光","龙辉巧-杯面"],"matchup":{"first":{"decka":"龙辉巧","win":"66","draw":"0","lose":"52"},"second":{"deckb":"龙辉巧","win":"74","draw":"0","lose":"35"}}},{"name":"电子龙","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"66","tags":["电子龙-银河","电子龙-暗电子","电子龙-兽带"],"matchup":{"first":{"decka":"电子龙","win":"22","draw":"0","lose":"38"},"second":{"deckb":"电子龙","win":"100","draw":"0","lose":"57"}}},{"name":"宝玉","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"63","tags":["宝玉-虹龙","宝玉-拯救的桥梁","宝玉-异热同心"],"matchup":{"first":{"decka":"宝玉","win":"31","draw":"0","lose":"58"},"second":{"deckb":"宝玉","win":"61","draw":"0","lose":"20"}}},{"name":"星圣","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"56","tags":["星圣-星骑士","星圣-次元场"],"matchup":{"first":{"decka":"星圣","win":"36","draw":"0","lose":"32"},"second":{"deckb":"星圣","win":"36","draw":"0","lose":"40"}}},{"name":"青眼","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"55","tags":["青眼-深渊之兽","青眼-假面","青眼-融合"],"matchup":{"first":{"decka":"青眼","win":"10","draw":"0","lose":"44"},"second":{"deckb":"青眼","win":"63","draw":"0","lose":"19"}}},{"name":"朋克","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"49","tags":["朋克-深渊之兽","朋克-割草","朋克-白雪"],"matchup":{"first":{"decka":"朋克","win":"53","draw":"0","lose":"53"},"second":{"deckb":"朋克","win":"58","draw":"0","lose":"49"}}},{"name":"恩底弥翁","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"48","tags":["恩底弥翁-滤抽","恩底弥翁-魔导兽","恩底弥翁-魔里"],"matchup":{"first":{"decka":"恩底弥翁","win":"51","draw":"0","lose":"58"},"second":{"deckb":"恩底弥翁","win":"56","draw":"0","lose":"33"}}},{"name":"咒眼","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"48","tags":["咒眼-强金","咒眼-俱舍怒威族"],"matchup":{"first":{"decka":"咒眼","win":"67","draw":"0","lose":"49"},"second":{"deckb":"咒眼","win":"59","draw":"1","lose":"56"}}},{"name":"海系","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"47","tags":["海系-俱舍怒威族","海系-冰水","海系-强金"],"matchup":{"first":{"decka":"海系","win":"21","draw":"0","lose":"21"},"second":{"deckb":"海系","win":"44","draw":"0","lose":"25"}}},{"name":"DD","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"46","tags":["DD-假面","DD-病毒"],"matchup":{"first":{"decka":"DD","win":"45","draw":"0","lose":"34"},"second":{"deckb":"DD","win":"43","draw":"0","lose":"36"}}},{"name":"幻影骑士团","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"44","tags":["幻影骑士团-朋克","幻影骑士团-未界域","幻影骑士团-深渊之兽"],"matchup":{"first":{"decka":"幻影骑士团","win":"40","draw":"0","lose":"50"},"second":{"deckb":"幻影骑士团","win":"57","draw":"0","lose":"36"}}},{"name":"银河光子","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"41","tags":["银河光子-深渊之兽","银河光子-七皇剑","银河光子-斩机"],"matchup":{"first":{"decka":"银河光子","win":"27","draw":"0","lose":"48"},"second":{"deckb":"银河光子","win":"50","draw":"0","lose":"18"}}},{"name":"幻变骚灵","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"41","tags":["幻变骚灵-强金","幻变骚灵-魔里"],"matchup":{"first":{"decka":"幻变骚灵","win":"47","draw":"0","lose":"43"},"second":{"deckb":"幻变骚灵","win":"51","draw":"0","lose":"35"}}},{"name":"同调士勇者同调系","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"40","tags":[],"matchup":{"first":{"decka":"同调士勇者同调系","win":"50","draw":"0","lose":"43"},"second":{"deckb":"同调士勇者同调系","win":"53","draw":"0","lose":"33"}}},{"name":"教导","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"37","tags":["教导-深渊之兽","教导-影依","教导-魔里"],"matchup":{"first":{"decka":"教导","win":"19","draw":"0","lose":"28"},"second":{"deckb":"教导","win":"24","draw":"0","lose":"29"}}},{"name":"恐龙族废铁","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"36","tags":["恐龙族废铁-进化药"],"matchup":{"first":{"decka":"恐龙族废铁","win":"42","draw":"0","lose":"39"},"second":{"deckb":"恐龙族废铁","win":"42","draw":"0","lose":"28"}}},{"name":"恐吓爪牙族","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"35","tags":["恐吓爪牙族-俱舍怒威族"],"matchup":{"first":{"decka":"恐吓爪牙族","win":"48","draw":"0","lose":"25"},"second":{"deckb":"恐吓爪牙族","win":"33","draw":"0","lose":"27"}}},{"name":"海造贼","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"35","tags":["海造贼-勇者"],"matchup":{"first":{"decka":"海造贼","win":"49","draw":"0","lose":"49"},"second":{"deckb":"海造贼","win":"57","draw":"0","lose":"48"}}},{"name":"斩机","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"35","tags":["斩机-恐啡肽狂龙"],"matchup":{"first":{"decka":"斩机","win":"36","draw":"0","lose":"33"},"second":{"deckb":"斩机","win":"55","draw":"0","lose":"30"}}},{"name":"救援ACE队","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"32","tags":["救援ACE队-次元场","救援ACE队-强金"],"matchup":{"first":{"decka":"救援ACE队","win":"43","draw":"0","lose":"33"},"second":{"deckb":"救援ACE队","win":"40","draw":"0","lose":"21"}}},{"name":"战华","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"31","tags":["战华-强金","战华-黄金国"],"matchup":{"first":{"decka":"战华","win":"14","draw":"0","lose":"14"},"second":{"deckb":"战华","win":"29","draw":"0","lose":"29"}}},{"name":"魔偶甜点","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"31","tags":["魔偶甜点-超重武者"],"matchup":{"first":{"decka":"魔偶甜点","win":"29","draw":"0","lose":"30"},"second":{"deckb":"魔偶甜点","win":"33","draw":"0","lose":"25"}}},{"name":"勇者","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"27","tags":["勇者-深渊之兽","勇者-朋克","勇者-强金"],"matchup":{"first":{"decka":"勇者","win":"22","draw":"0","lose":"24"},"second":{"deckb":"勇者","win":"29","draw":"0","lose":"23"}}},{"name":"坏兽","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"27","tags":["坏兽-辉夜","坏兽-未界域","坏兽-白雪"],"matchup":{"first":{"decka":"坏兽","win":"9","draw":"0","lose":"9"},"second":{"deckb":"坏兽","win":"66","draw":"0","lose":"64"}}},{"name":"割草黯黑狱火机","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"26","tags":["割草黯黑狱火机-推理门","割草黯黑狱火机-强金","割草黯黑狱火机-白雪"],"matchup":{"first":{"decka":"割草黯黑狱火机","win":"4","draw":"0","lose":"9"},"second":{"deckb":"割草黯黑狱火机","win":"42","draw":"0","lose":"32"}}},{"name":"均卡beat","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"26","tags":["均卡beat-削命","均卡beat-辉夜","均卡beat-次元场"],"matchup":{"first":{"decka":"均卡beat","win":"45","draw":"0","lose":"34"},"second":{"deckb":"均卡beat","win":"49","draw":"0","lose":"30"}}},{"name":"龙剑士魔里","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"24","tags":["龙剑士魔里-威风妖怪","龙剑士魔里-雾动机龙","龙剑士魔里-超重武者"],"matchup":{"first":{"decka":"龙剑士魔里","win":"8","draw":"0","lose":"26"},"second":{"deckb":"龙剑士魔里","win":"25","draw":"0","lose":"9"}}},{"name":"魔女术","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"24","tags":["魔女术-魔里","魔女术-教导","魔女术-割草"],"matchup":{"first":{"decka":"魔女术","win":"15","draw":"0","lose":"27"},"second":{"deckb":"魔女术","win":"45","draw":"0","lose":"18"}}},{"name":"弗兰克特化","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"23","tags":["弗兰克特化-废铁","弗兰克特化-恐龙族"],"matchup":{"first":{"decka":"弗兰克特化","win":"3","draw":"0","lose":"12"},"second":{"deckb":"弗兰克特化","win":"12","draw":"0","lose":"0"}}},{"name":"淘气仙星","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"23","tags":["淘气仙星-强金","淘气仙星-暴食","淘气仙星-深渊之兽"],"matchup":{"first":{"decka":"淘气仙星","win":"6","draw":"0","lose":"14"},"second":{"deckb":"淘气仙星","win":"10","draw":"0","lose":"11"}}},{"name":"空牙团","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"22","tags":["空牙团-神碑","空牙团-卫星闪灵","空牙团-杯面"],"matchup":{"first":{"decka":"空牙团","win":"8","draw":"0","lose":"13"},"second":{"deckb":"空牙团","win":"14","draw":"0","lose":"8"}}},{"name":"PSY骨架","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"22","tags":["PSY骨架-超重武者","PSY骨架-同调系","PSY骨架-深渊之兽"],"matchup":{"first":{"decka":"PSY骨架","win":"17","draw":"0","lose":"16"},"second":{"deckb":"PSY骨架","win":"26","draw":"0","lose":"17"}}},{"name":"半龙女仆","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"21","tags":["半龙女仆-深渊之兽","半龙女仆-死狱乡","半龙女仆-烙印"],"matchup":{"first":{"decka":"半龙女仆","win":"16","draw":"0","lose":"21"},"second":{"deckb":"半龙女仆","win":"16","draw":"0","lose":"11"}}},{"name":"水四阶","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"20","tags":["水四阶-七皇剑","水四阶-斩机"],"matchup":{"first":{"decka":"水四阶","win":"4","draw":"0","lose":"14"},"second":{"deckb":"水四阶","win":"11","draw":"0","lose":"14"}}},{"name":"恐龙族","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"20","tags":["恐龙族-进化药"],"matchup":{"first":{"decka":"恐龙族","win":"15","draw":"0","lose":"7"},"second":{"deckb":"恐龙族","win":"11","draw":"0","lose":"12"}}},{"name":"黑魔术师","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"20","tags":["黑魔术师-魔里","黑魔术师-传说之龙","黑魔术师-高仪"],"matchup":{"first":{"decka":"黑魔术师","win":"7","draw":"0","lose":"25"},"second":{"deckb":"黑魔术师","win":"19","draw":"0","lose":"12"}}},{"name":"护宝炮妖","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"19","tags":["护宝炮妖-斩机","护宝炮妖-兽带","护宝炮妖-割草"],"matchup":{"first":{"decka":"护宝炮妖","win":"21","draw":"0","lose":"8"},"second":{"deckb":"护宝炮妖","win":"25","draw":"0","lose":"13"}}},{"name":"三幻魔","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"19","tags":["三幻魔-混沌幻魔","三幻魔-假面","三幻魔-十二兽"],"matchup":{"first":{"decka":"三幻魔","win":"9","draw":"0","lose":"18"},"second":{"deckb":"三幻魔","win":"12","draw":"0","lose":"10"}}},{"name":"帝","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"19","tags":["帝-领域","帝-随风旅鸟","帝-虚无魔人"],"matchup":{"first":{"decka":"帝","win":"6","draw":"0","lose":"18"},"second":{"deckb":"帝","win":"16","draw":"0","lose":"3"}}},{"name":"辉夜坏兽","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"18","tags":["辉夜坏兽-次元场","辉夜坏兽-雪花","辉夜坏兽-超重武者"],"matchup":{"first":{"decka":"辉夜坏兽","win":"4","draw":"0","lose":"3"},"second":{"deckb":"辉夜坏兽","win":"52","draw":"0","lose":"36"}}},{"name":"教导召唤兽","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"18","tags":["教导召唤兽-影依","教导召唤兽-割草","教导召唤兽-深渊之兽"],"matchup":{"first":{"decka":"教导召唤兽","win":"17","draw":"0","lose":"13"},"second":{"deckb":"教导召唤兽","win":"23","draw":"0","lose":"10"}}},{"name":"恐龙真龙","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"18","tags":["恐龙真龙-进化药","恐龙真龙-废铁"],"matchup":{"first":{"decka":"恐龙真龙","win":"24","draw":"0","lose":"11"},"second":{"deckb":"恐龙真龙","win":"21","draw":"1","lose":"19"}}},{"name":"末那愚子族","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"17","tags":["末那愚子族-深渊之兽","末那愚子族-卫星闪灵"],"matchup":{"first":{"decka":"末那愚子族","win":"15","draw":"0","lose":"22"},"second":{"deckb":"末那愚子族","win":"28","draw":"0","lose":"17"}}},{"name":"削命真龙","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"17","tags":["削命真龙-强金","削命真龙-次元场"],"matchup":{"first":{"decka":"削命真龙","win":"23","draw":"0","lose":"23"},"second":{"deckb":"削命真龙","win":"27","draw":"0","lose":"21"}}},{"name":"龙连接","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"17","tags":["龙连接-深渊之兽","龙连接-黑白龙","龙连接-无形噬体"],"matchup":{"first":{"decka":"龙连接","win":"24","draw":"0","lose":"11"},"second":{"deckb":"龙连接","win":"28","draw":"0","lose":"24"}}},{"name":"魔界剧团","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"16","tags":["魔界剧团-无形噬体","魔界剧团-病毒","魔界剧团-AF"],"matchup":{"first":{"decka":"魔界剧团","win":"9","draw":"0","lose":"8"},"second":{"deckb":"魔界剧团","win":"8","draw":"0","lose":"4"}}},{"name":"黑羽","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"16","tags":["黑羽-深渊之兽"],"matchup":{"first":{"decka":"黑羽","win":"13","draw":"0","lose":"16"},"second":{"deckb":"黑羽","win":"12","draw":"0","lose":"9"}}},{"name":"源数","recent_time":"2023-03-03T00:00:00.000Z","source":"mycard-athletic","count":"16","tags":["源数-翼神龙","源数-PSY","源数-七皇剑"],"matchup":{"first":{"decka":"源数","win":"4","draw":"0","lose":"12"},"second":{"deckb":"源数","win":"41","draw":"0","lose":"36"}}}]' # typee = 1 pieChartSearch = on_command("查询饼图", aliases={"查饼图", "饼图查询"}) -font = font_path + "qmzl.ttf" +font = Path(font_path) / "qmzl.ttf" @pieChartSearch.handle() @@ -76,7 +77,7 @@ async def test(bot: Bot, event: Event, state: T_State): img = Image.open(buffer) # 使用Image打开图片数据 - img_back = Image.open(image_path + "pie_back.png") + img_back = Image.open(Path(image_path) / "pie_back.png") pie_width, pie_height = img.size @@ -87,8 +88,8 @@ async def test(bot: Bot, event: Event, state: T_State): img_back.paste(img, loca, mask=img) # =========备注添加============== - source = ImageFont.truetype(font, 15) - timefont = ImageFont.truetype(font, 25) + source = ImageFont.truetype(str(font), 15) + timefont = ImageFont.truetype(str(font), 25) time_up = pie_date[0]['recent_time'] draw = ImageDraw.Draw(img_back) diff --git a/nonebot_plugin_ocgbot_v2/daily.py b/nonebot_plugin_ocgbot_v2/daily.py index 225590a..4a6f141 100644 --- a/nonebot_plugin_ocgbot_v2/daily.py +++ b/nonebot_plugin_ocgbot_v2/daily.py @@ -1,11 +1,12 @@ import datetime +from pathlib import Path from PIL import Image, ImageDraw from nonebot import on_command from nonebot.adapters.onebot.v11 import Bot, Event, Message, MessageSegment from nonebot.typing import T_State -from nonebot_plugin_ocgbot_v2.libraries.FontUtil import * +from nonebot_plugin_ocgbot_v2.libraries.FontUtil import fonts from nonebot_plugin_ocgbot_v2.libraries.globalMessage import image_path, deck_path from nonebot_plugin_ocgbot_v2.libraries.staticvar import daily_card from nonebot_plugin_ocgbot_v2.libraries.tool import hash @@ -35,10 +36,10 @@ def getDailyPic(point: int, wm_value): card = obj[point % len(obj)] no = point % int(card['nums']) if card['type'] == "系列": - back_pic = Image.open(image_path + "daily_xilie.png") + back_pic = Image.open(Path(image_path) / "daily_xilie.png") else: - back_pic = Image.open(image_path + "daily_kapai.png") - url = deck_path + f"{card['id']}/{card['id']}-{no}.jpg" + back_pic = Image.open(Path(image_path) / "daily_kapai.png") + url = Path(deck_path) / f"{card['id']}/{card['id']}-{no}.jpg" cardPic = Image.open(url) proper_list = [] envy_list = [] @@ -100,25 +101,25 @@ def pic_joint(backPic: Image, cardPic: Image, daily: int, extra_text: str, weekd week = f"星期{num_dict.get(str(weekday))}" # 文字写入通过不同fill指定颜色 # 写入星期 - draw.text((550, 50), week, font=fontWeek, fill=(92, 128, 160)) + draw.text((550, 50), week, font=fonts['fontWeek'], fill=(92, 128, 160)) # 写入宜忌 for i in range(len(proper_list)): if i > 5: break else: - draw.text((60 + i % 3 * 102, 325 + int(i / 3) * 40), proper_list[i], font=fontList, fill=(92, 128, 160)) + draw.text((60 + i % 3 * 102, 325 + int(i / 3) * 40), proper_list[i], font=fonts['fontList'], fill=(92, 128, 160)) for i in range(len(envy_list)): if i > 5: break else: - draw.text((60 + i % 3 * 102, 507 + int(i / 3) * 40), envy_list[i], font=fontList, fill=(92, 128, 160)) + draw.text((60 + i % 3 * 102, 507 + int(i / 3) * 40), envy_list[i], font=fonts['fontList'], fill=(92, 128, 160)) # 写入小贴士 - draw.text(((backPic.width - fontText.size * len(extra_text)) / 2, 690), extra_text, font=fontText, + draw.text(((backPic.width - fonts['fontText'].size * len(extra_text)) / 2, 690), extra_text, font=fonts['fontText'], fill=(92, 128, 160)) # 贴入卡图 backPic.paste(cardPic.resize((280, 280)), (460, 290)) # 写入卡牌信息 - draw.text((430 + (400 - fontCardStr.size * len(card_str)) / 2, 580), card_str, font=fontCardStr, + draw.text((430 + (400 - fonts['fontCardStr'].size * len(card_str)) / 2, 580), card_str, font=fonts['fontCardStr'], fill=(92, 128, 160)) # 写入点数 - draw.text((260, 200), str(daily), font=fontPoint, fill=(92, 128, 160)) + draw.text((260, 200), str(daily), font=fonts['fontPoint'], fill=(92, 128, 160)) diff --git a/nonebot_plugin_ocgbot_v2/guess_card.py b/nonebot_plugin_ocgbot_v2/guess_card.py index 5e3bc19..dae7c70 100644 --- a/nonebot_plugin_ocgbot_v2/guess_card.py +++ b/nonebot_plugin_ocgbot_v2/guess_card.py @@ -7,7 +7,7 @@ from nonebot.params import CommandArg from nonebot.permission import SUPERUSER -from nonebot_plugin_ocgbot_v2.libraries.Card import getRandomCard, getCard, Card +from nonebot_plugin_ocgbot_v2.libraries.Card import getRandomCard, getCard from nonebot_plugin_ocgbot_v2.libraries.Guess import Guess from nonebot_plugin_ocgbot_v2.libraries.charpic import charPic from nonebot_plugin_ocgbot_v2.libraries.globalMessage import * diff --git a/nonebot_plugin_ocgbot_v2/libraries/Card.py b/nonebot_plugin_ocgbot_v2/libraries/Card.py index 292e9e7..a411238 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/Card.py +++ b/nonebot_plugin_ocgbot_v2/libraries/Card.py @@ -1,7 +1,7 @@ import copy import json import math -import os.path +from pathlib import Path from typing import Optional, Dict import httpx from nonebot_plugin_ocgbot_v2.libraries.SqliteUtils import SqliteUtils @@ -12,14 +12,14 @@ pre_flag = 0 extra_flag = 0 -conn, cursor = sqlite.connect(cdb_path + "cards.cdb") +conn, cursor = sqlite.connect(Path(cdb_path) / "cards.cdb") -if os.path.exists(cdb_path + "pre-release.cdb"): - conn_pre, cursor_pre = sqlite.connect(cdb_path + "pre-release.cdb") +if (Path(cdb_path) / "pre-release.cdb").exists(): + conn_pre, cursor_pre = sqlite.connect(Path(cdb_path) / "pre-release.cdb") pre_flag = 1 -if os.path.exists(cdb_path + "extra_card.cdb"): - conn_extra, cursor_extra = sqlite.connect(cdb_path + "extra_card.cdb") +if (Path(cdb_path) / "extra_card.cdb").exists(): + conn_extra, cursor_extra = sqlite.connect(Path(cdb_path) / "extra_card.cdb") extra_flag = 1 typeList = ['怪兽', '魔法', '陷阱'] @@ -73,6 +73,7 @@ def __getattribute__(self, item): return self[item] return super().__getattribute__(item) + class Card(Dict): cardId: Optional[int] = None name: Optional[str] = None @@ -252,7 +253,9 @@ def searchByName(name: str): card = Card_Extra(row) cards.append(card) if len(cards) == 0: - cards = searchById(searchFromBG(org_name)) + bg_temp = searchFromBG(org_name) + if bg_temp is not None: + cards = searchById() cards.sort(key=sortCard) return cards @@ -283,7 +286,10 @@ def searchFromBG(name): url = bg_url + name response = httpx.get(url) js = json.loads(response.text) - return js['result'][0]['id'] + if len(js["result"]) == 0: + return None + else: + return js['result'][0]['id'] def nickNameMatch(name: str): diff --git a/nonebot_plugin_ocgbot_v2/libraries/FontUtil.py b/nonebot_plugin_ocgbot_v2/libraries/FontUtil.py index 748119a..5b1b7a8 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/FontUtil.py +++ b/nonebot_plugin_ocgbot_v2/libraries/FontUtil.py @@ -1,19 +1,24 @@ +from pathlib import Path + from PIL import ImageFont from nonebot_plugin_ocgbot_v2.libraries.globalMessage import font_path -font = font_path + "qmzl.ttf" -fontWeek, fontList, fontCardStr, fontText, fontPoint = None, None, None, None, None +font = str(Path(font_path) / "qmzl.ttf") +fonts = {} + + +# fontWeek, fontList, fontCardStr, fontText, fontPoint = None, None, None, None, None def font_init(): - global fontWeek, fontList, fontCardStr, fontText, fontPoint + # global fontWeek, fontList, fontCardStr, fontText, fontPoint # 星期显示字体 - fontWeek = ImageFont.truetype(font, 45) + fonts['fontWeek'] = ImageFont.truetype(font, 45) # 宜忌显示字体 - fontList = ImageFont.truetype(font, 30) + fonts['fontList'] = ImageFont.truetype(font, 30) # 卡牌信息字体 - fontCardStr = ImageFont.truetype(font, 40) + fonts['fontCardStr'] = ImageFont.truetype(font, 40) # 小贴士字体 - fontText = ImageFont.truetype(font, 28) + fonts['fontText'] = ImageFont.truetype(font, 28) # 点数字体 - fontPoint = ImageFont.truetype(font, 60) + fonts['fontPoint'] = ImageFont.truetype(font, 60) diff --git a/nonebot_plugin_ocgbot_v2/libraries/forbideGet.py b/nonebot_plugin_ocgbot_v2/libraries/forbideGet.py index 718da9a..5ad96ce 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/forbideGet.py +++ b/nonebot_plugin_ocgbot_v2/libraries/forbideGet.py @@ -1,4 +1,6 @@ import json +from pathlib import Path + from requests_html import HTMLSession from nonebot_plugin_ocgbot_v2.libraries.SqliteUtils import SqliteUtils from nonebot_plugin_ocgbot_v2.libraries.globalMessage import json_path, cdb_path @@ -17,7 +19,7 @@ # 准限制卡cid pres = [] sqlite = SqliteUtils() -conn, cursor = sqlite.connect(cdb_path + "cards.cdb") +conn, cursor = sqlite.connect(Path(cdb_path) / "cards.cdb") def cidGet(): @@ -51,7 +53,7 @@ def insert(card_id, name, status): def WriteForbidden(js): # 写入数据 - with open(json_path + "forbidden.json", 'w', encoding='utf-8') as f: + with open(Path(json_path) / "forbidden.json", 'w', encoding='utf-8') as f: f.write(json.dumps(js, ensure_ascii=False, indent=4)) diff --git a/nonebot_plugin_ocgbot_v2/libraries/globalMessage.py b/nonebot_plugin_ocgbot_v2/libraries/globalMessage.py index 1bdf8e8..ec58658 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/globalMessage.py +++ b/nonebot_plugin_ocgbot_v2/libraries/globalMessage.py @@ -1,5 +1,4 @@ -import os.path -import pathlib +from pathlib import Path from random import choice import nonebot from nonebot import Config, logger @@ -85,8 +84,19 @@ "答错...好吧,##竟然答对了{0}(生气)", "呐❤呐❤呐❤,##竟然答对了{0},##不会作弊了吧❤~" ], + }, + 'random': { + 'sendwitchoutcd': [ + "##!慢点啦!", + "前面的区域之后再来探索吧~", + "##又在抽卡哦~休息一下好不好~", + "##小蓝不让你抽卡了(叉腰)~", + "抽多了对身体不好❤~##受不了的~", + "##又在抽卡呀,天天只会抽卡,真是飞舞❤~", + "##,着什么急❤~笨蛋❤笨蛋", + "##,不给你抽了!生气了吗?嘻嘻❤~" + ] } - }, { @@ -138,21 +148,25 @@ "好耶,##答对了{0}!小蓝可以去洗衣服啦", "嘿嘿嘿,##好厉害,小蓝都不会呢,答案就是{0}哦" ], + }, + 'random': { + 'sendwitchoutcd': [ + "##!慢点啦!", + "前面的区域之后再来探索吧~", + "##又在抽卡哦~休息一下好不好~", + "##小蓝不让你抽卡了(叉腰)~", + "抽多了对身体不好,##受不了的啦", + "##,不要着急啦", + "##,不给你抽了啦!" + ] } - }, ] -random_sendwitchoutcd = [ - "臭欧尼酱!慢点啦!", - "前面的区域之后再来探索吧~", - "臭欧尼酱又在抽卡哦~休息一下好不好~", - "臭欧尼酱小蓝不让你抽卡了(叉腰)~", - "抽多了对身体不好❤️~臭哥哥受不了的~", - "杂鱼又在抽卡呀,天天只会抽卡,真是飞舞❤️~", - "笨蛋大叔,着什么急❤️~笨蛋❤️笨蛋", - "臭大叔,不给你抽了!生气了吗?嘻嘻❤️~" -] + +def random_sendwitchoutcd() -> str: + arr = message_type[mess_type_choose]['random']['sendwitchoutcd'] + return choice(arr).replace("##", get_named()) def guess_sendwitchoutcd() -> str: @@ -224,40 +238,40 @@ def get_named() -> str: 'timeout': 100 } ] -static_path_abso = str(pathlib.Path(__file__).parent.parent).replace("\\", "/") + "/static/" -json_path = static_path_abso + "json/" -font_path = static_path_abso + "fonts/" -cdb_path = static_path_abso + "cdb/" -image_path = static_path_abso + "images/" -pics_path = static_path_abso + "pics/" -deck_path = static_path_abso + "decks/" +static_path_abso = Path(__file__).parent.parent / "static" +paths = {} +json_path = str(static_path_abso / "json") +font_path = str(static_path_abso / "fonts") +cdb_path = str(static_path_abso / "cdb") +image_path = str(static_path_abso / "images") +pics_path = str(static_path_abso / "pics") +deck_path = str(static_path_abso / "decks") logger.info("静态文件路径检查中......") try: - static_path_config = str(Config.parse_obj(nonebot.get_driver().config).static_path) + static_path_config = Path(Config.parse_obj(nonebot.get_driver().config).static_path) logger.info(static_path_config) - if not (static_path_config.endswith("/") or static_path_config.endswith("\\")): - static_path_config = static_path_config + "/" - if not os.path.exists(static_path_config): + # if not (static_path_config.endswith("/") or static_path_config.endswith("\\")): + # static_path_config = static_path_config + "/" + if not static_path_config.exists(): logger.info("环境路径不存在.....") else: - if os.path.exists(static_path_config + "json/"): - json_path = static_path_config + "json/" + if (static_path_config / "json").exists(): + json_path = str(static_path_config / "json") logger.info("环境路径存在json文件夹,已使用") - if os.path.exists(static_path_config + "fonts/"): - font_path = static_path_config + "fonts/" + if (static_path_config / "fonts").exists(): + font_path = str(static_path_config / "fonts") logger.info("环境路径存在fonts文件夹,已使用") - if os.path.exists(static_path_config + "cdb/"): - cbd_path = static_path_config + "cdb/" + if (static_path_config / "cdb/").exists(): + cbd_path = str(static_path_config / "cdb/") logger.info("环境路径存在cdb文件夹,已使用") - if os.path.exists(static_path_config + "images/"): - image_path = static_path_config + "images/" + if (static_path_config / "images/").exists(): + image_path = str(static_path_config / "images/") logger.info("环境路径存在images文件夹,已使用") - if os.path.exists(static_path_config + "pics/"): - pics_path = static_path_config + "pics/" - logger.info(pics_path) + if (static_path_config / "pics/").exists(): + pics_path = str(static_path_config / "pics/") logger.info("环境路径存在pics文件夹,已使用") - if os.path.exists(static_path_config + "decks/"): - deck_path = static_path_config + "decks/" + if (static_path_config / "decks/").exists(): + deck_path = str(static_path_config / "decks/") logger.info("环境路径存在deck文件夹,已使用") except: logger.info("不存在环境路径,使用本地路径....") diff --git a/nonebot_plugin_ocgbot_v2/libraries/guessManage.py b/nonebot_plugin_ocgbot_v2/libraries/guessManage.py index 841984c..658447e 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/guessManage.py +++ b/nonebot_plugin_ocgbot_v2/libraries/guessManage.py @@ -1,9 +1,6 @@ import os -import random import time -from pathlib import Path -import nonebot from nonebot.log import logger from ..libraries.globalMessage import guess_sendwitchoutcd diff --git a/nonebot_plugin_ocgbot_v2/libraries/image.py b/nonebot_plugin_ocgbot_v2/libraries/image.py index e7cf1ff..00815a5 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/image.py +++ b/nonebot_plugin_ocgbot_v2/libraries/image.py @@ -1,10 +1,12 @@ import base64 from io import BytesIO +from pathlib import Path + from PIL import ImageFont, ImageDraw, Image -from nonebot_plugin_ocgbot_v2.libraries.globalMessage import font_path,image_path +from nonebot_plugin_ocgbot_v2.libraries.globalMessage import font_path, image_path -fontpath = font_path+"msyh.ttc" -background = Image.open(image_path+"background.png") +fontpath = str(Path(font_path) / "msyh.ttc") +background = Image.open(Path(image_path) / "background.png") def draw_text(img_pil, text, offset_x): @@ -46,7 +48,7 @@ def text_to_image2(text, page_text): padding = 30 margin = 33 text_list = text.split('\n') - max_width = 0 + max_width = font.getsize(page_text)[0] for text in text_list: w, h = font.getsize(text) max_width = max(max_width, w) @@ -68,7 +70,7 @@ def text_to_image2(text, page_text): def text_to_image_with_back(text, page_text, title): font = ImageFont.truetype(fontpath, 28) - font_title = ImageFont.truetype(font_path+"qmzl.ttf", 50) + font_title = ImageFont.truetype(str(Path(font_path) / "qmzl.ttf"), 50) font_page = ImageFont.truetype(fontpath, 30) padding = 30 margin = 33 diff --git a/nonebot_plugin_ocgbot_v2/libraries/raiseCard.py b/nonebot_plugin_ocgbot_v2/libraries/raiseCard.py index 8cea269..8d0c1e1 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/raiseCard.py +++ b/nonebot_plugin_ocgbot_v2/libraries/raiseCard.py @@ -1,10 +1,12 @@ +from pathlib import Path + from PIL import ImageFont, ImageDraw, Image from nonebot_plugin_ocgbot_v2.libraries.globalMessage import image_path, font_path -cardpath = image_path + "card.jpg" -card2path = image_path + "card2.jpg" -fontpath = font_path + "msyh.ttc" +cardpath = Path(image_path) / "card.jpg" +card2path = Path(image_path) / "card2.jpg" +fontpath = Path(font_path) / "msyh.ttc" def draw_card_text(text, p): diff --git a/nonebot_plugin_ocgbot_v2/libraries/sendAction.py b/nonebot_plugin_ocgbot_v2/libraries/sendAction.py index 7e1245d..6c02f91 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/sendAction.py +++ b/nonebot_plugin_ocgbot_v2/libraries/sendAction.py @@ -1,4 +1,3 @@ -import os.path import random import re from nonebot.adapters.onebot.v11 import Message, MessageSegment @@ -6,7 +5,7 @@ from nonebot_plugin_ocgbot_v2.libraries.globalMessage import noSearchText, lanName, pics_path from nonebot_plugin_ocgbot_v2.libraries.image import * -static_url = pics_path +static_url = Path(pics_path) # 缩放比例 PANTOGRAPH = 0.6 @@ -59,12 +58,12 @@ async def send(js, bot, event, func, num=0): sendNosearch(func) else: msg_list = [] - pics_url = static_url + str( - js.cards[0].cardId) + '.jpg' + pics_url = static_url / (str( + js.cards[0].cardId) + '.jpg') if num != 0: num = num - 1 - pics_url = static_url + str( - js.cards[num].cardId) + '.jpg' + pics_url = static_url / (str( + js.cards[num].cardId) + '.jpg') if img_exist(pics_url): messageListAppend(js, pics_url, num, msg_list) else: @@ -96,15 +95,15 @@ async def send(js, bot, event, func, num=0): # 出现完整效果的方式 async def send2(js, func, num=0): - pics_url = static_url + str( - js.cards[0].cardId) + '.jpg' + pics_url = static_url / (str( + js.cards[0].cardId) + '.jpg') if js.amount == 0: sendNosearch(func) # num!=0即用户选择详细卡牌信息 elif num != 0: num = num - 1 - pics_url = static_url + str( - js.cards[num].cardId) + '.jpg' + pics_url = static_url / (str( + js.cards[num].cardId) + '.jpg') if img_exist(pics_url): await func.finish(getAllMessage(js, pics_url, num)) else: @@ -122,15 +121,15 @@ async def send2(js, func, num=0): # 单卡图方式 async def send3(js, func, num=0): - pics_url = static_url + str( - js.cards[0].cardId) + '.jpg' + pics_url = static_url / (str( + js.cards[0].cardId) + '.jpg') if js.amount == 0: sendNosearch(func) # num!=0即用户选择详细卡牌信息 elif num != 0: num = num - 1 - pics_url = static_url + str( - js.cards[num - 1].cardId) + '.jpg' + pics_url = static_url / (str( + js.cards[num - 1].cardId) + '.jpg') if img_exist(pics_url): await func.finish(getPicOnlyMessage(js, num, pics_url)) else: @@ -252,7 +251,7 @@ def getPicOnlyMessage(js, num, url): # =========判断============ # 判断图片是否存在 def img_exist(url): - return os.path.exists(url) + return url.exists() # ===================== @@ -265,7 +264,6 @@ async def send_cards_byCard(js, func): # if car['enName'] is not None: # result += "英文卡名-" + car['enName'] + " " + "日文卡名-" + car['jpName'] + "\n" car.effect = car.effect.replace('\r', '') - print(car.deff) if car.mainType == '怪兽': if car.deff is None: result += f"{car.level} / ATK: {car.atk} / : {car.zz} / {car.attribute}\n" @@ -280,7 +278,13 @@ async def send_cards_byCard(js, func): result += "\n" page_text = f"找到了{js.amount}张卡哟~,当前{js.nowNum}/{js.pageNum}页 输入数字可以选择搜索结果!输入`上一页`/`下一页` 进行翻页~" - await func.send(Message([ - MessageSegment("image", { - "file": f"base64://{str(image_to_base64(text_to_image2(result, page_text)), encoding='utf-8')}" - })])) + if js.amount > 1: + await func.send(Message([ + MessageSegment("image", { + "file": f"base64://{str(image_to_base64(text_to_image2(result, page_text)), encoding='utf-8')}" + })])) + else: + await func.finish(Message([ + MessageSegment("image", { + "file": f"base64://{str(image_to_base64(text_to_image2(result, page_text)), encoding='utf-8')}" + })])) diff --git a/nonebot_plugin_ocgbot_v2/ocg.py b/nonebot_plugin_ocgbot_v2/ocg.py index 7f7ff3d..61e02a9 100644 --- a/nonebot_plugin_ocgbot_v2/ocg.py +++ b/nonebot_plugin_ocgbot_v2/ocg.py @@ -52,12 +52,12 @@ async def _(bot: Bot, event: Event, state: T_State, args: Message = CommandArg() except: text = text + " 1" search_group = re.match(regex, text).groups() - try: - state['name'] = search_group[0] - state['page'] = search_group[1] - js = getCard(state['name'], state['page']) - except Exception as e: - await search_card.finish("咿呀?查询失败了呢") + # try: + state['name'] = search_group[0] + state['page'] = search_group[1] + js = getCard(state['name'], state['page']) + # except Exception as e: + # await search_card.finish("咿呀?查询失败了呢") if int(search_group[1]) > int(js.pageNum): await search_card.finish("页码超出最大值" + "`" + str(js.pageNum) + "`") state['js'] = js diff --git a/nonebot_plugin_ocgbot_v2/priceSearch.py b/nonebot_plugin_ocgbot_v2/priceSearch.py index 4dc8ba3..f5bbb86 100644 --- a/nonebot_plugin_ocgbot_v2/priceSearch.py +++ b/nonebot_plugin_ocgbot_v2/priceSearch.py @@ -5,7 +5,7 @@ from nonebot.adapters.onebot.v11 import Event, Bot, Message, MessageSegment from nonebot import on_command -from nonebot_plugin_ocgbot_v2.libraries.image import image_to_base64, text_to_image2, text_to_image_with_back +from nonebot_plugin_ocgbot_v2.libraries.image import image_to_base64, text_to_image_with_back gradeUrl = "https://api.jihuanshe.com/api/market/search/match-product?game_key=ygo&game_sub_key=ocg&type=card_version"