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: