From c85eeb9d74a84a09de0d85baff37a640677bc6fd Mon Sep 17 00:00:00 2001 From: Ching L Date: Thu, 11 Sep 2025 14:30:47 +0800 Subject: [PATCH] feat(discord): show player names at the beginning of match messages - Extract friend names from embed fields - Display player names prominently before match details - Maintain streak notifications ordering when present --- discord_bot.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/discord_bot.py b/discord_bot.py index e8dd91f..1351ea2 100644 --- a/discord_bot.py +++ b/discord_bot.py @@ -48,15 +48,27 @@ async def send_message(channel): data = await dota.serialize_match_for_discord(match_) logger.info(f"sending match {match_['match_id']}, {data}") try: - # 将连胜连败消息放在内容开头 + # 从embed中提取朋友信息 + friends_info = "" + if data['embeds'] and len(data['embeds']) > 0: + embed = data['embeds'][0] + if 'fields' in embed and len(embed['fields']) > 2: + # 第三个field包含了朋友信息 + field = embed['fields'][2] + if 'value' in field and field['value']: + friends_info = f"**{field['value']}** 的比赛:\n\n" + + # 将朋友信息和连胜连败消息放在内容开头 content = data['content'] if streak_notifications: streak_msg = '\n'.join(streak_notifications) + '\n\n' - content = streak_msg + content + content = friends_info + streak_msg + content # 发送后清空通知列表,避免重复发送 streak_notifications = [] + else: + content = friends_info + content - # 发送比赛结果(连胜信息已包含在content开头) + # 发送比赛结果 await channel.send(content=content, embeds=[discord.Embed.from_dict(embed) for embed in data['embeds']]) except Exception as e: