入群通知,使用富文本内容

This commit is contained in:
liuwei
2025-04-07 09:44:01 +08:00
parent 2dc2631f76
commit 28117e48cd
3 changed files with 37 additions and 5 deletions

View File

@@ -77,7 +77,7 @@
}
.log-content {
max-height: 600px;
max-height: 700px;
overflow-y: auto;
background-color: #f5f5f5;
padding: 10px;

View File

@@ -60,6 +60,35 @@ class MessageUtil:
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:
"""
发送富文本消息
卡片样式:
|-------------------------------------|
|title, 最长两行 |
|(长标题, 标题短的话这行没有) |
|digest, 最多三行,会占位 |--------|
|digest, 最多三行,会占位 |thumburl|
|digest, 最多三行,会占位 |--------|
|(account logo) name |
|-------------------------------------|
:param name: 左下显示的名字
:param account: 填公众号 id 可以显示对应的头像gh_ 开头的)
:param title: 标题,最多两行
:param digest: 摘要,三行
:param url: 点击后跳转的链接
:param thumburl: 缩略图的链接
:param receiver: 接收人, wxid 或者 roomid
:return: 0 为成功,其他失败
"""
# 风控处理,随机延迟发送,解决群消息高频发送导致的微信风险
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)
def update_contacts(self, contacts: dict) -> None:
"""
更新联系人字典

View File

@@ -208,12 +208,15 @@ class GroupMemberChangePlugin(MessagePluginInterface):
"""发送成员入群通知"""
now_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
message = f"""【入群欢迎】
message = f"""
欢迎新成员: {nickname}
入群时间: {now_time}
⌚️: {now_time}
"""
# 使用message_util发送消息
self.message_util.send_text_msg(message, group_id)
# 使用message_util发送消息 编写一个 send_rich_text 方法
self.message_util.send_rich_text("bot", "gh_bot", f"欢迎 {nickname} 加入群聊", message,
"https://hot.imsyy.top/#/",
"https://github.com/bovine-liu/liu_icon/blob/main/icon/a-bot.jpg",
group_id)
self.LOG.info(f"已发送入群通知: {nickname} 加入群 {group_id}")
@property