diff --git a/nonebot_plugin_ocgbot_v2/libraries/Guess.py b/nonebot_plugin_ocgbot_v2/libraries/Guess.py index aee2100..c02167c 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/Guess.py +++ b/nonebot_plugin_ocgbot_v2/libraries/Guess.py @@ -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: diff --git a/nonebot_plugin_ocgbot_v2/libraries/guessManage.py b/nonebot_plugin_ocgbot_v2/libraries/guessManage.py index 658447e..80dae06 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/guessManage.py +++ b/nonebot_plugin_ocgbot_v2/libraries/guessManage.py @@ -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)) diff --git a/nonebot_plugin_ocgbot_v2/libraries/randomManage.py b/nonebot_plugin_ocgbot_v2/libraries/randomManage.py index e040885..aa3e0b0 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/randomManage.py +++ b/nonebot_plugin_ocgbot_v2/libraries/randomManage.py @@ -1,6 +1,7 @@ import os import time from ..libraries.globalMessage import random_sendwitchoutcd + try: import ujson as json except: @@ -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)) @@ -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: @@ -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'抽卡功能已关闭!') # 查询冷却时间 @@ -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}!") + # --------------- 逻辑判断 结束 --------------- # --------------- 冷却更新 开始 --------------- diff --git a/nonebot_plugin_ocgbot_v2/libraries/searchManage.py b/nonebot_plugin_ocgbot_v2/libraries/searchManage.py index 5307731..35c304d 100644 --- a/nonebot_plugin_ocgbot_v2/libraries/searchManage.py +++ b/nonebot_plugin_ocgbot_v2/libraries/searchManage.py @@ -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))