Merge pull request #521 from nonebot/fix-ding

This commit is contained in:
Artin 2021-09-13 01:44:28 +08:00 committed by GitHub
commit b25a0387ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -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:

View File

@ -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

View File

@ -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"