🐛 优化导入抽卡记录提示,修复命令描述过长可能导致的问题

This commit is contained in:
CMHopeSunshine 2022-09-11 12:56:53 +08:00
parent cf7c1d73a5
commit 9545983396
5 changed files with 31 additions and 20 deletions

View File

@ -7,7 +7,7 @@ from tortoise.models import Model
class PluginPermission(Model): class PluginPermission(Model):
id = fields.IntField(pk=True, generated=True, auto_increment=True) 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() session_id: int = fields.IntField()
"""会话id""" """会话id"""
@ -26,11 +26,11 @@ class PluginPermission(Model):
class PluginStatistics(Model): class PluginStatistics(Model):
id = fields.IntField(pk=True, generated=True, auto_increment=True) 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) group_id: int = fields.IntField(null=True)
"""群id""" """群id"""

View File

@ -92,7 +92,7 @@ def create_guess_matcher(group_id, role_name, game_time):
re_str = '|'.join(alias_list) re_str = '|'.join(alias_list)
guess_matcher = on_regex(re_str, temp=True, rule=Rule(check_group), guess_matcher = on_regex(re_str, temp=True, rule=Rule(check_group),
expire_time=datetime.timedelta(seconds=game_time)) expire_time=datetime.timedelta(seconds=game_time))
guess_matcher.plugin_name = "Guess_voice" guess_matcher.plugin_name = "Genshin_voice"
@guess_matcher.handle() @guess_matcher.handle()
async def _(event: GroupMessageEvent): async def _(event: GroupMessageEvent):

View File

@ -2,13 +2,12 @@ import datetime
import random import random
from LittlePaimon.config import RESOURCE_BASE_PATH 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 PMImage
from LittlePaimon.utils.image import font_manager as fm from LittlePaimon.utils.image import font_manager as fm
from LittlePaimon.utils.message import MessageBuild from LittlePaimon.utils.message import MessageBuild
async def draw_daily_note_card(data, uid): async def draw_daily_note_card(data, uid):
circle_img = await load_image(RESOURCE_BASE_PATH / 'daily_note' / '透明圆.png') circle_img = await load_image(RESOURCE_BASE_PATH / 'daily_note' / '透明圆.png')
finished_icon = await load_image(RESOURCE_BASE_PATH / 'daily_note' / 'finished.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"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.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: if data['current_resin'] == 160:
await bg_img.text("树脂满了哦~", 892, 480, fm.get('优设标题黑.ttf', 40), 'white') await bg_img.text("树脂满了哦~", 892, 480, fm.get('优设标题黑.ttf', 40), 'white')
else: 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), await bg_img.text(f"{data['current_home_coin']}/{data['max_home_coin']}", 337, 701, fm.get('number.ttf', 48),
'white') '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']: if data['current_home_coin'] == data['max_home_coin']:
await bg_img.text("洞天宝钱满了哦~", 820, 701, fm.get('优设标题黑.ttf', 40), 'white') await bg_img.text("洞天宝钱满了哦~", 820, 701, fm.get('优设标题黑.ttf', 40), 'white')
else: 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(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.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: if data['finished_task_num'] == 4:
await bg_img.text("今日委托已全部完成~", 750, 924, fm.get('优设标题黑.ttf', 40), 'white') await bg_img.text("今日委托已全部完成~", 750, 924, fm.get('优设标题黑.ttf', 40), 'white')
else: else:
@ -53,7 +55,8 @@ async def draw_daily_note_card(data, uid):
if data['transformer']['obtained']: if data['transformer']['obtained']:
await bg_img.text(f"{7 - data['transformer']['recovery_time']['Day']}/7", 337, 1147, fm.get('number.ttf', 48), await bg_img.text(f"{7 - data['transformer']['recovery_time']['Day']}/7", 337, 1147, fm.get('number.ttf', 48),
'white') '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'] rt = data['transformer']['recovery_time']
if rt['Day'] == 0 and rt['reached']: if rt['Day'] == 0 and rt['reached']:
await bg_img.text("可使用", 465, 1147, fm.get('优设标题黑.ttf', 40), 'white') 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("未获得", 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.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: if data['remain_resin_discount_num'] == 0:
await bg_img.text("已完成", 1005, 1147, fm.get('优设标题黑.ttf', 40), 'white') await bg_img.text("已完成", 1005, 1147, fm.get('优设标题黑.ttf', 40), 'white')
else: 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}/{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}天结束", 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') 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'] 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], role_avatar = await load_image(RESOURCE_BASE_PATH / 'avatar_side' / role['avatar_side_icon'].split('/')[-1],
size=(135, 135), mode='RGBA') size=(135, 135), mode='RGBA')
await bg_img.paste(role_avatar, (i * 200 + 168, 1537)) 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': if role['status'] == 'Ongoing':
await bg_img.paste(circle_img, (i * 201 + 172, 1559)) await bg_img.paste(circle_img, (i * 201 + 172, 1559))
hour = int(role['remained_time']) // 3600 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') await bg_img.text(last_finish_str, 1408, 1588, fm.get('优设标题黑.ttf', 60), '#5680d2')
else: else:
await bg_img.text('未安排派遣', 1408, 1588, fm.get('优设标题黑.ttf', 60), '#5680d2') 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)) await bg_img.paste(role_img, (1220, 200))
now = datetime.datetime.now().strftime('%m月%d%H:%M') now = datetime.datetime.now().strftime('%m月%d%H:%M')
await bg_img.text('Created by LittlePaimon·' + now, 554, 1794, fm.get('优设标题黑.ttf', 40), '#5680d2') await bg_img.text('Created by LittlePaimon·' + now, 554, 1794, fm.get('优设标题黑.ttf', 40), '#5680d2')

View File

@ -192,6 +192,7 @@ def create_import_command(user_id: int):
data = data.json() data = data.json()
new_num = 0 new_num = 0
uid = data['info']['uid'] uid = data['info']['uid']
await import_cmd.send(f'开始导入UID{uid}的抽卡记录,请稍候...', at_sender=True)
logger.info('原神抽卡记录', '', {'用户': user_id, 'UID': uid}, '导入抽卡记录', True) logger.info('原神抽卡记录', '', {'用户': user_id, 'UID': uid}, '导入抽卡记录', True)
gacha_log, _ = load_history_info(str(event_data['user_id']), uid) gacha_log, _ = load_history_info(str(event_data['user_id']), uid)
for item in data['list']: 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) await import_cmd.send(f'UID{uid}抽卡记录导入完成,本次没有新增数据', at_sender=True)
else: else:
await import_cmd.send(f'UID{uid}抽卡记录导入完成,共新增{new_num}条抽卡记录', at_sender=True) await import_cmd.send(f'UID{uid}抽卡记录导入完成,共新增{new_num}条抽卡记录', at_sender=True)
except Exception as e: except Exception:
await import_cmd.finish(f'导入抽卡记录时发生错误,错误信息:{e}', at_sender=True) await import_cmd.finish('导入抽卡记录失败请确认文件是否符合UIGF统一祈愿可交换标准', at_sender=True)

View File

@ -13,6 +13,7 @@ import tqdm.asyncio
from ruamel import yaml from ruamel import yaml
cache_image: Dict[str, any] = {} 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( async def load_image(
@ -38,11 +39,13 @@ async def load_image(
if path.exists(): if path.exists():
img = Image.open(path) img = Image.open(path)
elif path.name.startswith(('UI_', 'Skill_')): 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: try:
img = await aiorequests.get_img(f'https://enka.network/ui/{path.name}', headers=headers, save_path=path, follow_redirects=True) img = await aiorequests.get_img(f'https://enka.network/ui/{path.name}', headers=headers, save_path=path, follow_redirects=True)
except Exception as e: except Exception:
raise FileNotFoundError(f'{path} not found') from e 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: else:
raise FileNotFoundError(f'{path} not found') raise FileNotFoundError(f'{path} not found')
cache_image[str(path)] = img cache_image[str(path)] = img