mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-10-21 16:27:15 +08:00
fix bug
This commit is contained in:
parent
8a9690c4cd
commit
1c96301733
@ -75,7 +75,7 @@ async def gacha(event: Union[MessageEvent, GroupMessageEvent], reGroup: Dict = R
|
||||
gacha_data = globals()[gacha_type]
|
||||
img = await more_ten(uid, gacha_data, num, sender)
|
||||
save_user_info()
|
||||
await sim_gacha.finish(MessageSegment.image(img), at_sender=True)
|
||||
await sim_gacha.finish(img, at_sender=True)
|
||||
|
||||
|
||||
@show_log.handle()
|
||||
|
@ -199,7 +199,7 @@ async def create_item(rank, item_type, name, element, count, dg_time):
|
||||
return bg
|
||||
|
||||
|
||||
async def ten(uid, gacha_data, sd) -> PngImagePlugin.PngImageFile:
|
||||
async def ten(uid, gacha_data) -> PngImagePlugin.PngImageFile:
|
||||
gacha_list = []
|
||||
for i in range(0, 10):
|
||||
if gacha_data['gacha_type'] == 'all_star':
|
||||
@ -236,14 +236,13 @@ async def ten(uid, gacha_data, sd) -> PngImagePlugin.PngImageFile:
|
||||
async def more_ten(uid, gacha_data, num, sd):
|
||||
time_str = datetime.datetime.strftime(datetime.datetime.now(), '%m-%d %H:%M')
|
||||
if num == 1:
|
||||
img = await ten(uid, gacha_data, sd)
|
||||
img = await ten(uid, gacha_data)
|
||||
else:
|
||||
img = Image.new("RGB", (1024, 575 * num), (255, 255, 255))
|
||||
for i in range(0, num):
|
||||
item_img = await ten(uid, gacha_data, sd)
|
||||
item_img = await ten(uid, gacha_data)
|
||||
img.paste(item_img, (0, 575 * i))
|
||||
draw = ImageDraw.Draw(img)
|
||||
draw.text((27, 575 * num - 30), ('@%s %s Created By LittlePaimon' % (str(sd.nickname), time_str)), font=time_font,
|
||||
fill="#8E8E8E")
|
||||
|
||||
return MessageBuild.Image(img, quality=75)
|
||||
|
@ -1,12 +1,12 @@
|
||||
from utils.auth_util import get_headers, get_sign_headers, get_use_cookie, get_own_cookie, check_retcode
|
||||
from utils.db_util import update_cookie_cache
|
||||
from utils.decorator import AsyncCache
|
||||
from utils.decorator import cache
|
||||
from utils import aiorequests
|
||||
import datetime
|
||||
import re
|
||||
|
||||
|
||||
@AsyncCache(ttl=datetime.timedelta(hours=1))
|
||||
@cache(ttl=datetime.timedelta(hours=1))
|
||||
async def get_abyss_data(user_id, uid, schedule_type="1", use_cache=True):
|
||||
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
||||
url = "https://api-takumi-record.mihoyo.com/game_record/app/genshin/api/spiralAbyss"
|
||||
@ -50,7 +50,7 @@ async def get_daily_note_data(uid):
|
||||
return f'你的uid{uid}的cookie已过期,需要重新绑定哦!'
|
||||
|
||||
|
||||
@AsyncCache(ttl=datetime.timedelta(hours=1))
|
||||
@cache(ttl=datetime.timedelta(hours=1))
|
||||
async def get_player_card_data(user_id, uid, use_cache=True):
|
||||
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
||||
url = "https://api-takumi-record.mihoyo.com/game_record/app/genshin/api/index"
|
||||
@ -72,7 +72,7 @@ async def get_player_card_data(user_id, uid, use_cache=True):
|
||||
return data
|
||||
|
||||
|
||||
@AsyncCache(ttl=datetime.timedelta(hours=1))
|
||||
@cache(ttl=datetime.timedelta(hours=1))
|
||||
async def get_chara_detail_data(user_id, uid, use_cache=True):
|
||||
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
||||
json_data = {
|
||||
@ -95,7 +95,7 @@ async def get_chara_detail_data(user_id, uid, use_cache=True):
|
||||
return data
|
||||
|
||||
|
||||
@AsyncCache(ttl=datetime.timedelta(hours=1))
|
||||
@cache(ttl=datetime.timedelta(hours=1))
|
||||
async def get_chara_skill_data(uid, chara_id, use_cache=True):
|
||||
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
||||
url = 'https://api-takumi.mihoyo.com/event/e20200928calculate/v1/sync/avatar/detail'
|
||||
@ -114,7 +114,7 @@ async def get_chara_skill_data(uid, chara_id, use_cache=True):
|
||||
return data
|
||||
|
||||
|
||||
@AsyncCache(ttl=datetime.timedelta(hours=1))
|
||||
@cache(ttl=datetime.timedelta(hours=1))
|
||||
async def get_monthinfo_data(uid, month, use_cache=True):
|
||||
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
||||
url = 'https://hk4e-api.mihoyo.com/event/ys_ledger/monthInfo'
|
||||
|
@ -30,36 +30,6 @@ def auto_withdraw(seconds: int = -1):
|
||||
|
||||
# 缓存装饰器 ttl为过期时间 参数use_cache决定是否使用缓存,默认为True
|
||||
def cache(ttl=datetime.timedelta(hours=1)):
|
||||
def wrap(func):
|
||||
cache_data = {}
|
||||
|
||||
@functools.wraps(func)
|
||||
def wrapped(*args, **kw):
|
||||
nonlocal cache_data
|
||||
bound = inspect.signature(func).bind(*args, **kw)
|
||||
bound.apply_defaults()
|
||||
ins_key = '|'.join(['%s_%s' % (k, v) for k, v in bound.arguments.items()])
|
||||
default_data = {"time": None, "value": None}
|
||||
data = cache_data.get(ins_key, default_data)
|
||||
now = datetime.datetime.now()
|
||||
if 'use_cache' not in kw:
|
||||
kw['use_cache'] = True
|
||||
if not kw['use_cache'] or not data['time'] or now - data['time'] > ttl:
|
||||
try:
|
||||
data['value'] = func(*args, **kw)
|
||||
data['time'] = now
|
||||
cache_data[ins_key] = data
|
||||
except Exception as e:
|
||||
raise e
|
||||
return data['value']
|
||||
|
||||
return wrapped
|
||||
|
||||
return wrap
|
||||
|
||||
|
||||
# 缓存装饰异步版
|
||||
def AsyncCache(ttl=datetime.timedelta(hours=1)):
|
||||
def wrap(func):
|
||||
cache_data = {}
|
||||
|
||||
|
@ -5,17 +5,13 @@ from typing import Union, Optional, Tuple
|
||||
from ssl import SSLCertVerificationError
|
||||
from PIL import Image
|
||||
|
||||
from .decorator import cache
|
||||
|
||||
|
||||
@cache()
|
||||
def load_image(
|
||||
path: Union[Path, str],
|
||||
*,
|
||||
size: Optional[Union[Tuple[int, int], float]] = None,
|
||||
crop: Optional[Tuple[int, int, int, int]] = None,
|
||||
mode: Optional[str] = None,
|
||||
use_cache: bool = True
|
||||
):
|
||||
img = Image.open(path)
|
||||
if size:
|
||||
|
Loading…
Reference in New Issue
Block a user