From 9545983396f0b75b5c8acec40aa9e49bd958acae Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Sun, 11 Sep 2022 12:56:53 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BC=98=E5=8C=96`=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=8A=BD=E5=8D=A1=E8=AE=B0=E5=BD=95`=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=91=BD=E4=BB=A4=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E8=BF=87=E9=95=BF=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/database/models/manager.py | 8 +++--- LittlePaimon/plugins/Genshin_Voice/handler.py | 2 +- LittlePaimon/plugins/Paimon_DailyNote/draw.py | 27 ++++++++++++------- .../plugins/Paimon_Gacha_Log/data_source.py | 5 ++-- LittlePaimon/utils/files.py | 9 ++++--- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/LittlePaimon/database/models/manager.py b/LittlePaimon/database/models/manager.py index ac6c19b..e2a5b20 100644 --- a/LittlePaimon/database/models/manager.py +++ b/LittlePaimon/database/models/manager.py @@ -7,7 +7,7 @@ from tortoise.models import Model class PluginPermission(Model): id = fields.IntField(pk=True, generated=True, auto_increment=True) - name: str = fields.CharField(max_length=255) + name: str = fields.TextField() """插件名称""" session_id: int = fields.IntField() """会话id""" @@ -26,11 +26,11 @@ class PluginPermission(Model): class PluginStatistics(Model): id = fields.IntField(pk=True, generated=True, auto_increment=True) - plugin_name: str = fields.CharField(max_length=255) + plugin_name: str = fields.TextField() """插件名称""" - matcher_name: str = fields.CharField(max_length=255) + matcher_name: str = fields.TextField() """命令名称""" - matcher_usage: str = fields.CharField(max_length=255, null=True) + matcher_usage: str = fields.TextField(null=True) """命令用法""" group_id: int = fields.IntField(null=True) """群id""" diff --git a/LittlePaimon/plugins/Genshin_Voice/handler.py b/LittlePaimon/plugins/Genshin_Voice/handler.py index 1d96901..b996654 100644 --- a/LittlePaimon/plugins/Genshin_Voice/handler.py +++ b/LittlePaimon/plugins/Genshin_Voice/handler.py @@ -92,7 +92,7 @@ def create_guess_matcher(group_id, role_name, game_time): re_str = '|'.join(alias_list) guess_matcher = on_regex(re_str, temp=True, rule=Rule(check_group), expire_time=datetime.timedelta(seconds=game_time)) - guess_matcher.plugin_name = "Guess_voice" + guess_matcher.plugin_name = "Genshin_voice" @guess_matcher.handle() async def _(event: GroupMessageEvent): diff --git a/LittlePaimon/plugins/Paimon_DailyNote/draw.py b/LittlePaimon/plugins/Paimon_DailyNote/draw.py index 580f3e3..3917cc9 100644 --- a/LittlePaimon/plugins/Paimon_DailyNote/draw.py +++ b/LittlePaimon/plugins/Paimon_DailyNote/draw.py @@ -2,13 +2,12 @@ import datetime import random from LittlePaimon.config import RESOURCE_BASE_PATH -from LittlePaimon.utils import logger, load_image +from LittlePaimon.utils import load_image from LittlePaimon.utils.image import PMImage from LittlePaimon.utils.image import font_manager as fm from LittlePaimon.utils.message import MessageBuild - async def draw_daily_note_card(data, uid): circle_img = await load_image(RESOURCE_BASE_PATH / 'daily_note' / '透明圆.png') finished_icon = await load_image(RESOURCE_BASE_PATH / 'daily_note' / 'finished.png') @@ -17,7 +16,8 @@ async def draw_daily_note_card(data, uid): await bg_img.text(f"uid{uid}", 152, 251, fm.get('number.ttf', 60), '#5680d2') # 树脂文字 await bg_img.text(f"{data['current_resin']}/160", 337, 480, fm.get('number.ttf', 48), 'white') - await bg_img.draw_ring((266, 266), (98, 369), percent=data['current_resin'] / 160, width=0.18, colors=['#507bd0', '#FFFFFF']) + await bg_img.draw_ring((266, 266), (98, 369), percent=data['current_resin'] / 160, width=0.18, + colors=['#507bd0', '#FFFFFF']) if data['current_resin'] == 160: await bg_img.text("树脂满了哦~", 892, 480, fm.get('优设标题黑.ttf', 40), 'white') else: @@ -28,7 +28,8 @@ async def draw_daily_note_card(data, uid): # 宝钱文字 await bg_img.text(f"{data['current_home_coin']}/{data['max_home_coin']}", 337, 701, fm.get('number.ttf', 48), 'white') - await bg_img.draw_ring((266, 266), (98, 593), percent=data['current_home_coin'] / (data['max_home_coin'] if data['max_home_coin'] !=0 else 1), width=0.18, colors=['#507bd0', '#FFFFFF']) + await bg_img.draw_ring((266, 266), (98, 593), percent=data['current_home_coin'] / ( + data['max_home_coin'] if data['max_home_coin'] != 0 else 1), width=0.18, colors=['#507bd0', '#FFFFFF']) if data['current_home_coin'] == data['max_home_coin']: await bg_img.text("洞天宝钱满了哦~", 820, 701, fm.get('优设标题黑.ttf', 40), 'white') else: @@ -44,7 +45,8 @@ async def draw_daily_note_card(data, uid): await bg_img.text(recover_time_str, 762, 701, fm.get('优设标题黑.ttf', 40), 'white') # 委托文字 await bg_img.text(f"{data['finished_task_num']}/4", 337, 924, fm.get('number.ttf', 48), 'white') - await bg_img.draw_ring((266, 266), (98, 816), percent=data['finished_task_num'] / 4, width=0.18, colors=['#507bd0', '#FFFFFF']) + await bg_img.draw_ring((266, 266), (98, 816), percent=data['finished_task_num'] / 4, width=0.18, + colors=['#507bd0', '#FFFFFF']) if data['finished_task_num'] == 4: await bg_img.text("今日委托已全部完成~", 750, 924, fm.get('优设标题黑.ttf', 40), 'white') else: @@ -53,7 +55,8 @@ async def draw_daily_note_card(data, uid): if data['transformer']['obtained']: await bg_img.text(f"{7 - data['transformer']['recovery_time']['Day']}/7", 337, 1147, fm.get('number.ttf', 48), 'white') - await bg_img.draw_ring((266, 266), (98, 1039), percent=(7 - data['transformer']['recovery_time']['Day']) / 7, width=0.18, colors=['#507bd0', '#FFFFFF']) + await bg_img.draw_ring((266, 266), (98, 1039), percent=(7 - data['transformer']['recovery_time']['Day']) / 7, + width=0.18, colors=['#507bd0', '#FFFFFF']) rt = data['transformer']['recovery_time'] if rt['Day'] == 0 and rt['reached']: await bg_img.text("可使用", 465, 1147, fm.get('优设标题黑.ttf', 40), 'white') @@ -67,7 +70,8 @@ async def draw_daily_note_card(data, uid): await bg_img.text("未获得", 337, 1143, fm.get('优设标题黑.ttf', 48), 'white') # 周本文字 await bg_img.text(f"{3 - data['remain_resin_discount_num']}/3", 843, 1147, fm.get('number.ttf', 48), 'white') - await bg_img.draw_ring((266, 266), (604, 1039), percent=(3 - data['remain_resin_discount_num']) / 3, width=0.18, colors=['#507bd0', '#FFFFFF']) + await bg_img.draw_ring((266, 266), (604, 1039), percent=(3 - data['remain_resin_discount_num']) / 3, width=0.18, + colors=['#507bd0', '#FFFFFF']) if data['remain_resin_discount_num'] == 0: await bg_img.text("已完成", 1005, 1147, fm.get('优设标题黑.ttf', 40), 'white') else: @@ -87,7 +91,8 @@ async def draw_daily_note_card(data, uid): await bg_img.text(f"{abyss_new.days}/{abyss_new_total.days}", 337, 1358, fm.get('number.ttf', 48), 'white') await bg_img.text(f"本期深渊还有{abyss_new.days if abyss_new.days <= abyss_new_total.days else abyss_new_total.days}天结束", 745, 1358, fm.get('优设标题黑.ttf', 40), 'white') - await bg_img.draw_ring(percent=abyss_new.days / abyss_new_total.days, pos=(100, 1249), size=(266, 266), width=0.18, colors=['#507bd0', '#FFFFFF']) + await bg_img.draw_ring(percent=abyss_new.days / abyss_new_total.days, pos=(100, 1249), size=(266, 266), width=0.18, + colors=['#507bd0', '#FFFFFF']) # 派遣情况 exp = data['expeditions'] @@ -98,7 +103,8 @@ async def draw_daily_note_card(data, uid): role_avatar = await load_image(RESOURCE_BASE_PATH / 'avatar_side' / role['avatar_side_icon'].split('/')[-1], size=(135, 135), mode='RGBA') await bg_img.paste(role_avatar, (i * 200 + 168, 1537)) - await bg_img.draw_ring(percent=1 - int(role['remained_time']) / 72000, pos=(i * 201 + 101, 1490), size=(266, 266), width=0.18, colors=['#507bd0', '#FFFFFF']) + await bg_img.draw_ring(percent=1 - int(role['remained_time']) / 72000, pos=(i * 201 + 101, 1490), + size=(266, 266), width=0.18, colors=['#507bd0', '#FFFFFF']) if role['status'] == 'Ongoing': await bg_img.paste(circle_img, (i * 201 + 172, 1559)) hour = int(role['remained_time']) // 3600 @@ -121,7 +127,8 @@ async def draw_daily_note_card(data, uid): await bg_img.text(last_finish_str, 1408, 1588, fm.get('优设标题黑.ttf', 60), '#5680d2') else: await bg_img.text('未安排派遣', 1408, 1588, fm.get('优设标题黑.ttf', 60), '#5680d2') - role_img = await load_image(random.choice(list((RESOURCE_BASE_PATH / 'emoticons').iterdir())), size=3.5, mode='RGBA') + role_img = await load_image(random.choice(list((RESOURCE_BASE_PATH / 'emoticons').iterdir())), size=3.5, + mode='RGBA') await bg_img.paste(role_img, (1220, 200)) now = datetime.datetime.now().strftime('%m月%d日%H:%M') await bg_img.text('Created by LittlePaimon·' + now, 554, 1794, fm.get('优设标题黑.ttf', 40), '#5680d2') diff --git a/LittlePaimon/plugins/Paimon_Gacha_Log/data_source.py b/LittlePaimon/plugins/Paimon_Gacha_Log/data_source.py index c6be696..8ac96ed 100644 --- a/LittlePaimon/plugins/Paimon_Gacha_Log/data_source.py +++ b/LittlePaimon/plugins/Paimon_Gacha_Log/data_source.py @@ -192,6 +192,7 @@ def create_import_command(user_id: int): data = data.json() new_num = 0 uid = data['info']['uid'] + await import_cmd.send(f'开始导入UID{uid}的抽卡记录,请稍候...', at_sender=True) logger.info('原神抽卡记录', '➤', {'用户': user_id, 'UID': uid}, '导入抽卡记录', True) gacha_log, _ = load_history_info(str(event_data['user_id']), uid) for item in data['list']: @@ -208,5 +209,5 @@ def create_import_command(user_id: int): await import_cmd.send(f'UID{uid}抽卡记录导入完成,本次没有新增数据', at_sender=True) else: await import_cmd.send(f'UID{uid}抽卡记录导入完成,共新增{new_num}条抽卡记录', at_sender=True) - except Exception as e: - await import_cmd.finish(f'导入抽卡记录时发生错误,错误信息:{e}', at_sender=True) + except Exception: + await import_cmd.finish('导入抽卡记录失败,请确认文件是否符合UIGF统一祈愿可交换标准', at_sender=True) diff --git a/LittlePaimon/utils/files.py b/LittlePaimon/utils/files.py index 409094d..db9fb57 100644 --- a/LittlePaimon/utils/files.py +++ b/LittlePaimon/utils/files.py @@ -13,6 +13,7 @@ import tqdm.asyncio from ruamel import yaml cache_image: Dict[str, any] = {} +headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'} async def load_image( @@ -38,11 +39,13 @@ async def load_image( if path.exists(): img = Image.open(path) elif path.name.startswith(('UI_', 'Skill_')): - headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'} try: img = await aiorequests.get_img(f'https://enka.network/ui/{path.name}', headers=headers, save_path=path, follow_redirects=True) - except Exception as e: - raise FileNotFoundError(f'{path} not found') from e + except Exception: + try: + img = await aiorequests.get_img(f'https://file.minigg.icu/genshin/ui/{path.name}', headers=headers, save_path=path, follow_redirects=True) + except Exception as e: + raise FileNotFoundError(f'{path} not found') from e else: raise FileNotFoundError(f'{path} not found') cache_image[str(path)] = img