mirror of
https://github.com/PaiGramTeam/PamGram.git
synced 2024-11-16 03:55:26 +00:00
✨ Support starrail rogue locust
This commit is contained in:
parent
3c8f3931cb
commit
a29fa75415
@ -2,7 +2,7 @@ from typing import Optional, List, Dict, Tuple, TYPE_CHECKING
|
||||
|
||||
from simnet.errors import BadRequest as SimnetBadRequest
|
||||
from simnet.models.starrail.character import RogueCharacter
|
||||
from simnet.models.starrail.chronicle.rogue import StarRailRogue
|
||||
from simnet.models.starrail.chronicle.rogue import StarRailRogue, StarRailRogueLocust
|
||||
from telegram import Update, Message
|
||||
from telegram.constants import ChatAction
|
||||
from telegram.ext import CallbackContext, filters
|
||||
@ -34,6 +34,20 @@ class NotHaveData(Exception):
|
||||
class PlayerRoguePlugins(Plugin):
|
||||
"""玩家模拟宇宙信息查询"""
|
||||
|
||||
LUO_MA = ["", "Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ"]
|
||||
BUFF_EN = {
|
||||
"「丰饶」": "Abundance",
|
||||
"「毁灭」": "Destruction",
|
||||
"「智识」": "Erudition",
|
||||
"「协同」": "Harmony",
|
||||
"「巡猎」": "Hunt",
|
||||
"「欢愉」": "Joy",
|
||||
"「记忆」": "Memory",
|
||||
"「虚无」": "Nihility",
|
||||
"「存护」": "Preservation",
|
||||
"「繁育」": "Propagation",
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
template: TemplateService,
|
||||
@ -114,18 +128,6 @@ class PlayerRoguePlugins(Plugin):
|
||||
await render_result.reply_photo(message, filename=f"{user.id}.png", allow_sending_without_reply=True)
|
||||
|
||||
async def get_rander_data(self, uid: int, data: StarRailRogue, pre: bool) -> Dict:
|
||||
luo_ma_bum = ["", "Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ"]
|
||||
buff_en_map = {
|
||||
"「丰饶」": "Abundance",
|
||||
"「毁灭」": "Destruction",
|
||||
"「智识」": "Erudition",
|
||||
"「协同」": "Harmony",
|
||||
"「巡猎」": "Hunt",
|
||||
"「欢愉」": "Joy",
|
||||
"「记忆」": "Memory",
|
||||
"「虚无」": "Nihility",
|
||||
"「存护」": "Preservation",
|
||||
}
|
||||
record_raw = data.last_record if pre else data.current_record
|
||||
if not record_raw.has_data:
|
||||
raise NotHaveData
|
||||
@ -140,13 +142,13 @@ class PlayerRoguePlugins(Plugin):
|
||||
return {
|
||||
"uid": mask_number(uid),
|
||||
"basic": data.basic_info,
|
||||
"name": f"{record.name} {luo_ma_bum[record.difficulty]}",
|
||||
"name": f"{record.name} {self.LUO_MA[record.difficulty]}",
|
||||
"finish_cnt": record_raw.basic.finish_cnt,
|
||||
"time": record.finish_time.datetime.strftime("%Y-%m-%d %H:%M"),
|
||||
"score": record.score,
|
||||
"avatars": new_avatars,
|
||||
"buffs": record.buffs,
|
||||
"buff_en_map": buff_en_map,
|
||||
"buff_en_map": self.BUFF_EN,
|
||||
"miracles": record.miracles,
|
||||
}
|
||||
|
||||
@ -164,3 +166,53 @@ class PlayerRoguePlugins(Plugin):
|
||||
full_page=True,
|
||||
query_selector="#new-container",
|
||||
)
|
||||
|
||||
@handler.command("rogue_locust", block=False)
|
||||
@handler.message(filters.Regex("^寰宇蝗灾信息查询(.*)"), block=False)
|
||||
async def rogue_locust_command_start(self, update: Update, _: CallbackContext) -> Optional[int]:
|
||||
user = update.effective_user
|
||||
message = update.effective_message
|
||||
logger.info("用户 %s[%s] 查询寰宇蝗灾信息命令请求", user.full_name, user.id)
|
||||
try:
|
||||
async with self.helper.genshin(user.id) as client:
|
||||
data = await client.get_starrail_rogue_locust()
|
||||
render_result = await self.rogue_locust_render(data, client.player_id)
|
||||
except SimnetBadRequest as exc:
|
||||
raise exc
|
||||
except AttributeError as exc:
|
||||
logger.error("寰宇蝗灾数据有误")
|
||||
logger.exception(exc)
|
||||
await message.reply_text("寰宇蝗灾数据有误 估计是彦卿晕了")
|
||||
return
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||
await render_result.reply_photo(message, filename=f"{user.id}.png", allow_sending_without_reply=True)
|
||||
|
||||
async def rogue_locust_render(self, source: StarRailRogueLocust, uid: int) -> RenderResult:
|
||||
try:
|
||||
record = max(source.detail.records, key=lambda x: x.finish_time.datetime)
|
||||
name = f"{record.name} {self.LUO_MA[record.difficulty]}"
|
||||
new_avatars = [None, None, None, None]
|
||||
for idx, avatar in enumerate(record.final_lineup):
|
||||
old_avatar = avatar.dict()
|
||||
old_avatar["icon"] = self.assets.avatar.square(avatar.id).as_uri()
|
||||
new_avatars[idx] = RogueCharacter(**old_avatar)
|
||||
except ValueError:
|
||||
record, name, new_avatars = None, None, None
|
||||
|
||||
data = {
|
||||
"uid": mask_number(uid),
|
||||
"cnt": source.basic.cnt,
|
||||
"finish_cnt": len(source.detail.records),
|
||||
"record": record,
|
||||
"name": name,
|
||||
"avatars": new_avatars,
|
||||
"buff_en_map": self.BUFF_EN,
|
||||
}
|
||||
|
||||
return await self.template_service.render(
|
||||
"starrail/rogue/rogue_locust.html",
|
||||
data,
|
||||
{"width": 520, "height": 1000},
|
||||
full_page=True,
|
||||
query_selector="#new-locust-container",
|
||||
)
|
||||
|
BIN
resources/img/path/Propagation.png
Normal file
BIN
resources/img/path/Propagation.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
BIN
resources/starrail/rogue/img/detail_bg.ab3a5254.png
Normal file
BIN
resources/starrail/rogue/img/detail_bg.ab3a5254.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 556 KiB |
@ -50,7 +50,12 @@
|
||||
{% for avatar in avatars %}
|
||||
<div class="col avatar_width">
|
||||
{% if avatar %}
|
||||
<img class="avatar rounded-2" src="{{ avatar.icon }}" alt="">
|
||||
<div style="position: relative;">
|
||||
<img class="avatar rounded-2" src="{{ avatar.icon }}" alt="">
|
||||
{% if avatar.rank > 0 %}
|
||||
<p class="avatar_mz text-center">{{ avatar.rank }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<p class="avatar_text_width text-white text-center small mt-1">Lv.{{ avatar.level }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
120
resources/starrail/rogue/rogue_locust.html
Normal file
120
resources/starrail/rogue/rogue_locust.html
Normal file
@ -0,0 +1,120 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
<link rel="stylesheet" href="../../styles/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<div id="new-locust-container">
|
||||
<div style="height: 10px;"></div>
|
||||
<div>
|
||||
<p class="text-white text-center"><span class="border rounded-pill p-1">
|
||||
UID {{ uid }}
|
||||
</span></p>
|
||||
</div>
|
||||
<div id="overview">
|
||||
<div style="height: 27px;"></div>
|
||||
<div class="row" style="width: 90%; margin-left: 25px;">
|
||||
<div class="col">
|
||||
<p class="text-white text-center">
|
||||
<span>{{ cnt.narrow }}</span><br/><span>行者之道</span></p>
|
||||
</div>
|
||||
<div class="col">
|
||||
<p class="text-white text-center">
|
||||
<span>{{ cnt.miracle }}</span><br/><span>解锁奇物</span></p>
|
||||
</div>
|
||||
<div class="col">
|
||||
<p class="text-white text-center">
|
||||
<span>{{ cnt.event }}</span><br/><span>解锁事件</span></p>
|
||||
</div>
|
||||
<div class="col">
|
||||
<p class="text-white text-center">
|
||||
<span>{{ finish_cnt }}</span><br/><span>最近通关</span></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if record %}
|
||||
<div id="detail">
|
||||
<div style="height: 30px;"></div>
|
||||
<p class="text-white text-center"><span>{{ name }}</span></p>
|
||||
<p class="text-white small mx-3" style="position: relative;">
|
||||
<span style="margin-left: 40px;">{{ record.time_str }}</span>
|
||||
{% if record.fury %}
|
||||
<span style="position:absolute; right: 45px;">
|
||||
{% if record.fury.type == 1 %}
|
||||
扰动等级:{{ record.fury.point }}
|
||||
{% endif %}
|
||||
</span>
|
||||
{% endif %}
|
||||
</p>
|
||||
<div class="hr"></div>
|
||||
<div style="height: 10px"></div>
|
||||
<div id="avatars">
|
||||
<div class="row" style="width: 90%; margin-left: 7.5%;">
|
||||
{% for avatar in avatars %}
|
||||
<div class="col avatar_width">
|
||||
{% if avatar %}
|
||||
<div style="position: relative;">
|
||||
<img class="avatar rounded-2" src="{{ avatar.icon }}" alt="">
|
||||
{% if avatar.rank > 0 %}
|
||||
<p class="avatar_mz text-center">{{ avatar.rank }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<p class="avatar_text_width text-white text-center small mt-1">Lv.{{ avatar.level }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr"></div>
|
||||
<div style="height: 10px"></div>
|
||||
<div id="buff">
|
||||
{% for buff in record.buffs %}
|
||||
<div>
|
||||
<p class="text-white text-center">
|
||||
<img class="buff-img"
|
||||
src="../../img/path/{{ buff_en_map.get(buff.base_type.name, 'None') }}.png" alt="">
|
||||
{{ buff.base_type.name }}
|
||||
<span class="badge rounded-pill bg-info">{{ buff.base_type.cnt }}</span>
|
||||
</p>
|
||||
<div class="ms-2">
|
||||
{% set item_bg = ['', 'bg-secondary', 'bg-primary', 'bg-warning'] %}
|
||||
{% for i in range(0, buff.items|length, 4) %}
|
||||
{% set items = buff.items[i:i+4] %}
|
||||
<div class="row" style="width: 90%; margin-left: 20px;">
|
||||
{% for item in items %}
|
||||
<div class="col" style="padding: 2px;">
|
||||
<p class="text-white text-center small text-width text-over rounded-2 p-1 {{ item_bg[item.rank] }}">
|
||||
{{ item.name }}
|
||||
</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="hr"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div id="m ms-2">
|
||||
<div class="row" style="width: 90%; margin-left: 20px;">
|
||||
{% for miracle in record.miracles %}
|
||||
<div class="col">
|
||||
<img class="buff-img" src="{{ miracle.icon }}" alt="">
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div style="height: 30px;"></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -5,6 +5,13 @@
|
||||
background-size: 100% 100%;
|
||||
}
|
||||
|
||||
#new-locust-container {
|
||||
width: 520px;
|
||||
background-image: url("img/detail_bg.ab3a5254.png");
|
||||
background-repeat: no-repeat;
|
||||
background-size: 100% 100%;
|
||||
}
|
||||
|
||||
#overview {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
@ -37,6 +44,17 @@
|
||||
width: 66px;
|
||||
}
|
||||
|
||||
.avatar_mz {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 27px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background: rgba(0,0,0,.5);
|
||||
border-radius: 0 1px 0 1.6vw;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.hr {
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
|
Loading…
Reference in New Issue
Block a user