mirror of
https://github.com/PaiGramTeam/PamGram.git
synced 2024-11-16 03:55:26 +00:00
✨ Support starrail activity - TreasureDungeon
This commit is contained in:
parent
1fafbea483
commit
ddccf1118d
@ -1,6 +1,11 @@
|
||||
from typing import Optional, List, Dict, TYPE_CHECKING
|
||||
import asyncio
|
||||
from typing import Optional, List, Dict, TYPE_CHECKING, Any, Coroutine
|
||||
|
||||
from simnet.models.starrail.chronicle.activity import StarRailStarFight, StarRailFantasticStory
|
||||
from simnet.models.starrail.chronicle.activity import (
|
||||
StarRailStarFight,
|
||||
StarRailFantasticStory,
|
||||
StarRailTreasureDungeonRecord,
|
||||
)
|
||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, Message
|
||||
from telegram.constants import ChatAction
|
||||
from telegram.ext import CallbackContext, filters
|
||||
@ -8,8 +13,8 @@ from telegram.helpers import create_deep_linked_url
|
||||
|
||||
from core.dependence.assets import AssetsService
|
||||
from core.plugin import Plugin, handler
|
||||
from core.services.template.models import RenderResult
|
||||
from core.services.template.services import TemplateService
|
||||
from gram_core.services.template.models import RenderResult, RenderGroupResult
|
||||
from plugins.tools.genshin import GenshinHelper, PlayerNotFoundError, CookiesNotFoundError
|
||||
from utils.log import logger
|
||||
|
||||
@ -197,3 +202,81 @@ class PlayerActivityPlugins(Plugin):
|
||||
full_page=True,
|
||||
query_selector="#container",
|
||||
)
|
||||
|
||||
@handler.command("treasure_dungeon", block=False)
|
||||
@handler.message(filters.Regex("^地城探宝信息查询(.*)"), block=False)
|
||||
async def treasure_dungeon_command_start(self, update: Update, context: CallbackContext) -> Optional[int]:
|
||||
user = update.effective_user
|
||||
message = update.effective_message
|
||||
logger.info("用户 %s[%s] 查询地城探宝信息命令请求", user.full_name, user.id)
|
||||
try:
|
||||
uid = await self.get_uid(user.id, context.args, message.reply_to_message)
|
||||
async with self.helper.genshin(user.id) as client:
|
||||
render_result = await self.treasure_dungeon_render(client, uid)
|
||||
if render_result is None:
|
||||
raise NotHaveData
|
||||
except PlayerNotFoundError:
|
||||
buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]]
|
||||
if filters.ChatType.GROUPS.filter(message):
|
||||
reply_message = await message.reply_text(
|
||||
"未查询到您所绑定的账号信息,请先私聊彦卿绑定账号", reply_markup=InlineKeyboardMarkup(buttons)
|
||||
)
|
||||
self.add_delete_message_job(reply_message, delay=30)
|
||||
self.add_delete_message_job(message, delay=30)
|
||||
else:
|
||||
await message.reply_text("未查询到您所绑定的账号信息,请先绑定账号", reply_markup=InlineKeyboardMarkup(buttons))
|
||||
return
|
||||
except AttributeError as exc:
|
||||
logger.error("活动数据有误")
|
||||
logger.exception(exc)
|
||||
await message.reply_text("活动数据有误 估计是彦卿晕了")
|
||||
return
|
||||
except NotHaveData:
|
||||
reply_message = await message.reply_text("没有查找到此活动数据")
|
||||
if filters.ChatType.GROUPS.filter(reply_message):
|
||||
self.add_delete_message_job(message)
|
||||
self.add_delete_message_job(reply_message)
|
||||
return
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||
await RenderGroupResult(results=render_result).reply_media_group(
|
||||
message, allow_sending_without_reply=True, write_timeout=60
|
||||
)
|
||||
logger.info("用户 %s[%s] [bold]地城探宝信息数据[/bold]: 成功发送图片", user.full_name, user.id, extra={"markup": True})
|
||||
|
||||
async def treasure_dungeon_render(self, client: "StarRailClient", uid: Optional[int] = None) -> List[RenderResult]:
|
||||
if uid is None:
|
||||
uid = client.player_id
|
||||
|
||||
act_data = await client.get_starrail_activity(uid)
|
||||
try:
|
||||
data = act_data.treasure_dungeon
|
||||
if not data.exists_data:
|
||||
raise NotHaveData
|
||||
if all(record.finish_time is None for record in data.records):
|
||||
raise NotHaveData
|
||||
except ValueError:
|
||||
raise NotHaveData
|
||||
|
||||
avatar_icons = {}
|
||||
for record in data.records:
|
||||
for avatar in record.avatars:
|
||||
avatar_icons[avatar.id] = self.assets.avatar.icon(avatar.id).as_uri()
|
||||
|
||||
def render(record: StarRailTreasureDungeonRecord) -> Coroutine[Any, Any, RenderResult]:
|
||||
render_data = {
|
||||
"uid": uid,
|
||||
"record": record,
|
||||
"avatar_icons": avatar_icons,
|
||||
}
|
||||
return self.template_service.render(
|
||||
"starrail/activity/treasure_dungeon.html",
|
||||
render_data,
|
||||
{"width": 500, "height": 762},
|
||||
full_page=True,
|
||||
query_selector="#container",
|
||||
)
|
||||
|
||||
tasks = [render(record) for record in data.records if record.finish_time is not None]
|
||||
if len(tasks) == 1:
|
||||
return [await tasks[0]]
|
||||
return await asyncio.gather(*tasks)
|
||||
|
1952
resources/starrail/activity/css/33_8822068204d7dabf8934.css
Normal file
1952
resources/starrail/activity/css/33_8822068204d7dabf8934.css
Normal file
File diff suppressed because one or more lines are too long
@ -12,7 +12,11 @@
|
||||
style="background: url('images/story-bg.436f1d88.png') 0% 0% / 100% no-repeat rgb(71, 89, 131);">
|
||||
<div data-v-6cd4e78c="" class="header">
|
||||
<div data-v-6cd4e78c="" class="border">
|
||||
<div data-v-6cd4e78c="" class="left"><span data-v-6cd4e78c="">评书奇谭</span></div> <!---->
|
||||
<div data-v-6cd4e78c="" class="left"><span data-v-6cd4e78c="">评书奇谭</span></div>
|
||||
<div data-v-e64e4972="" class="right">
|
||||
<span data-v-e64e4972="">UID:{{ uid }}</span>
|
||||
<span data-v-e64e4972=""> </span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-v-6cd4e78c="" class="container">
|
||||
|
BIN
resources/starrail/activity/images/treasure-bg.4e14b9b5.png
Normal file
BIN
resources/starrail/activity/images/treasure-bg.4e14b9b5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
111
resources/starrail/activity/treasure_dungeon.html
Normal file
111
resources/starrail/activity/treasure_dungeon.html
Normal file
@ -0,0 +1,111 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<link href="css/33_8822068204d7dabf8934.css" rel="stylesheet">
|
||||
<style>
|
||||
* {
|
||||
-webkit-box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div data-v-6cd4e78c="" data-v-056bcd56="" class="layout"
|
||||
style="background: url('images/treasure-bg.4e14b9b5.png') 0% 0% / 100% no-repeat rgb(53, 47, 25);">
|
||||
<div data-v-6cd4e78c="" class="header">
|
||||
<div data-v-6cd4e78c="" class="border">
|
||||
<div data-v-6cd4e78c="" class="left"><span data-v-6cd4e78c="">地城探宝</span></div>
|
||||
<div data-v-e64e4972="" class="right">
|
||||
<span data-v-e64e4972="">UID:{{ uid }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-v-6cd4e78c="" class="container">
|
||||
<div data-v-6cd4e78c="" class="border">
|
||||
<div data-v-4c014de0="" class="card" data-v-6cd4e78c="">
|
||||
<div data-v-4c014de0="" class="inner">
|
||||
<div data-v-4c014de0="" class="header">
|
||||
<div data-v-4c014de0="" class="name">
|
||||
{{ record.name }}
|
||||
</div>
|
||||
<div data-v-4c014de0="" class="time">
|
||||
{{ record.time_str }}
|
||||
</div>
|
||||
<div data-v-4c014de0="" class="difficulty" style="background-color: rgb(214, 168, 94);">
|
||||
{% if record.difficulty_id == 0 %}
|
||||
浅层探索
|
||||
{% else %}
|
||||
深层探索
|
||||
{% endif %}
|
||||
</div>
|
||||
<div data-v-4c014de0="" class="right">
|
||||
<img data-v-4c014de0="" src="{{ record.icon }}" alt="" class="icon">
|
||||
</div>
|
||||
</div>
|
||||
<div data-v-4c014de0="" class="line"></div>
|
||||
<div data-v-4c014de0="" class="sub-title">参与角色</div>
|
||||
<div data-v-4c014de0="" class="roles">
|
||||
{% for role in record.avatars %}
|
||||
<div data-v-4c014de0="" class="avatar-item">
|
||||
<img data-v-4c014de0="" src="{{ avatar_icons[role.id] }}" class="icon">
|
||||
<span data-v-4c014de0="">等级{{ role.level }}</span>
|
||||
{% if role.is_trial %}
|
||||
<span data-v-4c014de0="" class="is-trial">试用</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div data-v-4c014de0="" class="expand-container is-expand">
|
||||
<div data-v-4c014de0="" class="expand-item half-width">
|
||||
<div data-v-4c014de0="" class="left">
|
||||
<img data-v-4c014de0="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAMAAADzapwJAAAAOVBMVEVHcEz///////////////////////////////////////////////////////////////////////99PJZNAAAAEnRSTlMAMJBg3xDPn4B/UKBvX0BwvyB19BZ7AAAAbklEQVQY063RSw6AIAwEUD5Fivid+x9WLMZY7dJZvpChBed+zpQls9aInqw0kckFFu8wmUyO+HIubgAodOZLR6B44t5Dy93Aza9ROD2axdvhzauZOUjPqtfOGIL06LXbGMyW17O/vp9Urh///qgDYFIHxdPoOxIAAAAASUVORK5CYII=" class="icon">
|
||||
伤害提高
|
||||
</div>
|
||||
<span data-v-4c014de0="">{{ record.atk_buff }}%</span></div>
|
||||
<div data-v-4c014de0="" class="expand-item half-width">
|
||||
<div data-v-4c014de0="" class="left">
|
||||
<img data-v-4c014de0="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAMAAADzapwJAAAARVBMVEVHcEz///////////////////////////////////////////////////////////////////////////////////////9X1DS3AAAAFnRSTlMAvxAwYECg3yDvkIBQr59ff49wb7DPw3T3cwAAAKBJREFUGBmdwVtiwyAMBMAFBJJ42E7a7v2P2sbBNO1nZvCeWNw3wz9ZvVbVHa/ijdWkW+EtYsnqPSmpJqqG6YPBDp4OKzxwymwWOKk1ZjwIoVwUFDwkRufixoST3guXTRRPNQiXPWx4ym5cjBmT58ApdMel1DunvXziIm7Kk5ruuETdbPBHsKL4lTksiaQ42PGiK0drw13wh5UvUlvEO74BTGUNgYPvMN8AAAAASUVORK5CYII=" class="icon">
|
||||
伤害减免
|
||||
</div>
|
||||
<span data-v-4c014de0="">{{ record.def_buff }}%</span></div>
|
||||
<div data-v-4c014de0="" class="expand-item">
|
||||
<div data-v-4c014de0="" class="left"><!---->
|
||||
持续伤害提高
|
||||
</div>
|
||||
<span data-v-4c014de0="">{{ record.special_buff }}%</span></div>
|
||||
<div data-v-4c014de0="" class="expand-item">
|
||||
<div data-v-4c014de0="" class="left"><!---->
|
||||
消耗耐力
|
||||
</div>
|
||||
<span data-v-4c014de0="">{{ record.used_stamina }}</span></div>
|
||||
<div data-v-4c014de0="" class="expand-item">
|
||||
<div data-v-4c014de0="" class="left"><!---->
|
||||
击败敌人数量
|
||||
</div>
|
||||
<span data-v-4c014de0="">{{ record.enemy_killed }}</span></div>
|
||||
<div data-v-4c014de0="" class="expand-item">
|
||||
<div data-v-4c014de0="" class="left"><!---->
|
||||
发现古代兵器
|
||||
</div>
|
||||
<span data-v-4c014de0="">{{ record.ancient_weapon }}</span></div>
|
||||
<div data-v-4c014de0="" class="expand-item">
|
||||
<div data-v-4c014de0="" class="left"><!---->
|
||||
发现古代防具
|
||||
</div>
|
||||
<span data-v-4c014de0="">{{ record.ancient_armor }}</span></div>
|
||||
<div data-v-4c014de0="" class="expand-item">
|
||||
<div data-v-4c014de0="" class="left"><!---->
|
||||
发现古代炸弹
|
||||
</div>
|
||||
<span data-v-4c014de0="">{{ record.ancient_bomb }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user