feat(discord): show player names at the beginning of match messages
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- Extract friend names from embed fields - Display player names prominently before match details - Maintain streak notifications ordering when present
This commit is contained in:
parent
21c7b95653
commit
c85eeb9d74
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user