调整 message_util 的发送text方法名,方便替换wcf.send_text。加入了虚拟群组管理功能;
This commit is contained in:
@@ -18,7 +18,7 @@ class MessageUtil:
|
||||
self.contact_manager = contact_manager
|
||||
self.LOG = logging.getLogger("MessageUtil")
|
||||
|
||||
def send_text_msg(self, msg: str, receiver: str, at_list: str = "") -> None:
|
||||
def send_text(self, msg: str, receiver: str, at_list: str = "") -> None:
|
||||
"""
|
||||
发送文本消息
|
||||
|
||||
@@ -56,11 +56,25 @@ class MessageUtil:
|
||||
"""
|
||||
# 风控处理,随机延迟发送,解决群消息高频发送导致的微信风险
|
||||
time.sleep(random.uniform(0.5, 1.5))
|
||||
|
||||
|
||||
self.LOG.info(f"Sending file to {receiver}: {file_path}")
|
||||
self.wcf.send_file(file_path, receiver)
|
||||
|
||||
def send_rich_text(self, name: str, account: str, title: str, digest: str, url: str, thumburl: str, receiver: str) -> int:
|
||||
def send_image(self, image_path: str, receiver: str) -> None:
|
||||
"""
|
||||
发送文件消息
|
||||
|
||||
:param image_path: 文件路径
|
||||
:param receiver: 接收人wxid或者群id
|
||||
"""
|
||||
# 风控处理,随机延迟发送,解决群消息高频发送导致的微信风险
|
||||
time.sleep(random.uniform(0.5, 1.5))
|
||||
|
||||
self.LOG.info(f"Sending file to {receiver}: {image_path}")
|
||||
self.wcf.send_image(image_path, receiver)
|
||||
|
||||
def send_rich_text(self, name: str, account: str, title: str, digest: str, url: str, thumburl: str,
|
||||
receiver: str) -> int:
|
||||
"""
|
||||
发送富文本消息
|
||||
|
||||
@@ -85,7 +99,7 @@ class MessageUtil:
|
||||
"""
|
||||
# 风控处理,随机延迟发送,解决群消息高频发送导致的微信风险
|
||||
time.sleep(random.uniform(0.5, 1.5))
|
||||
|
||||
|
||||
self.LOG.info(f"Sending rich text to {receiver}: {title}")
|
||||
return self.wcf.send_rich_text(name, account, title, digest, url, thumburl, receiver)
|
||||
|
||||
@@ -100,4 +114,4 @@ class MessageUtil:
|
||||
# 修改使用 allContacts 的地方,改为使用 contact_manager
|
||||
# 例如:
|
||||
# 原来的代码: nickname = self.allContacts.get(wxid, wxid)
|
||||
# 修改为: nickname = self.contact_manager.get_nickname(wxid)
|
||||
# 修改为: nickname = self.contact_manager.get_nickname(wxid)
|
||||
|
||||
Reference in New Issue
Block a user