diff --git a/nonebot_plugin_ocgbot_v2/__init__.py b/nonebot_plugin_ocgbot_v2/__init__.py index 5011ee0..57dd0b9 100644 --- a/nonebot_plugin_ocgbot_v2/__init__.py +++ b/nonebot_plugin_ocgbot_v2/__init__.py @@ -2,7 +2,6 @@ import json import os.path from threading import Thread - import httpx from nonebot import logger, get_driver from nonebot_plugin_ocgbot_v2.libraries.forbideGet import forbiddenGet diff --git a/nonebot_plugin_ocgbot_v2/cardPieChart.py b/nonebot_plugin_ocgbot_v2/cardPieChart.py index bdd1ac5..310ab3b 100644 --- a/nonebot_plugin_ocgbot_v2/cardPieChart.py +++ b/nonebot_plugin_ocgbot_v2/cardPieChart.py @@ -1,7 +1,7 @@ import io import numpy -import requests +import httpx from PIL import Image, ImageFont, ImageDraw from matplotlib import pyplot as plt from matplotlib import font_manager as fm @@ -23,7 +23,7 @@ @pieChartSearch.handle() async def test(bot: Bot, event: Event, state: T_State): - pie_date = requests.get(url).json() + pie_date = httpx.get(url).json() # global typee # if typee == 1: # pie_date = json.loads(json1) diff --git a/nonebot_plugin_ocgbot_v2/daily.py b/nonebot_plugin_ocgbot_v2/daily.py index 9386019..225590a 100644 --- a/nonebot_plugin_ocgbot_v2/daily.py +++ b/nonebot_plugin_ocgbot_v2/daily.py @@ -1,6 +1,6 @@ import datetime -from PIL import Image, ImageFont, ImageDraw +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 diff --git a/nonebot_plugin_ocgbot_v2/help.py b/nonebot_plugin_ocgbot_v2/help.py index 3200ec7..639c2bf 100644 --- a/nonebot_plugin_ocgbot_v2/help.py +++ b/nonebot_plugin_ocgbot_v2/help.py @@ -1,7 +1,6 @@ from nonebot.typing import T_State from nonebot.adapters.onebot.v11 import Event, Bot, Message, MessageSegment from nonebot import on_command - from nonebot_plugin_ocgbot_v2.libraries.image import * ocghelp = on_command('ygo help', aliases={'ygohelp', 'ygo帮助', '#帮助', 'y帮助', '.help', 'yhelp', '#菜单', '菜单', 'help'}) diff --git a/nonebot_plugin_ocgbot_v2/libraries/Card.py b/nonebot_plugin_ocgbot_v2/libraries/Card.py index 4c497cc..292e9e7 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/Card.py +++ b/nonebot_plugin_ocgbot_v2/libraries/Card.py @@ -3,9 +3,7 @@ import math import os.path from typing import Optional, Dict - -import requests - +import httpx from nonebot_plugin_ocgbot_v2.libraries.SqliteUtils import SqliteUtils from nonebot_plugin_ocgbot_v2.libraries.globalMessage import cdb_path from nonebot_plugin_ocgbot_v2.libraries.staticvar import forbidden, nick_name_0, nick_name_1 @@ -283,7 +281,7 @@ def sortCard(a): def searchFromBG(name): url = bg_url + name - response = requests.get(url) + response = httpx.get(url) js = json.loads(response.text) return js['result'][0]['id'] diff --git a/nonebot_plugin_ocgbot_v2/libraries/FontUtil.py b/nonebot_plugin_ocgbot_v2/libraries/FontUtil.py index 333b78a..748119a 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/FontUtil.py +++ b/nonebot_plugin_ocgbot_v2/libraries/FontUtil.py @@ -1,5 +1,4 @@ from PIL import ImageFont - from nonebot_plugin_ocgbot_v2.libraries.globalMessage import font_path font = font_path + "qmzl.ttf" diff --git a/nonebot_plugin_ocgbot_v2/libraries/Guess.py b/nonebot_plugin_ocgbot_v2/libraries/Guess.py index 33b8362..aee2100 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/Guess.py +++ b/nonebot_plugin_ocgbot_v2/libraries/Guess.py @@ -1,8 +1,6 @@ from PIL.Image import Image from typing import Dict - from pydantic import BaseModel - from nonebot_plugin_ocgbot_v2.libraries.Card import Card from nonebot_plugin_ocgbot_v2.libraries.globalMessage import guess_diff diff --git a/nonebot_plugin_ocgbot_v2/libraries/SqliteUtils.py b/nonebot_plugin_ocgbot_v2/libraries/SqliteUtils.py index cd9be6d..72727bc 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/SqliteUtils.py +++ b/nonebot_plugin_ocgbot_v2/libraries/SqliteUtils.py @@ -10,7 +10,7 @@ def dict_factory(cursor, row): d[col[0]] = row[idx] return d - def connect(self,db_file): + def connect(self, db_file): # 建立和数据库的连接 conn = sqlite3.connect(db_file) # 使得查询结果以字典形式返回 diff --git a/nonebot_plugin_ocgbot_v2/libraries/forbideGet.py b/nonebot_plugin_ocgbot_v2/libraries/forbideGet.py index a3ea7ab..718da9a 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/forbideGet.py +++ b/nonebot_plugin_ocgbot_v2/libraries/forbideGet.py @@ -1,14 +1,11 @@ import json - 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 from nonebot_plugin_ocgbot_v2.libraries.staticvar import forbidden url = "https://www.db.yugioh-card.com/yugiohdb/forbidden_limited.action?request_locale=ja#list_forbidden" session = HTMLSession() -r = session.get(url) bans_url = "#list_forbidden > div.list > div>div" rests_url = "#list_limited > #forbidden_limited_list > div>div" pres_url = "#list_semi_limited > #forbidden_limited_list > div>div" @@ -34,7 +31,7 @@ def cidGet(): pres.append(k.find("input")[0].attrs['value'].split("cid=")[1]) -def forbideUpdate(card_id): +def forbiddenUpdate(card_id): cursor.execute( "select * from texts where id={0} ;".format(card_id) ) @@ -43,12 +40,12 @@ def forbideUpdate(card_id): def insert(card_id, name, status): - json = { + data = { "card_id": card_id, "name": name, "status": status } - forbidden.append(json) + forbidden.append(data) WriteForbidden(forbidden) @@ -68,7 +65,7 @@ def forbiddenGet(): card_id = list(re.html.find("div.col-md-6.col-xs-8.names > h3:nth-child(3) > span:nth-child(1)"))[0].text else: card_id = card_id[0].text - name = forbideUpdate(card_id)['name'] + name = forbiddenUpdate(card_id)['name'] insert(card_id, name, "禁") for i in rests: card_url = "https://ygocdb.com/?search=" + i @@ -78,7 +75,7 @@ def forbiddenGet(): card_id = re.html.find("div.col-md-6.col-xs-8.names > h3:nth-child(3) > span:nth-child(1)")[0].text else: card_id = card_id[0].text - name = forbideUpdate(card_id)['name'] + name = forbiddenUpdate(card_id)['name'] insert(card_id, name, "限") for i in pres: card_url = "https://ygocdb.com/?search=" + i @@ -88,5 +85,5 @@ def forbiddenGet(): card_id = list(re.html.find("div.col-md-6.col-xs-8.names > h3:nth-child(3) > span:nth-child(1)"))[0].text else: card_id = card_id[0].text - name = forbideUpdate(card_id)['name'] + name = forbiddenUpdate(card_id)['name'] insert(card_id, name, "准限") diff --git a/nonebot_plugin_ocgbot_v2/libraries/globalMessage.py b/nonebot_plugin_ocgbot_v2/libraries/globalMessage.py index d9a836f..1bdf8e8 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/globalMessage.py +++ b/nonebot_plugin_ocgbot_v2/libraries/globalMessage.py @@ -1,7 +1,6 @@ import os.path import pathlib from random import choice - import nonebot from nonebot import Config, logger diff --git a/nonebot_plugin_ocgbot_v2/libraries/image.py b/nonebot_plugin_ocgbot_v2/libraries/image.py index cac68bc..e7cf1ff 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/image.py +++ b/nonebot_plugin_ocgbot_v2/libraries/image.py @@ -1,8 +1,6 @@ import base64 from io import BytesIO - from PIL import ImageFont, ImageDraw, Image - from nonebot_plugin_ocgbot_v2.libraries.globalMessage import font_path,image_path fontpath = font_path+"msyh.ttc" diff --git a/nonebot_plugin_ocgbot_v2/libraries/raiseCard.py b/nonebot_plugin_ocgbot_v2/libraries/raiseCard.py index 1fe31cb..8cea269 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/raiseCard.py +++ b/nonebot_plugin_ocgbot_v2/libraries/raiseCard.py @@ -8,7 +8,7 @@ def draw_card_text(text, p): - if (p == 2): + if p == 2: i = Image.open(card2path) else: i = Image.open(cardpath) diff --git a/nonebot_plugin_ocgbot_v2/libraries/randomManage.py b/nonebot_plugin_ocgbot_v2/libraries/randomManage.py index f92aee1..e040885 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/randomManage.py +++ b/nonebot_plugin_ocgbot_v2/libraries/randomManage.py @@ -1,9 +1,6 @@ import os -import random import time - from ..libraries.globalMessage import random_sendwitchoutcd - try: import ujson as json except: @@ -48,7 +45,7 @@ def ReadLastSend(self, sessionId): except KeyError: return 0 - # 查询cd + # 查询cd def ReadCd(self, group_sessionId): try: return self.cfg[group_sessionId]['cd'] diff --git a/nonebot_plugin_ocgbot_v2/libraries/searchManage.py b/nonebot_plugin_ocgbot_v2/libraries/searchManage.py index 7d12787..5307731 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/searchManage.py +++ b/nonebot_plugin_ocgbot_v2/libraries/searchManage.py @@ -1,5 +1,4 @@ import os - try: import ujson as json except: @@ -46,8 +45,8 @@ def ReadSearchType(self, sessionId): # --------------- 逻辑判断 开始 --------------- def CheckType(self, sessionId: str, userType: str = 'group'): - searchType=self.ReadSearchType(sessionId) - if searchType!=1 and searchType != 2 and searchType != 3: + searchType = self.ReadSearchType(sessionId) + if searchType != 1 and searchType != 2 and searchType != 3: raise PermissionError(f'查询失败!') else: return searchType @@ -56,7 +55,7 @@ def CheckType(self, sessionId: str, userType: str = 'group'): # --------------- 增删系统 开始 --------------- def UpdateSearchType(self, sessionId: str, type: int): - if type != 1 and type != 2 and type!=3: + if type != 1 and type != 2 and type != 3: return "请选择正确查卡方式" else: if not sessionId in self.cfg.keys(): diff --git a/nonebot_plugin_ocgbot_v2/libraries/tool.py b/nonebot_plugin_ocgbot_v2/libraries/tool.py index 415dc83..ad63320 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/tool.py +++ b/nonebot_plugin_ocgbot_v2/libraries/tool.py @@ -12,5 +12,5 @@ def hash(qq: int): return (days * qq) >> 8 -def getRandom(num: int) -> int : - return random.randint(1,num) % num +def getRandom(num: int) -> int: + return random.randint(1, num) % num diff --git a/nonebot_plugin_ocgbot_v2/ocg.py b/nonebot_plugin_ocgbot_v2/ocg.py index af8783e..7f7ff3d 100644 --- a/nonebot_plugin_ocgbot_v2/ocg.py +++ b/nonebot_plugin_ocgbot_v2/ocg.py @@ -1,14 +1,10 @@ -import json - import nonebot from nonebot.params import CommandArg - from nonebot.permission import SUPERUSER from nonebot.typing import T_State from nonebot.adapters.onebot.v11 import Event, Bot, GroupMessageEvent, PrivateMessageEvent, GROUP_ADMIN, \ GROUP_OWNER from nonebot import on_command - from nonebot_plugin_ocgbot_v2.libraries.Card import getCard, getRandomCard from nonebot_plugin_ocgbot_v2.libraries.searchManage import SearchManager from nonebot_plugin_ocgbot_v2.libraries.sendAction import * diff --git a/nonebot_plugin_ocgbot_v2/priceSearch.py b/nonebot_plugin_ocgbot_v2/priceSearch.py index 3c03f7e..4dc8ba3 100644 --- a/nonebot_plugin_ocgbot_v2/priceSearch.py +++ b/nonebot_plugin_ocgbot_v2/priceSearch.py @@ -1,5 +1,5 @@ import re -import requests +import httpx from nonebot.params import CommandArg from nonebot.typing import T_State from nonebot.adapters.onebot.v11 import Event, Bot, Message, MessageSegment @@ -30,7 +30,7 @@ async def _(bot: Bot, event: Event, state: T_State,args: Message = CommandArg()) textNext = search_group.groups()[0] name = textNext url = f"{gradeUrl}&keyword={name}&page={page}" - result = requests.get(url).json() + result = httpx.get(url).json() page_text = f"找到了{result['total']}条数据哟~,当前{result['current_page']}/{result['last_page']}页 数据来源:集换社" await priceSearch.send(Message([