mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-16 04:35:49 +00:00
🔧 更新注入方式
This commit is contained in:
parent
ed5da75c00
commit
5e93a31e12
@ -16,6 +16,13 @@ from utils.plugins.manager import listener_plugins_class
|
||||
|
||||
@listener_plugins_class()
|
||||
class Abyss(BasePlugins):
|
||||
"""深渊数据查询"""
|
||||
|
||||
@inject
|
||||
def __init__(self, user_service: UserService, cookies_service: CookiesService, template_service: TemplateService):
|
||||
self.template_service = template_service
|
||||
self.cookies_service = cookies_service
|
||||
self.user_service = user_service
|
||||
|
||||
@classmethod
|
||||
def create_handlers(cls) -> list:
|
||||
@ -81,14 +88,13 @@ class Abyss(BasePlugins):
|
||||
return abyss_data
|
||||
|
||||
@inject
|
||||
async def command_start(self, update: Update, context: CallbackContext, user_service: UserService,
|
||||
cookies_service: CookiesService, template_service: TemplateService) -> None:
|
||||
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
||||
user = update.effective_user
|
||||
message = update.message
|
||||
Log.info(f"用户 {user.full_name}[{user.id}] 查深渊挑战命令请求")
|
||||
await message.reply_chat_action(ChatAction.TYPING)
|
||||
try:
|
||||
client = await get_genshin_client(user.id, user_service, cookies_service)
|
||||
client = await get_genshin_client(user.id, self.user_service, self.cookies_service)
|
||||
abyss_data = await self._get_abyss_data(client)
|
||||
except UserNotFoundError:
|
||||
reply_message = await message.reply_text("未查询到账号信息,请先私聊派蒙绑定账号")
|
||||
@ -105,7 +111,7 @@ class Abyss(BasePlugins):
|
||||
return
|
||||
raise exc
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||
png_data = await template_service.render('genshin/abyss', "abyss.html", abyss_data,
|
||||
png_data = await self.template_service.render('genshin/abyss', "abyss.html", abyss_data,
|
||||
{"width": 690, "height": 504}, full_page=False)
|
||||
await message.reply_photo(png_data, filename=f"abyss_{user.id}.png",
|
||||
allow_sending_without_reply=True)
|
||||
|
@ -13,6 +13,10 @@ from utils.plugins.manager import listener_plugins_class
|
||||
class Admin:
|
||||
"""有关BOT ADMIN处理"""
|
||||
|
||||
@inject
|
||||
def __init__(self, bot_admin_service: BotAdminService):
|
||||
self.bot_admin_service = bot_admin_service
|
||||
|
||||
@classmethod
|
||||
def create_handlers(cls) -> list:
|
||||
admin = cls()
|
||||
@ -23,31 +27,29 @@ class Admin:
|
||||
]
|
||||
|
||||
@bot_admins_rights_check
|
||||
@inject
|
||||
async def add_admin(self, update: Update, _: CallbackContext, bot_admin_service: BotAdminService):
|
||||
async def add_admin(self, update: Update, _: CallbackContext):
|
||||
message = update.message
|
||||
reply_to_message = message.reply_to_message
|
||||
if reply_to_message is None:
|
||||
await message.reply_text("请回复对应消息")
|
||||
else:
|
||||
admin_list = await bot_admin_service.get_admin_list()
|
||||
admin_list = await self.bot_admin_service.get_admin_list()
|
||||
if reply_to_message.from_user.id in admin_list:
|
||||
await message.reply_text("该用户已经存在管理员列表")
|
||||
else:
|
||||
await bot_admin_service.add_admin(reply_to_message.from_user.id)
|
||||
await self.bot_admin_service.add_admin(reply_to_message.from_user.id)
|
||||
await message.reply_text("添加成功")
|
||||
|
||||
@bot_admins_rights_check
|
||||
@inject
|
||||
async def del_admin(self, update: Update, _: CallbackContext, bot_admin_service: BotAdminService):
|
||||
async def del_admin(self, update: Update, _: CallbackContext):
|
||||
message = update.message
|
||||
reply_to_message = message.reply_to_message
|
||||
admin_list = await bot_admin_service.get_admin_list()
|
||||
admin_list = await self.bot_admin_service.get_admin_list()
|
||||
if reply_to_message is None:
|
||||
await message.reply_text("请回复对应消息")
|
||||
else:
|
||||
if reply_to_message.from_user.id in admin_list:
|
||||
await bot_admin_service.delete_admin(reply_to_message.from_user.id)
|
||||
await self.bot_admin_service.delete_admin(reply_to_message.from_user.id)
|
||||
await message.reply_text("删除成功")
|
||||
else:
|
||||
await message.reply_text("该用户不存在管理员列表")
|
||||
|
@ -14,11 +14,11 @@ from utils.plugins.manager import listener_plugins_class
|
||||
|
||||
@listener_plugins_class()
|
||||
class Help:
|
||||
"""
|
||||
帮助
|
||||
"""
|
||||
"""帮助菜单"""
|
||||
|
||||
def __init__(self):
|
||||
@inject
|
||||
def __init__(self, template_service: TemplateService):
|
||||
self.template_service = template_service
|
||||
self.help_png = None
|
||||
self.file_id = None
|
||||
|
||||
@ -31,14 +31,13 @@ class Help:
|
||||
|
||||
@error_callable
|
||||
@restricts()
|
||||
@inject
|
||||
async def command_start(self, update: Update, _: CallbackContext, template_service: TemplateService) -> None:
|
||||
async def command_start(self, update: Update, _: CallbackContext) -> None:
|
||||
message = update.message
|
||||
user = update.effective_user
|
||||
Log.info(f"用户 {user.full_name}[{user.id}] 发出help命令")
|
||||
if self.file_id is None or config.DEBUG:
|
||||
await message.reply_chat_action(ChatAction.TYPING)
|
||||
help_png = await template_service.render('bot/help', "help.html", {}, {"width": 768, "height": 768})
|
||||
help_png = await self.template_service.render('bot/help', "help.html", {}, {"width": 768, "height": 768})
|
||||
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||
reply_photo = await message.reply_photo(help_png, filename="help.png", allow_sending_without_reply=True)
|
||||
photo = reply_photo.photo[0]
|
||||
|
@ -21,6 +21,11 @@ class Weapon(BasePlugins):
|
||||
|
||||
KEYBOARD = [[InlineKeyboardButton(text="查看武器列表并查询", switch_inline_query_current_chat="查看武器列表并查询")]]
|
||||
|
||||
@inject
|
||||
def __init__(self, template_service: TemplateService, wiki_service: WikiService):
|
||||
self.wiki_service = wiki_service
|
||||
self.template_service = template_service
|
||||
|
||||
@classmethod
|
||||
def create_handlers(cls) -> list:
|
||||
weapon = cls()
|
||||
@ -31,8 +36,7 @@ class Weapon(BasePlugins):
|
||||
|
||||
@error_callable
|
||||
@restricts()
|
||||
@inject
|
||||
async def command_start(self, update: Update, context: CallbackContext, template_service: TemplateService, wiki_service: WikiService) -> None:
|
||||
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
||||
message = update.message
|
||||
user = update.effective_user
|
||||
args = get_all_args(context)
|
||||
@ -46,7 +50,7 @@ class Weapon(BasePlugins):
|
||||
self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id)
|
||||
return
|
||||
weapon_name = weaponToName(weapon_name)
|
||||
weapons_list = await wiki_service.get_weapons_list()
|
||||
weapons_list = await self.wiki_service.get_weapons_list()
|
||||
for weapon in weapons_list:
|
||||
if weapon["name"] == weapon_name:
|
||||
weapon_data = weapon
|
||||
@ -85,7 +89,7 @@ class Weapon(BasePlugins):
|
||||
return _template_data
|
||||
|
||||
template_data = await input_template_data(weapon_data)
|
||||
png_data = await template_service.render('genshin/weapon', "weapon.html", template_data,
|
||||
png_data = await self.template_service.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",
|
||||
|
@ -11,9 +11,11 @@ from utils.plugins.manager import listener_plugins_class
|
||||
|
||||
@listener_plugins_class()
|
||||
class Wiki(BasePlugins):
|
||||
"""
|
||||
有关WIKI
|
||||
"""
|
||||
"""有关WIKI操作"""
|
||||
|
||||
@inject
|
||||
def __init__(self, wiki_service: WikiService):
|
||||
self.wiki_service = wiki_service
|
||||
|
||||
@classmethod
|
||||
def create_handlers(cls) -> list:
|
||||
@ -22,11 +24,10 @@ class Wiki(BasePlugins):
|
||||
CommandHandler("refresh_wiki", wiki.refresh_wiki, block=False),
|
||||
]
|
||||
|
||||
@inject
|
||||
@bot_admins_rights_check
|
||||
@error_callable
|
||||
async def refresh_wiki(self, update: Update, _: CallbackContext, wiki_service: WikiService = None):
|
||||
async def refresh_wiki(self, update: Update, _: CallbackContext):
|
||||
message = update.message
|
||||
await message.reply_text("正在刷新Wiki缓存,请稍等")
|
||||
await wiki_service.refresh_wiki()
|
||||
await self.wiki_service.refresh_wiki()
|
||||
await message.reply_text("刷新Wiki缓存成功")
|
||||
|
Loading…
Reference in New Issue
Block a user