feat: Add end time to Match class

This commit is contained in:
Ching 2024-03-06 11:01:04 +08:00
parent e1e5a63fe7
commit ab5f6695e1

View File

@ -61,6 +61,7 @@ class Match(BaseModel):
'radiant_score': match_.radiant_score, 'radiant_score': match_.radiant_score,
# isoformat utc+8 # isoformat utc+8
'start_time': datetime.datetime.fromtimestamp(match_.start_time).strftime('%Y-%m-%dT%H:%M:%S.000+08:00'), 'start_time': datetime.datetime.fromtimestamp(match_.start_time).strftime('%Y-%m-%dT%H:%M:%S.000+08:00'),
'end_time': datetime.datetime.fromtimestamp(match_.start_time + match_.duration).strftime('%Y-%m-%dT%H:%M:%S.000+08:00'),
'duration': '%d:%02d:%02d' % utils.convert_seconds_to_hms(match_.duration), 'duration': '%d:%02d:%02d' % utils.convert_seconds_to_hms(match_.duration),
'radiant_win': match_.radiant_win, 'radiant_win': match_.radiant_win,
'party_size': self.party_size, 'party_size': self.party_size,
@ -97,6 +98,7 @@ class Friend(BaseModel):
'assists': match_.assists, 'assists': match_.assists,
'party_size': match_.party_size, 'party_size': match_.party_size,
'start_time': match_.start_time, 'start_time': match_.start_time,
'end_time': match_.start_time + match_.duration,
'duration': match_.duration, 'duration': match_.duration,
'average_rank': utils.get_ranking(match_.average_rank), 'average_rank': utils.get_ranking(match_.average_rank),
'hero_id': match_.hero_id, 'hero_id': match_.hero_id,
@ -142,14 +144,15 @@ class Friend(BaseModel):
if match_['average_rank']: if match_['average_rank']:
summary += '\n' + match_['average_rank'] summary += '\n' + match_['average_rank']
start_time = datetime.datetime.fromtimestamp(match_['start_time']).strftime('%Y-%m-%dT%H:%M:%S.000+08:00') # start_time = datetime.datetime.fromtimestamp(match_['start_time']).strftime('%Y-%m-%dT%H:%M:%S.000+08:00')
end_time = datetime.datetime.fromtimestamp(match_['end_time']).strftime('%Y-%m-%dT%H:%M:%S.000+08:00')
hero_name = Hero.get(hero_id=match_['hero_id']).localized_name hero_name = Hero.get(hero_id=match_['hero_id']).localized_name
data['embeds'].append({ data['embeds'].append({
'title': f"{hero_name} {match_['kills']}{match_['deaths']}{match_['assists']}", 'title': f"{hero_name} {match_['kills']}{match_['deaths']}{match_['assists']}",
'description': summary, 'description': summary,
'color': 6732650 if match_['win'] else 16724787, # 66bb6a or FF3333 'color': 6732650 if match_['win'] else 16724787, # 66bb6a or FF3333
'fields': [], 'fields': [],
'timestamp': start_time, 'timestamp': end_time,
'url': f"https://www.opendota.com/matches/{match_['match_id']}", 'url': f"https://www.opendota.com/matches/{match_['match_id']}",
}) })
return data return data
@ -295,7 +298,7 @@ def serialize_match_for_discord(match_):
"name": "opendota", "name": "opendota",
"url": "https://www.opendota.com/matches/%s" % match_['match_id'] "url": "https://www.opendota.com/matches/%s" % match_['match_id']
}, },
"timestamp": match_['start_time'] "timestamp": match_['end_time']
} }
], ],
} }