修改 Weaponservice 传入方式

This commit is contained in:
洛水居室 2022-07-07 12:30:35 +08:00
parent a982f69a68
commit d9fa9cd466
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -8,10 +8,11 @@ from metadata.shortname import weaponToName
from model.helpers import url_to_file
from plugins.base import BasePlugins, restricts
from plugins.errorhandler import conversation_error_handler
from service import BaseService
from utils.base import PaimonContext
@listener_plugins_class()
@listener_plugins_class(need_service=True)
class Weapon(BasePlugins):
"""
武器查询
@ -19,9 +20,12 @@ class Weapon(BasePlugins):
KEYBOARD = [[InlineKeyboardButton(text="查看武器列表并查询", switch_inline_query_current_chat="查看武器列表并查询")]]
def __init__(self, service: BaseService):
self.service = service
@classmethod
def create_handlers(cls) -> list:
weapon = cls()
def create_handlers(cls, service: BaseService) -> list:
weapon = cls(service)
return [
CommandHandler("weapon", weapon.command_start, block=False),
MessageHandler(filters.Regex("^武器查询(.*)"), weapon.command_start, block=False)
@ -34,7 +38,6 @@ class Weapon(BasePlugins):
user = update.effective_user
args = context.args
match = context.match
service = context.service
weapon_name: str = ""
if args is None:
if match is not None:
@ -91,7 +94,7 @@ class Weapon(BasePlugins):
return _template_data
template_data = await input_template_data(weapon_data)
png_data = await service.template.render('genshin/weapon', "weapon.html", template_data,
png_data = await self.service.template.render('genshin/weapon', "weapon.html", template_data,
{"width": 540, "height": 540})
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
await message.reply_photo(png_data, filename=f"{template_data['weapon_name']}.png",