mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 05:16:48 +08:00
Merge pull request #521 from nonebot/fix-ding
This commit is contained in:
commit
b25a0387ba
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user