mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-10-21 16:27:15 +08:00
✨ 每日材料
显示名字,以绿色显示已拥有的角色/武器
This commit is contained in:
parent
53b699fca8
commit
1f6ba5a2e3
@ -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('插件管理器', '<g>初始化完成</g>')
|
||||
|
@ -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 不可以',
|
||||
|
@ -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': '周三',
|
||||
|
@ -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()
|
Loading…
Reference in New Issue
Block a user