From 9931563d803133793fb3f5b8a8acf7b3ac26d14f Mon Sep 17 00:00:00 2001 From: artin Date: Mon, 13 Sep 2021 01:18:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20ding=20adapter=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. cannot send complicate message, such as actionCard 2. fix judge current connection mode --- nonebot/matcher.py | 3 ++- .../nonebot/adapters/ding/bot.py | 2 +- .../nonebot/adapters/ding/message.py | 13 +++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/nonebot/matcher.py b/nonebot/matcher.py index 095d3320..0d552d9f 100644 --- a/nonebot/matcher.py +++ b/nonebot/matcher.py @@ -505,7 +505,7 @@ class Matcher(metaclass=MatcherMeta): """ bot = current_bot.get() event = current_event.get() - if message: + if message is not None: await bot.send(event=event, message=message, **kwargs) raise FinishedException @@ -571,6 +571,7 @@ class Matcher(metaclass=MatcherMeta): while self.handlers: handler = self.handlers.pop(0) + logger.debug(f"Running handler {handler}") await handler(self, bot, event, self.state) except RejectedException: diff --git a/packages/nonebot-adapter-ding/nonebot/adapters/ding/bot.py b/packages/nonebot-adapter-ding/nonebot/adapters/ding/bot.py index 57dac284..2900a8d3 100644 --- a/packages/nonebot-adapter-ding/nonebot/adapters/ding/bot.py +++ b/packages/nonebot-adapter-ding/nonebot/adapters/ding/bot.py @@ -114,7 +114,7 @@ class Bot(BaseBot): api: str, event: Optional[MessageEvent] = None, **data) -> Any: - if self.connection_type != "http": + if not isinstance(self.request, HTTPRequest): log("ERROR", "Only support http connection.") return diff --git a/packages/nonebot-adapter-ding/nonebot/adapters/ding/message.py b/packages/nonebot-adapter-ding/nonebot/adapters/ding/message.py index eb7d655d..42012f9e 100644 --- a/packages/nonebot-adapter-ding/nonebot/adapters/ding/message.py +++ b/packages/nonebot-adapter-ding/nonebot/adapters/ding/message.py @@ -17,12 +17,21 @@ class MessageSegment(BaseMessageSegment["Message"]): @overrides(BaseMessageSegment) def __str__(self) -> str: + """ + 该消息段所代表的 str,在命令匹配部分使用, + 钉钉目前只支持匹配 text 命令 + """ if self.type == "text": return str(self.data["content"]) - elif self.type == "markdown": - return str(self.data["text"]) return "" + def __bool__(self) -> bool: + """ + 因为暂时还不支持 text 和 markdown 之外的其他复杂消息段的 `__str__`(也不太需要), + 会导致判断非这两种类型的消息段的布尔值为 true 的时候出错 + """ + return self.data is not None + @overrides(BaseMessageSegment) def is_text(self) -> bool: return self.type == "text"