GraiaProject / Avilla

The next-gen framework for IM development. Powered by Graia Project.
MIT License
160 stars 14 forks source link

bug: raised NotImplementedError when `ctx.pull()` with `File` #150

Closed SerinaNya closed 8 months ago

SerinaNya commented 9 months ago

问题描述

在试图对 File 对象进行 ctx.pull() 以获取 上传文件之文件名及文件大小 时抛出 NotImplementedError 异常。

版本信息

avilla-core = "1.0.0a24"
avilla-elizabeth = "1.0.0a26"

报错和部分日志

INFO     avilla-core version: 1.0.0a24                                                                                                                   graia.py:49
INFO     graia-broadcast version: 0.23.5                                                                                                                 graia.py:49
INFO     graia-saya version: 0.0.19                                                                                                                      graia.py:49
INFO     graia-scheduler version: unknown / not-installed                                                                                                graia.py:49
INFO     graia-ariadne version: unknown / not-installed                                                                                                  graia.py:49
INFO     statv version: 0.3.2                                                                                                                            graia.py:49
INFO     launart version: 0.8.2                                                                                                                          graia.py:49
INFO     creart version: 0.3.0                                                                                                                           graia.py:49
INFO     creart-graia version: unknown / not-installed                                                                                                   graia.py:49
INFO     kayaku version: unknown / not-installed                                                                                                         graia.py:49
INFO     Using platform: <class 'avilla.elizabeth.protocol.ElizabethProtocol'> 

...

INFO     [Elizabeth 8888888888]: land(qq).group(0000000000) -> '[$File]'                                                                          application.py:160
INFO     Received file from allowed group.                                                                                                            log_file.py:18
Traceback (most recent call last):
  File "C:\Users\Xiao_Jin\AppData\Local\pypoetry\Cache\virtualenvs\commspt-bot-avilla-FLAIqaDu-py3.12\Lib\site-packages\graia\broadcast\__init__.py", line 184, in Executor
    result = await run_always_await(target_callable, **parameter_compile_result)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Xiao_Jin\AppData\Local\pypoetry\Cache\virtualenvs\commspt-bot-avilla-FLAIqaDu-py3.12\Lib\site-packages\graia\broadcast\utilles.py", line 34, in run_always_await
    obj = await obj
          ^^^^^^^^^
  File "d:\Datas\commspt-bot-avilla\commspt_bot_avilla\modules\log_file.py", line 20, in process_log_file
    print(await ctx.pull(File, file.resource.to_selector()))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Xiao_Jin\AppData\Local\pypoetry\Cache\virtualenvs\commspt-bot-avilla-FLAIqaDu-py3.12\Lib\site-packages\avilla\core\context\__init__.py", line 141, in pull
    return await self.staff.pull_metadata(target, route)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Xiao_Jin\AppData\Local\pypoetry\Cache\virtualenvs\commspt-bot-avilla-FLAIqaDu-py3.12\Lib\site-packages\avilla\core\ryanvk\staff.py", line 67, in pull_metadata
    return await self.call_fn(CoreCapability.pull, target, route)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Xiao_Jin\AppData\Local\pypoetry\Cache\virtualenvs\commspt-bot-avilla-FLAIqaDu-py3.12\Lib\site-packages\graia\ryanvk\staff.py", line 33, in call_fn 
    collector, entity = fn.behavior.harvest_overload(self, fn, *args, **kwargs)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Xiao_Jin\AppData\Local\pypoetry\Cache\virtualenvs\commspt-bot-avilla-FLAIqaDu-py3.12\Lib\site-packages\graia\ryanvk\behavior.py", line 40, in harvest_overload
    entities = overload_item.get_entities(scope, {i: bound_args.arguments[i] for i in required_args})
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Xiao_Jin\AppData\Local\pypoetry\Cache\virtualenvs\commspt-bot-avilla-FLAIqaDu-py3.12\Lib\site-packages\avilla\core\ryanvk\overload\target.py", line 136, in get_entities
    bind_sets.append(get_bind_set())
                     ^^^^^^^^^^^^^^
  File "C:\Users\Xiao_Jin\AppData\Local\pypoetry\Cache\virtualenvs\commspt-bot-avilla-FLAIqaDu-py3.12\Lib\site-packages\avilla\core\ryanvk\overload\target.py", line 108, in get_bind_set
    raise NotImplementedError
NotImplementedError

使用代码 log_file.py

from avilla.core import Context, MessageReceived, File, MessageChain

from avilla.core.tools.filter import Filter
from graia.saya.builtins.broadcast.shortcut import dispatch, listen
from loguru import logger
from commspt_bot_avilla.utils.adv_filter import from_groups_preset_general

from rich import print

@listen(MessageReceived)
@dispatch(
    Filter()
    .dispatch(MessageReceived)
    .assert_true(lambda e: from_groups_preset_general()(e.context.scene))
    .assert_true(lambda e: File in e.message.content)
)
async def process_log_file(ctx: Context, chain: MessageChain):
    logger.info("Received file from allowed group.")
    file = chain.get_first(File)
    print(await ctx.pull(File, file.resource.to_selector()))