GraiaProject / Avilla

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

[BUG] 收到消息的消息链中如果带有图片,操作消息链需要 deepcopy 的方法时导致 `AttributeError: 'Picture' object has no attribute 'resource'` 异常 #145

Closed djkcyl closed 11 months ago

djkcyl commented 11 months ago

复现

chain.removeprefix(" ")

结果

Traceback (most recent call last):
  File "/root/ABot-NT/.venv/lib/python3.10/site-packages/graia/broadcast/__init__.py", line 157, in Executor
    await run_always_await(i, dii)  # type: ignore
  File "/root/ABot-NT/.venv/lib/python3.10/site-packages/graia/broadcast/utilles.py", line 34, in run_always_await
    obj = await obj
  File "/root/ABot-NT/.venv/lib/python3.10/site-packages/avilla/twilight/twilight.py", line 795, in beforeExecution
    chain = await interface.lookup_by_directly(
  File "/root/ABot-NT/.venv/lib/python3.10/site-packages/graia/broadcast/interfaces/dispatcher.py", line 176, in lookup_by_directly
    result = await dispatcher.catch(self)  # type: ignore
  File "/root/ABot-NT/.venv/lib/python3.10/site-packages/graia/broadcast/interfaces/decorator.py", line 52, in catch
    return Force(await run_always_await(decorator.target, self))
  File "/root/ABot-NT/.venv/lib/python3.10/site-packages/graia/broadcast/utilles.py", line 34, in run_always_await
    obj = await obj
  File "/root/ABot-NT/.venv/lib/python3.10/site-packages/avilla/twilight/base.py", line 34, in target
    return await self(
  File "/root/ABot-NT/utils/message/preprocessor.py", line 21, in __call__
    return chain.removeprefix(" ").removeprefix("/").removesuffix(" ")
  File "/root/ABot-NT/.venv/lib/python3.10/site-packages/graia/amnesia/message/chain.py", line 474, in removeprefix
    elements = deepcopy(self.content) if copy else self.content
  File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.10/copy.py", line 206, in _deepcopy_list
    append(deepcopy(a, memo))
  File "/usr/lib/python3.10/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/python3.10/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.10/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/python3.10/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.10/copy.py", line 153, in deepcopy
    y = copier(memo)
  File "/root/ABot-NT/.venv/lib/python3.10/site-packages/avilla/core/selector.py", line 84, in wrapper
    return Selector(pattern={**self.pattern, name: str(content)})
  File "/root/ABot-NT/.venv/lib/python3.10/site-packages/avilla/core/elements.py", line 62, in __repr__
    return f"[$Picture:resource={self.resource.to_selector()}]"
AttributeError: 'Picture' object has no attribute 'resource'