From 39ce723a9bae658e132d80e2b5b16c9723f6f744 Mon Sep 17 00:00:00 2001 From: liuwei Date: Tue, 3 Jun 2025 12:25:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=94=E5=AF=B9=E4=BA=86=E5=B0=B1=E5=8F=91?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=9F=B3=E4=B9=90=E5=8D=A1=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/guess_song/main.py | 71 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/plugins/guess_song/main.py b/plugins/guess_song/main.py index 38f45ca..311079d 100644 --- a/plugins/guess_song/main.py +++ b/plugins/guess_song/main.py @@ -208,7 +208,10 @@ class GuessSongPlugin(MessagePluginInterface): "song_name": song_info.get("song_name", ""), "singer_name": song_info.get("singer_name", ""), "start_time": time.time(), - "hint_given": False + "hint_given": False, + "play_url": song_info.get("play_url"), + "singer_pic": song_info.get('cover', '') or song_info.get('cover', ''), + "data_url": song_info.get('link', '') } if self.redis_db: @@ -263,7 +266,7 @@ class GuessSongPlugin(MessagePluginInterface): # 删除游戏会话 if self.redis_db: self.redis_db.delete_game_session(session_id) - + await self._send_music_message(bot, game_data, session_id) return True, "猜对了" else: # 答案错误 @@ -399,3 +402,67 @@ class GuessSongPlugin(MessagePluginInterface): except Exception as e: self.LOG.error(f"发送歌曲片段出错: {e}") return False + + async def _send_music_message(self, bot: WechatAPIClient, song_info: Dict[str, Any], receiver: str) -> bool: + """发送音乐消息""" + try: + song_name = song_info.get("song_name", "") + singer_name = song_info.get("singer_name", "") + play_url = song_info.get("play_url", "") + singer_pic = song_info.get("singer_pic", "") + data_url = song_info.get("data_url", "") + + xml_message = f""" + {song_name} + {singer_name}-点击三角直接播放 + view + 3 + 0 + + {data_url} + {play_url} + + + + + + + + + + + + 0 + + + + + + + + 0 + + + + + + 0 + + + {singer_pic} + +0 + + 49 + 汽水音乐 + +""" + + self.LOG.info(f"发送音乐消息:{xml_message}") + res = await bot.send_app_message(wxid=receiver, xml=xml_message, type=0) + self.LOG.info(f"发送音乐消息 res:{res}") + return True + + except Exception as e: + self.LOG.error(f"发送音乐消息出错: {e}") + return False