Skip to content

Commit

Permalink
fixed:适配新版本pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
fireinsect committed Mar 4, 2024
1 parent 3bdd472 commit 34798cc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions nonebot_plugin_ocgbot_v2/libraries/Guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
from nonebot_plugin_ocgbot_v2.libraries.globalMessage import guess_diff



class GuessData(BaseModel):
card: Card
image: str
time: int
end: bool = False
class Config:
arbitrary_types_allowed = True


class Guess:
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_ocgbot_v2/libraries/guessManage.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def ReadCfg(self) -> dict:
# 写入cfg
def WriteCfg(self):
# 尝试创建路径
os.makedirs(self.path[:-18], mode=0o777, exist_ok=True)
os.makedirs(self.path.rsplit("/",1)[0], mode=0o777, exist_ok=True)
# 写入数据
with open(self.path, 'w', encoding='utf-8') as f:
f.write(json.dumps(self.cfg))
Expand Down
9 changes: 6 additions & 3 deletions nonebot_plugin_ocgbot_v2/libraries/randomManage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import time
from ..libraries.globalMessage import random_sendwitchoutcd

try:
import ujson as json
except:
Expand Down Expand Up @@ -30,7 +31,7 @@ def ReadCfg(self) -> dict:

def WriteCfg(self):
# 尝试创建路径
os.makedirs(self.path[:-16], mode=0o777, exist_ok=True)
os.makedirs(self.path.rsplit("/", 1)[0], mode=0o777, exist_ok=True)
# 写入数据
with open(self.path, 'w', encoding='utf-8') as f:
f.write(json.dumps(self.cfg))
Expand All @@ -51,6 +52,7 @@ def ReadCd(self, group_sessionId):
return self.cfg[group_sessionId]['cd']
except KeyError:
return self.random_cd

# 查询黑名单
def ReadBanList(self, sessionId):
try:
Expand All @@ -61,7 +63,7 @@ def ReadBanList(self, sessionId):
# --------------- 查询系统 结束 ---------------

# --------------- 逻辑判断 开始 ---------------
def CheckPermission(self, sessionId: str,groupSession: str, userType: str = 'group'):
def CheckPermission(self, sessionId: str, groupSession: str, userType: str = 'group'):
if self.ReadBanList(groupSession):
raise PermissionError(f'抽卡功能已关闭!')
# 查询冷却时间
Expand All @@ -76,8 +78,9 @@ def CheckPermission(self, sessionId: str,groupSession: str, userType: str = 'gro
hours, minutes = divmod(minutes, 60)
else:
seconds = timeLeft
cd_msg = f"{str(round(hours)) + '小时' if hours else ''}{str(round(minutes)) + '分钟' if minutes else ''}{str(round(seconds,3)) + '秒' if seconds else ''}"
cd_msg = f"{str(round(hours)) + '小时' if hours else ''}{str(round(minutes)) + '分钟' if minutes else ''}{str(round(seconds, 3)) + '秒' if seconds else ''}"
raise PermissionError(f"{random_sendwitchoutcd()} 你的CD还有{cd_msg}!")

# --------------- 逻辑判断 结束 ---------------

# --------------- 冷却更新 开始 ---------------
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_ocgbot_v2/libraries/searchManage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def ReadCfg(self) -> dict:

def WriteCfg(self):
# 尝试创建路径
os.makedirs(self.path[:-16], mode=0o777, exist_ok=True)
os.makedirs(self.path.rsplit("/",1)[0], mode=0o777, exist_ok=True)
# 写入数据
with open(self.path, 'w', encoding='utf-8') as f:
f.write(json.dumps(self.cfg))
Expand Down

0 comments on commit 34798cc

Please sign in to comment.