diff --git a/discord_bot.py b/discord_bot.py index 1351ea2..939102e 100644 --- a/discord_bot.py +++ b/discord_bot.py @@ -44,6 +44,9 @@ async def send_message(channel): logger.error(f"Error in send_message task: {e}") return + # 用于标记是否是第一场比赛 + first_match = True + for match_ in matches: data = await dota.serialize_match_for_discord(match_) logger.info(f"sending match {match_['match_id']}, {data}") @@ -58,13 +61,12 @@ async def send_message(channel): if 'value' in field and field['value']: friends_info = f"**{field['value']}** 的比赛:\n\n" - # 将朋友信息和连胜连败消息放在内容开头 + # 将朋友信息放在内容开头,连胜连败消息只在第一场比赛时添加 content = data['content'] - if streak_notifications: + if first_match and streak_notifications: streak_msg = '\n'.join(streak_notifications) + '\n\n' content = friends_info + streak_msg + content - # 发送后清空通知列表,避免重复发送 - streak_notifications = [] + first_match = False # 标记已经处理过第一场比赛 else: content = friends_info + content diff --git a/dota.py b/dota.py index 00a9583..9f3a429 100644 --- a/dota.py +++ b/dota.py @@ -14,6 +14,9 @@ player_client = opendota.PlayersApi() match_client = opendota.MatchesApi() image_generator = ImageGenerator() +# 初始化全局变量,用于存储连胜连败更新 +streak_updates = [] + class BaseModel(peewee.Model): class Meta: