GraiaProject / Application

一个设计精巧, 协议实现完备的, 基于 mirai-api-http 的即时聊天软件自动化框架.
https://graia-document.vercel.app/
GNU Affero General Public License v3.0
438 stars 63 forks source link

Decorater 报错 TypeError #17

Closed aboutmydreams closed 4 years ago

aboutmydreams commented 4 years ago

参考教程时发生错误 https://graia.originpages.com/#/suggests/donot_make_handler?id=%e8%bf%87%e6%bb%a4%e6%b6%88%e6%81%af

复现步骤:

def at_me(message: MessageChain):
    if message[At] != []:
        raise ExecutionStop()

@bcc.receiver("GroupMessage", priority=1, headless_decoraters=[Decorater(at_me)])
async def group_message_handler(app: GraiaMiraiApplication, message: MessageChain, group: Group, member: Member):

控制台日志输出截图:

Traceback (most recent call last):
  File "/Users/dengwenhao/coding/learn/Application/demo.py", line 45, in <module>
    @bcc.receiver("GroupMessage", priority=1, headless_decoraters=[Decorater(at_me)])
  File "/usr/local/lib/python3.7/site-packages/graia/broadcast/entities/decorater.py", line 11, in __init__
    super().__init__(target=target, pre=pre)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
[2020-08-06 01:06:07,694][ERROR]: Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x109854fd0>

运行环境:

Uwwal commented 4 years ago

应该是headless_decoraters=[Depend(at_me)]吧 教程里面这节好像还有其他问题 如果只是写if not judge(message): raise ExecutionStop()的话 无法执行异步函数 还需要再if后面加个else: return True (第一次用issue不知道路人能不能跟回 见谅..)

aboutmydreams commented 4 years ago

@Uwwal

应该是headless_decoraters=[Depend(at_me)]吧 教程里面这节好像还有其他问题 如果只是写if not judge(message): raise ExecutionStop()的话 无法执行异步函数 还需要再if后面加个else: return True (第一次用issue不知道路人能不能跟回 见谅..)

hi,Depend 是v3中的用法,当前的版本里面没有这个装饰器哦

Uwwal commented 4 years ago

@Uwwal

应该是headless_decoraters=[Depend(at_me)]吧 教程里面这节好像还有其他问题 如果只是写if not judge(message): raise ExecutionStop()的话 无法执行异步函数 还需要再if后面加个else: return True (第一次用issue不知道路人能不能跟回 见谅..)

hi,Depend 是v3中的用法,当前的版本里面没有这个装饰器哦

我看graia.broadcast.builtin.decoraters里面有个Depend类倒是..(好像也能用)

GreyElaina commented 4 years ago

用法错了. 我们提供了 graia.broadcast.builtin.decoraters.Depend 作为 v3 中 Depend, 即依赖注入系统的向上兼容迁移.

GreyElaina commented 4 years ago

Decorater 通过实现 target 抽象方法, BCC 内部进行处理来参与到参数解析的过程中去.