feat(discord): add win/loss status to match messages
All checks were successful
continuous-integration/drone Build is passing

- 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
This commit is contained in:
Ching L 2025-10-24 14:39:41 +08:00
parent bb4ee378d9
commit 7f81574192
2 changed files with 5 additions and 2 deletions

View File

@ -51,15 +51,17 @@ async def send_message(channel):
data = await dota.serialize_match_for_discord(match_) data = await dota.serialize_match_for_discord(match_)
logger.info(f"sending match {match_['match_id']}, {data}") logger.info(f"sending match {match_['match_id']}, {data}")
try: try:
# 从embed中提取朋友信息 # 从embed中提取朋友信息,并添加胜负状态
friends_info = "" friends_info = ""
win_status = "✅ **胜利** " if data.get('win') else "❌ **失败** "
if data['embeds'] and len(data['embeds']) > 0: if data['embeds'] and len(data['embeds']) > 0:
embed = data['embeds'][0] embed = data['embeds'][0]
if 'fields' in embed and len(embed['fields']) > 2: if 'fields' in embed and len(embed['fields']) > 2:
# 第三个field包含了朋友信息 # 第三个field包含了朋友信息
field = embed['fields'][2] field = embed['fields'][2]
if 'value' in field and field['value']: 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'] content = data['content']

View File

@ -503,6 +503,7 @@ async def serialize_match_for_discord(match_):
data = { data = {
"content": content, "content": content,
"tts": False, "tts": False,
"win": win,
"embeds": [ "embeds": [
{ {
"color": color, "color": color,