🎨 使用 assets
服务获取图片
@ -1,5 +1,4 @@
|
||||
import asyncio
|
||||
import os
|
||||
import re
|
||||
from datetime import datetime
|
||||
from typing import Any, List, Optional, Tuple, Union
|
||||
@ -10,6 +9,7 @@ from telegram import Update
|
||||
from telegram.constants import ChatAction
|
||||
from telegram.ext import CallbackContext, CommandHandler, MessageHandler, filters
|
||||
|
||||
from core.base.assets import AssetsService
|
||||
from core.base.redisdb import RedisDB
|
||||
from core.baseplugin import BasePlugin
|
||||
from core.plugin import Plugin, handler
|
||||
@ -113,16 +113,6 @@ class GachaHandle:
|
||||
else:
|
||||
raise GachaNotFound(gacha_name)
|
||||
|
||||
@staticmethod
|
||||
async def de_item_list(item_list: List[int]) -> List[dict]:
|
||||
gacha_item: List[dict] = []
|
||||
for item_id in item_list:
|
||||
if 10000 <= item_id <= 100000:
|
||||
gacha_item.append(WEAPON_DATA.get(str(item_id)))
|
||||
if 10000000 <= item_id <= 19999999:
|
||||
gacha_item.append(AVATAR_DATA.get(str(item_id)))
|
||||
return gacha_item
|
||||
|
||||
@staticmethod
|
||||
def de_title(title: str) -> Union[Tuple[str, None], Tuple[str, Any]]:
|
||||
title_html = BeautifulSoup(title, "lxml")
|
||||
@ -138,15 +128,14 @@ class GachaHandle:
|
||||
class Gacha(Plugin, BasePlugin):
|
||||
"""抽卡模拟器(非首模拟器/减寿模拟器)"""
|
||||
|
||||
def __init__(self, template_service: TemplateService = None, redis: RedisDB = None):
|
||||
def __init__(self, assets: AssetsService = None, template_service: TemplateService = None, redis: RedisDB = None):
|
||||
self.gacha_db = GachaRedis(redis)
|
||||
self.handle = GachaHandle()
|
||||
self.banner_system = BannerSystem()
|
||||
self.template_service = template_service
|
||||
self.current_dir = os.getcwd()
|
||||
self.resources_dir = os.path.join(self.current_dir, "resources")
|
||||
self.banner_cache = {}
|
||||
self._look = asyncio.Lock()
|
||||
self.assets_service = assets
|
||||
|
||||
async def get_banner(self, gacha_base_info: GachaInfoObject):
|
||||
async with self._look:
|
||||
@ -156,6 +145,23 @@ class Gacha(Plugin, BasePlugin):
|
||||
self.banner_cache.setdefault(gacha_base_info.gacha_id, banner)
|
||||
return banner
|
||||
|
||||
async def de_item_list(self,item_list: List[int]) -> List[dict]:
|
||||
gacha_item: List[dict] = []
|
||||
for item_id in item_list:
|
||||
if 10000 <= item_id <= 100000:
|
||||
data = WEAPON_DATA.get(str(item_id))
|
||||
avatar = self.assets_service.weapon(item_id)
|
||||
gacha = await avatar.gacha()
|
||||
data.setdefault("url", gacha.as_uri())
|
||||
gacha_item.append(data)
|
||||
elif 10000000 <= item_id <= 19999999:
|
||||
data = AVATAR_DATA.get(str(item_id))
|
||||
avatar = self.assets_service.avatar(item_id)
|
||||
gacha = await avatar.gacha_card()
|
||||
data.setdefault("url", gacha.as_uri())
|
||||
gacha_item.append(data)
|
||||
return gacha_item
|
||||
|
||||
@handler(CommandHandler, command="gacha", block=False)
|
||||
@handler(MessageHandler, filters=filters.Regex("^非首模拟器(.*)"), block=False)
|
||||
@restricts(restricts_time=3, restricts_time_of_groups=20)
|
||||
@ -192,10 +198,9 @@ class Gacha(Plugin, BasePlugin):
|
||||
player_gacha_info.event_weapon_banner.wish_item_id = 0
|
||||
# 执行抽卡
|
||||
item_list = self.banner_system.do_pulls(player_gacha_info, banner, 10)
|
||||
data = await self.handle.de_item_list(item_list)
|
||||
data = await self.de_item_list(item_list)
|
||||
player_gacha_banner_info = player_gacha_info.get_banner_info(banner)
|
||||
template_data = {
|
||||
"_res_path": f"file://{self.resources_dir}",
|
||||
"name": f"{user.full_name}",
|
||||
"info": gacha_name,
|
||||
"banner_name": banner.html_title,
|
||||
|
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 413 KiB |
Before Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 160 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 566 KiB |
Before Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 172 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 542 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 44 KiB |
@ -138,7 +138,9 @@ body {
|
||||
}
|
||||
|
||||
.item-weapon-img {
|
||||
width: 110px;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
left: -35%;
|
||||
filter: drop-shadow(3px 9px 0px #333);
|
||||
}
|
||||
|
||||
|
@ -28,25 +28,25 @@
|
||||
{% for item in items %}
|
||||
<div class="item">
|
||||
<div class="item-bg-box">
|
||||
<img class="item-bg" src="{{_res_path}}/genshin/gacha/items/bg.png" alt=""/>
|
||||
<img class="item-bg" src="items/bg.png" alt=""/>
|
||||
</div>
|
||||
<img class="item-shadow" src="{{_res_path}}/genshin/gacha/items/shadow-{{item.rank}}.png" alt=""/>
|
||||
<img class="item-shadow2" src="{{_res_path}}/genshin/gacha/items/bg2.png" alt=""/>
|
||||
<img class="item-shadow" src="items/shadow-{{item.rank}}.png" alt=""/>
|
||||
<img class="item-shadow2" src="items/bg2.png" alt=""/>
|
||||
{% if item.id <= 100000 %}
|
||||
<div class="item-weapon-box">
|
||||
<img class="item-weapon-img" src="{{_res_path}}/genshin/gacha/weapon/{{item.name}}.png" alt=""/>
|
||||
<img class="item-weapon-img" src="{{item.url}}" alt=""/>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="item-img-box">
|
||||
<img class="item-character-img" src="{{_res_path}}/genshin/gacha/character/{{item.name}}.png" alt=""/>
|
||||
<img class="item-character-img" src="{{item.url}}" alt=""/>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if item.id <= 100000 %}
|
||||
<img class="item-element" src="{{_res_path}}/genshin/gacha/items/{{item.type}}.png" alt=""/>
|
||||
<img class="item-element" src="items/{{item.type}}.png" alt=""/>
|
||||
{% else %}
|
||||
<img class="item-element" src="{{_res_path}}/genshin/gacha/items/{{item.element}}.png" alt=""/>
|
||||
<img class="item-element" src="items/{{item.element}}.png" alt=""/>
|
||||
{% endif %}
|
||||
<img class="item-star" src="{{_res_path}}/genshin/gacha/items/s-{{item.rank}}.png" alt=""/>
|
||||
<img class="item-star" src="items/s-{{item.rank}}.png" alt=""/>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
Before Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 7.4 KiB |
Before Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 7.4 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 42 KiB |