Skip to content

Commit 83112c6

Browse files
committed
prevent say nothing
1 parent 276d4bc commit 83112c6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/wechaty/user/contact.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ async def say(self, message: Union[str, Message, FileBox, Contact, UrlLink]
202202
say something
203203
:param message: message content
204204
"""
205+
if not message:
206+
log.error('can"t say nothing')
207+
return None
208+
205209
if not self.is_ready():
206210
await self.ready()
207211

src/wechaty/user/message.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __str__(self) -> str:
111111
return ''.join(message_list)
112112

113113
async def say(self, msg: Union[str, Contact, FileBox, UrlLink, MiniProgram],
114-
mention_ids: Optional[List[str]] = None) -> Message:
114+
mention_ids: Optional[List[str]] = None) -> Optional[Message]:
115115
"""
116116
send the message to the conversation envrioment which is source of this message.
117117
@@ -125,6 +125,10 @@ async def say(self, msg: Union[str, Contact, FileBox, UrlLink, MiniProgram],
125125
"""
126126
log.info('say() <%s>', msg)
127127

128+
if not msg:
129+
log.error('can"t say nothing')
130+
return None
131+
128132
room = self.room()
129133
if room is not None:
130134
conversation_id = room.room_id

src/wechaty/user/room.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ async def say(self,
259259
"""
260260
log.info('Room say <%s, %s>', some_thing, mention_ids)
261261

262+
if not some_thing:
263+
log.error('can"t say nothing')
264+
return None
265+
262266
# we should import UrlLink type locally because of circular dependency
263267

264268
from wechaty.user.url_link import UrlLink

0 commit comments

Comments
 (0)