fix: resolve streak notification issues
- Initialize global streak_updates variable to prevent NameError - Fix streak notifications only showing for first match - Ensure notifications appear once per batch instead of being lost
This commit is contained in:
parent
c85eeb9d74
commit
7498f413bf
@ -44,6 +44,9 @@ async def send_message(channel):
|
|||||||
logger.error(f"Error in send_message task: {e}")
|
logger.error(f"Error in send_message task: {e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# 用于标记是否是第一场比赛
|
||||||
|
first_match = True
|
||||||
|
|
||||||
for match_ in matches:
|
for match_ in matches:
|
||||||
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}")
|
||||||
@ -58,13 +61,12 @@ async def send_message(channel):
|
|||||||
if 'value' in field and field['value']:
|
if 'value' in field and field['value']:
|
||||||
friends_info = f"**{field['value']}** 的比赛:\n\n"
|
friends_info = f"**{field['value']}** 的比赛:\n\n"
|
||||||
|
|
||||||
# 将朋友信息和连胜连败消息放在内容开头
|
# 将朋友信息放在内容开头,连胜连败消息只在第一场比赛时添加
|
||||||
content = data['content']
|
content = data['content']
|
||||||
if streak_notifications:
|
if first_match and streak_notifications:
|
||||||
streak_msg = '\n'.join(streak_notifications) + '\n\n'
|
streak_msg = '\n'.join(streak_notifications) + '\n\n'
|
||||||
content = friends_info + streak_msg + content
|
content = friends_info + streak_msg + content
|
||||||
# 发送后清空通知列表,避免重复发送
|
first_match = False # 标记已经处理过第一场比赛
|
||||||
streak_notifications = []
|
|
||||||
else:
|
else:
|
||||||
content = friends_info + content
|
content = friends_info + content
|
||||||
|
|
||||||
|
|||||||
3
dota.py
3
dota.py
@ -14,6 +14,9 @@ player_client = opendota.PlayersApi()
|
|||||||
match_client = opendota.MatchesApi()
|
match_client = opendota.MatchesApi()
|
||||||
image_generator = ImageGenerator()
|
image_generator = ImageGenerator()
|
||||||
|
|
||||||
|
# 初始化全局变量,用于存储连胜连败更新
|
||||||
|
streak_updates = []
|
||||||
|
|
||||||
|
|
||||||
class BaseModel(peewee.Model):
|
class BaseModel(peewee.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user