PaiGram/plugins
2022-07-31 16:17:27 +08:00
..
gacha 添加抽卡模拟器插件 2022-07-31 16:15:09 +08:00
map 添加 map 插件 支持资源点查询 2022-07-27 00:19:21 +08:00
abyss.py 🔧 修复部分插件依赖无法找到的问题 2022-07-31 16:17:27 +08:00
admin.py 🔧 更新注入方式 2022-07-31 12:51:22 +08:00
artifact_rate.py 🔧 修复 artifact_rate 插件的 cancel 函数未找到的问题 2022-07-27 00:09:15 +08:00
base.py Initial commit 2022-07-26 18:07:31 +08:00
daily_note.py 添加每日便签插件 2022-07-31 13:48:41 +08:00
errorhandler.py Initial commit 2022-07-26 18:07:31 +08:00
help.py 🔧 更新注入方式 2022-07-31 12:51:22 +08:00
ledger.py 添加旅行札记查询插件 2022-07-31 16:00:52 +08:00
README.md Initial commit 2022-07-26 18:07:31 +08:00
sign.py 🔧 修复部分插件依赖无法找到的问题 2022-07-31 16:17:27 +08:00
start.py 🔧 合并可折叠 if 语句 2022-07-27 00:30:15 +08:00
strategy.py 添加角色攻略查询插件 2022-07-31 15:38:31 +08:00
uid.py 添加玩家查询插件 2022-07-31 13:16:38 +08:00
weapon.py 🔧 更新注入方式 2022-07-31 12:51:22 +08:00
wiki.py 🔧 更新注入方式 2022-07-31 12:51:22 +08:00

plugins 目录

说明

该目录仅限处理交互层和业务层数据交换的任务

如有任何新业务接口,请转到 service 目录添加

如有任何API请求接口请转到 model 目录添加

基础代码

from telegram.ext import CommandHandler, CallbackContext

from logger import Log
from utils.decorators.error import error_callable
from utils.decorators.restricts import restricts
from utils.plugins.manager import listener_plugins_class

@listener_plugins_class()
class Example:

    @classmethod
    def create_handlers(cls):
        example = cls()
        return [CommandHandler('example', example.command_start)]

    @error_callable
    @restricts()
    async def command_start(self, update: Update, context: CallbackContext) -> None:
        user = update.effective_user
        Log.info(f"用户 {user.full_name}[{user.id}] 发出example命令")
        await message.reply_text("Example")

注意

plugins 模块下的类必须提供 create_handlers 类方法作为构建相应处理程序给 handle.py

在函数注册为命令处理过程(如 CommandHandler )需要添加 error_callable 修饰器作为错误统一处理

如果套引用服务,参数需要声明需要引用服务的类型,并且添加 inject 修饰器

必要的函数必须捕获异常后通知用户或者直接抛出异常

入口函数必须使用 @restricts() 修饰器 预防洪水攻击

只需在构建的类前加上 @listener_plugins_class() 修饰器即可向程序注册插件

注意:@restricts() 修饰器带参,必须带括号,否则会出现调用错误