This commit is contained in:
xtaodada 2022-09-03 23:51:22 +08:00
parent a2c1797d6d
commit fc253c8422
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -36,29 +36,50 @@ class Player:
data = json.load(fp)
self.name = data.get("playerInfo", {}).get("nickname", "")
@staticmethod
def can_refresh():
return sqlite.get("can_refresh", True)
@staticmethod
def lock():
sqlite["can_refresh"] = False
@staticmethod
def unlock():
sqlite["can_refresh"] = True
async def update_char(self):
all_char_ = await getRawData(self.uid)
all_char_ = all_char_.get("list", [])
for i in all_char_:
for f in self.all_char:
if f["name"] == i:
self.all_char.remove(f)
break
try:
all_char = await getPanelMsg(self.uid, i)
img = all_char.get("pic", None)
error = all_char.get("error", None)
if img:
msg = await app.send_photo(channel_id, img)
self.all_char.append(gen_char_dict(i, msg.photo.file_id))
elif error:
return error
else:
print(all_char)
except Exception as e:
print(e)
continue
return f"成功缓存了 UID{self.uid}{''.join(all_char_)}{len(all_char_)} 位角色数据!"
if not self.can_refresh():
return "有刷新任务正在运行,请稍等一会儿再试"
self.lock()
try:
all_char_ = await getRawData(self.uid)
all_char_ = all_char_.get("list", [])
for i in all_char_:
for f in self.all_char:
if f["name"] == i:
self.all_char.remove(f)
break
try:
all_char = await getPanelMsg(self.uid, i)
img = all_char.get("pic", None)
error = all_char.get("error", None)
if img:
msg = await app.send_photo(channel_id, img)
self.all_char.append(gen_char_dict(i, msg.photo.file_id))
elif error:
return error
else:
print(all_char)
except Exception as e:
print(e)
continue
return f"成功缓存了 UID{self.uid}{''.join(all_char_)}{len(all_char_)} 位角色数据!"
except Exception as e:
print(e)
return "数据刷新失败,请重试"
finally:
self.unlock()
def export(self):
return {"name": self.name, "uid": self.uid, "time": int(time.time()), "all_char": self.all_char}