From 7f81574192d37cf045a120b667eb92580c0f06c2 Mon Sep 17 00:00:00 2001 From: Ching L Date: Fri, 24 Oct 2025 14:39:41 +0800 Subject: [PATCH] feat(discord): add win/loss status to match messages - Added win field to serialize_match_for_discord return data - Display victory/defeat emoji and text at start of match messages - Extract win status directly from data instead of inferring from embed color --- discord_bot.py | 6 ++++-- dota.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/discord_bot.py b/discord_bot.py index 939102e..bc45a6c 100644 --- a/discord_bot.py +++ b/discord_bot.py @@ -51,15 +51,17 @@ async def send_message(channel): data = await dota.serialize_match_for_discord(match_) logger.info(f"sending match {match_['match_id']}, {data}") try: - # 从embed中提取朋友信息 + # 从embed中提取朋友信息,并添加胜负状态 friends_info = "" + win_status = "✅ **胜利** " if data.get('win') else "❌ **失败** " + 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" + friends_info = f"{win_status}**{field['value']}** 的比赛:\n\n" # 将朋友信息放在内容开头,连胜连败消息只在第一场比赛时添加 content = data['content'] diff --git a/dota.py b/dota.py index ac3e204..2747d14 100644 --- a/dota.py +++ b/dota.py @@ -503,6 +503,7 @@ async def serialize_match_for_discord(match_): data = { "content": content, "tts": False, + "win": win, "embeds": [ { "color": color,