Skip to content

Commit

Permalink
fixed: 优化部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
fireinsect committed Feb 6, 2024
1 parent ed7338c commit d0d0186
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 42 deletions.
1 change: 0 additions & 1 deletion nonebot_plugin_ocgbot_v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_ocgbot_v2/cardPieChart.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_ocgbot_v2/daily.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion nonebot_plugin_ocgbot_v2/help.py
Original file line number Diff line number Diff line change
@@ -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'})
Expand Down
6 changes: 2 additions & 4 deletions nonebot_plugin_ocgbot_v2/libraries/Card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']

Expand Down
1 change: 0 additions & 1 deletion nonebot_plugin_ocgbot_v2/libraries/FontUtil.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from PIL import ImageFont

from nonebot_plugin_ocgbot_v2.libraries.globalMessage import font_path

font = font_path + "qmzl.ttf"
Expand Down
2 changes: 0 additions & 2 deletions nonebot_plugin_ocgbot_v2/libraries/Guess.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_ocgbot_v2/libraries/SqliteUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
# 使得查询结果以字典形式返回
Expand Down
15 changes: 6 additions & 9 deletions nonebot_plugin_ocgbot_v2/libraries/forbideGet.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)
)
Expand All @@ -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)


Expand All @@ -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
Expand All @@ -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
Expand All @@ -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, "准限")
1 change: 0 additions & 1 deletion nonebot_plugin_ocgbot_v2/libraries/globalMessage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os.path
import pathlib
from random import choice

import nonebot
from nonebot import Config, logger

Expand Down
2 changes: 0 additions & 2 deletions nonebot_plugin_ocgbot_v2/libraries/image.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_ocgbot_v2/libraries/raiseCard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions nonebot_plugin_ocgbot_v2/libraries/randomManage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import os
import random
import time

from ..libraries.globalMessage import random_sendwitchoutcd

try:
import ujson as json
except:
Expand Down Expand Up @@ -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']
Expand Down
7 changes: 3 additions & 4 deletions nonebot_plugin_ocgbot_v2/libraries/searchManage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os

try:
import ujson as json
except:
Expand Down Expand Up @@ -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
Expand All @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_ocgbot_v2/libraries/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions nonebot_plugin_ocgbot_v2/ocg.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_ocgbot_v2/priceSearch.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit d0d0186

Please sign in to comment.