Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
✨ 有引用的消息支持获取原消息的图片链接
Browse files Browse the repository at this point in the history
  • Loading branch information
CMHopeSunshine committed Dec 21, 2023
1 parent b8e706d commit 487ca5a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 56 deletions.
14 changes: 0 additions & 14 deletions nonebot/adapters/villa/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,6 @@
from .adapter import Adapter


def _check_reply(bot: "Bot", event: SendMessageEvent):
"""检查事件是否有引用消息,如果有则删除。
参数:
bot: Bot对象
event: 事件
"""
if event.content.quote is not None:
event.message = event.message.exclude("quote")
if not event.message:
event.message.append(MessageSegment.text(""))


def _check_at_me(bot: "Bot", event: SendMessageEvent):
"""检查事件是否和机器人有关,如果有关则设置 to_me 为 True,并删除消息中的 at 信息。
Expand Down Expand Up @@ -251,7 +238,6 @@ async def handle_event(self, event: Event):
"""处理事件"""
if isinstance(event, SendMessageEvent):
_check_at_me(self, event)
_check_reply(self, event)
await handle_event(self, event)

def _verify_signature(
Expand Down
14 changes: 7 additions & 7 deletions nonebot/adapters/villa/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ def payload_to_event(cls, data: Dict[str, Any]):
return data
msg = Message()
msg_content_info = data["content"] = json.loads(data["content"])
if quote := msg_content_info.get("quote"):
msg.append(
MessageSegment.quote(
message_id=quote["quoted_message_id"],
message_send_time=quote["quoted_message_send_time"],
),
)
# if quote := msg_content_info.get("quote"):
# msg.append(
# MessageSegment.quote(
# message_id=quote["quoted_message_id"],
# message_send_time=quote["quoted_message_send_time"],
# ),
# )

content = msg_content_info["content"]
text = content["text"]
Expand Down
4 changes: 2 additions & 2 deletions nonebot/adapters/villa/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def __add__(
self,
other: Union[str, "MessageSegment", Iterable["MessageSegment"]],
) -> "Message":
return super().__add__(other)
return self.get_message_class()(self) + other

@override
def __radd__(
self,
other: Union[str, "MessageSegment", Iterable["MessageSegment"]],
) -> "Message":
return super().__radd__(other)
return self.get_message_class()(self) + other

@override
def is_text(self) -> bool:
Expand Down
7 changes: 4 additions & 3 deletions nonebot/adapters/villa/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ class Robot(BaseModel):
class QuoteMessage(BaseModel):
content: str
msg_uid: str
bot_msg_id: Optional[str]
bot_msg_id: Optional[str] = None
send_at: int
msg_type: str
from_user_id: int
from_user_nickname: str
from_user_id: Optional[int] = None
from_user_nickname: Optional[str] = None
from_user_id_str: str
images: Optional[List[str]] = None


## 鉴权部分
Expand Down
56 changes: 28 additions & 28 deletions nonebot/adapters/villa/pb/model_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions nonebot/adapters/villa/permission.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from typing import Union

from nonebot.adapters.villa import AddQuickEmoticonEvent, Bot, SendMessageEvent
from nonebot.adapters.villa.api import RoleType
from nonebot.permission import Permission

from .bot import Bot
from .event import AddQuickEmoticonEvent, SendMessageEvent
from .models import RoleType


async def is_owner_or_admin(
bot: Bot,
Expand Down

0 comments on commit 487ca5a

Please sign in to comment.