From 1f6ba5a2e33a4e177663bc26947d90d1705ddd7c Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Sun, 25 Sep 2022 00:27:14 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20`=E6=AF=8F=E6=97=A5=E6=9D=90?= =?UTF-8?q?=E6=96=99`=E6=98=BE=E7=A4=BA=E5=90=8D=E5=AD=97=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E7=BB=BF=E8=89=B2=E6=98=BE=E7=A4=BA=E5=B7=B2=E6=8B=A5?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E8=A7=92=E8=89=B2/=E6=AD=A6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/plugin_manager/manager.py | 2 +- .../plugins/Learning_Chat/__init__.py | 2 +- LittlePaimon/plugins/Paimon_Wiki/__init__.py | 4 +- .../Paimon_Wiki/draw_daily_material.py | 55 +++++++++++++------ 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/LittlePaimon/manager/plugin_manager/manager.py b/LittlePaimon/manager/plugin_manager/manager.py index 057f84c..3406f97 100644 --- a/LittlePaimon/manager/plugin_manager/manager.py +++ b/LittlePaimon/manager/plugin_manager/manager.py @@ -101,7 +101,7 @@ class PluginManager: for matcher in matchers: if matcher._default_state: matcher_info = MatcherInfo.parse_obj(matcher._default_state) - if matcher_info.pm_name not in [m.pm_name for m in self.data[plugin.name].matchers]: + if self.data[plugin.name].matchers is not None and matcher_info.pm_name not in [m.pm_name for m in self.data[plugin.name].matchers]: self.data[plugin.name].matchers.append(matcher_info) self.save() logger.success('插件管理器', '初始化完成') diff --git a/LittlePaimon/plugins/Learning_Chat/__init__.py b/LittlePaimon/plugins/Learning_Chat/__init__.py index 4a531e8..10a12fd 100644 --- a/LittlePaimon/plugins/Learning_Chat/__init__.py +++ b/LittlePaimon/plugins/Learning_Chat/__init__.py @@ -75,7 +75,7 @@ learning_chat = on_message(priority=99, block=False, rule=Rule(chat_rule), permi 'pm_usage': '群聊学习', 'pm_priority': 1 }) -ban_chat = on_keyword({'不可以', '达咩', '不行', 'no'}, rule=to_me(), priority=1, block=True, state={ +ban_chat = on_keyword({'不可以', '达咩', '不行'}, rule=to_me(), priority=1, block=True, state={ 'pm_name': '群聊学习禁用', 'pm_description': '如果bot说了不好的话,回复这句话,告诉TA不能这么说,需管理权限', 'pm_usage': '@bot 不可以', diff --git a/LittlePaimon/plugins/Paimon_Wiki/__init__.py b/LittlePaimon/plugins/Paimon_Wiki/__init__.py index ed72570..d0180cc 100644 --- a/LittlePaimon/plugins/Paimon_Wiki/__init__.py +++ b/LittlePaimon/plugins/Paimon_Wiki/__init__.py @@ -97,11 +97,11 @@ async def _(event: MessageEvent, regex_dict: dict = RegexDict()): elif regex_dict['day'] == '周日': await daily_material.finish('周日所有材料都可以刷哦!', at_sender=True) elif regex_dict['day'].startswith('周'): - await daily_material.finish(await draw_material(regex_dict['day'])) + await daily_material.finish(await draw_material(str(event.user_id), regex_dict['day'])) if day == '0': await daily_material.finish('周日所有材料都可以刷哦!', at_sender=True) else: - await daily_material.finish(await draw_material({ + await daily_material.finish(await draw_material(str(event.user_id), { '1': '周一', '2': '周二', '3': '周三', diff --git a/LittlePaimon/plugins/Paimon_Wiki/draw_daily_material.py b/LittlePaimon/plugins/Paimon_Wiki/draw_daily_material.py index 8c7c783..280d8af 100644 --- a/LittlePaimon/plugins/Paimon_Wiki/draw_daily_material.py +++ b/LittlePaimon/plugins/Paimon_Wiki/draw_daily_material.py @@ -5,6 +5,7 @@ from LittlePaimon.utils import aiorequests, scheduler from LittlePaimon.utils.files import save_json, load_json, load_image from LittlePaimon.utils.image import PMImage, font_manager as fm from LittlePaimon.utils.message import MessageBuild +from LittlePaimon.database.models import Character, LastQuery week_cn = { 'monday': '周一', @@ -30,6 +31,10 @@ async def get_daily_material(): daily_data = (await aiorequests.get(DAILY_URL)).json()['data'] material_data = (await aiorequests.get(MATERIAL_URL)).json()['data'] upgrade_data = (await aiorequests.get(UPGRADE_URL)).json()['data'] + detail_data = { + 'avatar': (await aiorequests.get(CHARACTER_URL)).json()['data']['items'], + 'weapon': (await aiorequests.get(WEAPON_URL)).json()['data']['items'] + } for week in daily_data: if week == 'sunday': continue @@ -39,16 +44,17 @@ async def get_daily_material(): for domain_key in domain_data_sort: item_type = 'avatar' if domain_data[domain_key]['name'].startswith('精通秘境') else 'weapon' material = material_data['items'][str(domain_data[domain_key]['reward'][-1])] - used = [upgrade_data[item_type][id] for id in upgrade_data[item_type] if + used = [(upgrade_data[item_type][id], detail_data[item_type][id]['name']) for id in upgrade_data[item_type] + if str(material['id']) in upgrade_data[item_type][id]['items'] and 'Player' not in upgrade_data[item_type][id]['icon']] daily_info['天赋' if item_type == 'avatar' else '武器'][week_cn[week]][ - f'{material["name"]}-{material["icon"]}'] = [f'{u["rank"]}{u["icon"]}' for u in used] - save_json(daily_info, Path() / 'data' / 'LittlePaimon' / 'daily_material.json') + f'{material["name"]}-{material["icon"]}'] = [f'{u["rank"]}{u["icon"]}-{name}' for u, name in used] + save_json(daily_info, Path() / 'data' / 'LittlePaimon' / 'daily_materials.json') -async def draw_material(week: str = '周一'): - if not (Path() / 'data' / 'LittlePaimon' / 'daily_material.json').exists(): +async def draw_material(user_id: str, week: str = '周一'): + if not (Path() / 'data' / 'LittlePaimon' / 'daily_materials.json').exists(): await get_daily_material() if week in {'周一', '周四'}: week_str = '周一/周四' @@ -56,11 +62,18 @@ async def draw_material(week: str = '周一'): week_str = '周二/周五' else: week_str = '周三/周六' - daily_info = load_json(Path() / 'data' / 'LittlePaimon' / 'daily_material.json') + daily_info = load_json(Path() / 'data' / 'LittlePaimon' / 'daily_materials.json') avatar = daily_info['天赋'][week] weapon = daily_info['武器'][week] - total_height = max(70 * len(avatar) + sum(math.ceil(len(items) / 5) * 140 for items in avatar.values()), - 70 * len(weapon) + sum(math.ceil(len(items) / 5) * 140 for items in weapon.values())) + 165 + if last_query := await LastQuery.get_or_none(user_id=user_id): + charas = await Character.filter(user_id=user_id, uid=last_query.uid) + else: + charas = await Character.filter(user_id=user_id) + characters = [chara.name for chara in charas if chara is not None] + weapons = [chara.weapon.name for chara in charas if chara.weapon is not None] + # total_height = max(70 * len(avatar) + sum(math.ceil(len(items) / 5) * 160 for items in avatar.values()), + # 70 * len(weapon) + sum(math.ceil(len(items) / 5) * 160 for items in weapon.values())) + 165 + total_height = 70 * len(weapon) + sum(math.ceil(len(items) / 5) * 160 for items in weapon.values()) + 165 img = PMImage(RESOURCE_BASE_PATH / 'general' / 'bg.png') await img.stretch((50, img.width - 50), 1520, 'width') await img.stretch((50, img.height - 50), total_height - 100, 'height') @@ -85,11 +98,15 @@ async def draw_material(week: str = '周一'): items.sort(key=lambda x: int(x[0]), reverse=True) for i in range(len(items)): star = items[i][0] - icon = items[i][1:] - await img.paste(star_bg[star], (90 + 128 * (i % 5), now_height + 125 * int(i / 5))) + icon = items[i][1:].split('-')[0] + name_ = items[i][1:].split('-')[1] + await img.paste(star_bg[star], (90 + 128 * (i % 5), now_height + 145 * int(i / 5))) await img.paste(await load_image(RESOURCE_BASE_PATH / 'avatar' / f'{icon}.png', size=(110, 110)), - (90 + 128 * (i % 5), now_height + 125 * int(i / 5))) - now_height += math.ceil(len(items) / 5) * 125 + 15 + (90 + 128 * (i % 5), now_height + 145 * int(i / 5))) + await img.text(name_, (90 + 128 * (i % 5), 90 + 128 * (i % 5) + 110), now_height + 145 * int(i / 5) + 110, + fm.get('SourceHanSerifCN-Bold.otf', 20), 'green' if name_ in characters else 'black', + 'center') + now_height += math.ceil(len(items) / 5) * 145 + 70 now_height = 165 for name, items in weapon.items(): name, icon = name.split('-') @@ -101,16 +118,20 @@ async def draw_material(week: str = '周一'): items.sort(key=lambda x: int(x[0]), reverse=True) for i in range(len(items)): star = items[i][0] - icon = items[i][1:] - await img.paste(star_bg[star], (908 + 128 * (i % 5), now_height + 125 * int(i / 5))) + icon = items[i][1:].split('-')[0] + name_ = items[i][1:].split('-')[1] + await img.paste(star_bg[star], (908 + 128 * (i % 5), now_height + 145 * int(i / 5))) await img.paste(await load_image(RESOURCE_BASE_PATH / 'weapon' / f'{icon}.png', size=(110, 110)), - (908 + 128 * (i % 5), now_height + 125 * int(i / 5))) - now_height += math.ceil(len(items) / 5) * 125 + 15 + (908 + 128 * (i % 5), now_height + 145 * int(i / 5))) + await img.text(name_, (908 + 128 * (i % 5), 908 + 128 * (i % 5) + 110), now_height + 145 * int(i / 5) + 110, + fm.get('SourceHanSerifCN-Bold.otf', 20), 'green' if name_ in weapons else 'black', 'center') + now_height += math.ceil(len(items) / 5) * 145 + 15 await img.text('CREATED BY LITTLEPAIMON', (0, img.width), img.height - 83, fm.get('bahnschrift_bold', 44, 'Bold'), '#3c3c3c', align='center') return MessageBuild.Image(img, mode='RGB', quality=80) + @scheduler.scheduled_job('cron', hour=7, misfire_grace_time=10) async def update_daily_material(): - await get_daily_material() \ No newline at end of file + await get_daily_material()