mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-21 22:58:05 +00:00
✨ Support genshin stats new fields
This commit is contained in:
parent
05abee352e
commit
43176fc564
@ -189,7 +189,10 @@ class Calendar:
|
|||||||
|
|
||||||
def get_date(d1: str, d2: str) -> datetime:
|
def get_date(d1: str, d2: str) -> datetime:
|
||||||
if d1 and len(d1) > 6:
|
if d1 and len(d1) > 6:
|
||||||
return datetime.strptime(d1, "%Y-%m-%d %H:%M:%S")
|
try:
|
||||||
|
return datetime.strptime(d1, "%Y-%m-%d %H:%M:%S")
|
||||||
|
except ValueError:
|
||||||
|
return datetime.strptime(d1, "%Y-%m-%d %H:%M")
|
||||||
return datetime.strptime(d2, "%Y-%m-%d %H:%M:%S")
|
return datetime.strptime(d2, "%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
s_date = get_date(detail and detail.start, ds.start_time)
|
s_date = get_date(detail and detail.start, ds.start_time)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import random
|
import random
|
||||||
|
from pathlib import Path
|
||||||
from typing import Optional, TYPE_CHECKING, List
|
from typing import Optional, TYPE_CHECKING, List
|
||||||
from telegram.constants import ChatAction
|
from telegram.constants import ChatAction
|
||||||
from telegram.ext import filters
|
from telegram.ext import filters
|
||||||
@ -10,6 +11,8 @@ from core.services.template.models import RenderResult
|
|||||||
from core.services.template.services import TemplateService
|
from core.services.template.services import TemplateService
|
||||||
from gram_core.plugin.methods.inline_use_data import IInlineUseData
|
from gram_core.plugin.methods.inline_use_data import IInlineUseData
|
||||||
from plugins.tools.genshin import GenshinHelper
|
from plugins.tools.genshin import GenshinHelper
|
||||||
|
from utils.const import RESOURCE_DIR
|
||||||
|
from utils.error import UrlResourcesNotFoundError
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
from utils.uid import mask_number
|
from utils.uid import mask_number
|
||||||
|
|
||||||
@ -76,6 +79,7 @@ class PlayerStatsPlugins(Plugin):
|
|||||||
("活跃天数", "days_active"),
|
("活跃天数", "days_active"),
|
||||||
("成就达成数", "achievements"),
|
("成就达成数", "achievements"),
|
||||||
("获取角色数", "characters"),
|
("获取角色数", "characters"),
|
||||||
|
("满好感角色数", "full_fetter_avatar_num"),
|
||||||
("深境螺旋", "spiral_abyss"),
|
("深境螺旋", "spiral_abyss"),
|
||||||
("解锁传送点", "unlocked_waypoints"),
|
("解锁传送点", "unlocked_waypoints"),
|
||||||
("解锁秘境", "unlocked_domains"),
|
("解锁秘境", "unlocked_domains"),
|
||||||
@ -89,6 +93,7 @@ class PlayerStatsPlugins(Plugin):
|
|||||||
("雷神瞳", "electroculi"),
|
("雷神瞳", "electroculi"),
|
||||||
("草神瞳", "dendroculi"),
|
("草神瞳", "dendroculi"),
|
||||||
("水神瞳", "hydroculi"),
|
("水神瞳", "hydroculi"),
|
||||||
|
("火神瞳", "pyroculi"),
|
||||||
],
|
],
|
||||||
"style": random.choice(["mondstadt", "liyue"]), # nosec
|
"style": random.choice(["mondstadt", "liyue"]), # nosec
|
||||||
}
|
}
|
||||||
@ -102,6 +107,16 @@ class PlayerStatsPlugins(Plugin):
|
|||||||
full_page=True,
|
full_page=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def _download_resource(self, url: str) -> str:
|
||||||
|
try:
|
||||||
|
return await self.download_resource(url)
|
||||||
|
except UrlResourcesNotFoundError:
|
||||||
|
path = Path(url)
|
||||||
|
file_path = RESOURCE_DIR / "img" / "city" / path.name
|
||||||
|
if file_path.exists():
|
||||||
|
return file_path.as_uri()
|
||||||
|
logger.warning("缓存地区图片资源失败 %s", url)
|
||||||
|
|
||||||
async def cache_images(self, data: "GenshinUserStats") -> None:
|
async def cache_images(self, data: "GenshinUserStats") -> None:
|
||||||
"""缓存所有图片到本地"""
|
"""缓存所有图片到本地"""
|
||||||
# TODO: 并发下载所有资源
|
# TODO: 并发下载所有资源
|
||||||
@ -109,8 +124,8 @@ class PlayerStatsPlugins(Plugin):
|
|||||||
# 探索地区
|
# 探索地区
|
||||||
for item in data.explorations:
|
for item in data.explorations:
|
||||||
item.__config__.allow_mutation = True
|
item.__config__.allow_mutation = True
|
||||||
item.icon = await self.download_resource(item.icon)
|
item.icon = await self._download_resource(item.icon)
|
||||||
item.cover = await self.download_resource(item.cover)
|
item.cover = await self._download_resource(item.cover)
|
||||||
|
|
||||||
async def stats_use_by_inline(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE"):
|
async def stats_use_by_inline(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE"):
|
||||||
callback_query = update.callback_query
|
callback_query = update.callback_query
|
||||||
|
BIN
resources/img/city/UI_ChapterCover_Nata.png
Normal file
BIN
resources/img/city/UI_ChapterCover_Nata.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 256 KiB |
BIN
resources/img/city/UI_ChapterIcon_Nata.png
Normal file
BIN
resources/img/city/UI_ChapterIcon_Nata.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
Loading…
Reference in New Issue
Block a user