🐛 fix ding adapter issues

1. cannot send complicate message, such as actionCard
2. fix judge current connection mode
This commit is contained in:
artin 2021-09-13 01:18:25 +08:00
parent 53a576dae5
commit 9931563d80
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"