feat(dota.py): 修改比赛信息格式,增加最高经济和最高伤害标识
修改比赛信息格式,增加最高经济和最高伤害标识 Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
df9e629cdb
commit
c401fb5187
41
dota.py
41
dota.py
@ -98,6 +98,18 @@ def get_friends_recent_matches():
|
||||
matches.append(match_obj.serialize_match())
|
||||
return matches
|
||||
|
||||
def shorten_digits(num):
|
||||
# if num like 12345, return 1.2w
|
||||
# if num like 1234, return 1.2k
|
||||
# if num < 1000, return num
|
||||
# if result ends with 0, remove it
|
||||
if num >= 10000:
|
||||
return '%.1fw' % (num / 10000)
|
||||
elif num >= 1000:
|
||||
return '%.1fk' % (num / 1000)
|
||||
else:
|
||||
return str(num)
|
||||
|
||||
def serialize_match_for_discord(match_):
|
||||
# {
|
||||
# "content": "## 天辉\n\n我(LV23 大鱼人): 2 杀 5 死 3 助 | 12345 经济 | 13442 伤害\n我(LV23 大鱼人): 2 杀 5 死 3 助 | 12345 经济 | 13442 伤害\n我(LV23 大鱼人): 2 杀 5 死 3 助 | 12345 经济 | 13442 伤害\n我(LV23 大鱼人): 2 杀 5 死 3 助 | 12345 经济 | 13442 伤害\n我(LV23 大鱼人): 2 杀 5 死 3 助 | 12345 经济 | 13442 伤害\n\n## 夜魇\n\n我(LV23 大鱼人): 2 杀 5 死 3 助 | 12345 经济 | 13442 伤害\n我(LV23 大鱼人): 2 杀 5 死 3 助 | 12345 经济 | 13442 伤害\n我(LV23 大鱼人): 2 杀 5 死 3 助 | 12345 经济 | 13442 伤害\n我(LV23 大鱼人): 2 杀 5 死 3 助 | 12345 经济 | 13442 伤害\n我(LV23 大鱼人): 2 杀 5 死 3 助 | 12345 经济 | 13442 伤害\n",
|
||||
@ -149,12 +161,39 @@ def serialize_match_for_discord(match_):
|
||||
|
||||
radiant = []
|
||||
dire = []
|
||||
radiant_highest_gold = 0
|
||||
radiant_highest_gold_idx = 0
|
||||
radiant_highest_damage = 0
|
||||
radiant_highest_damage_idx = 0
|
||||
dire_highest_gold = 0
|
||||
dire_highest_gold_idx = 0
|
||||
dire_highest_damage = 0
|
||||
dire_highest_damage_idx = 0
|
||||
|
||||
for player in match_['players']:
|
||||
desc = f"{player['nickname'] or player['personaname']}(LV{player['level']} {player['hero']}): {player['kills']} 杀 {player['deaths']} 死 {player['assists']} 助 | {player['total_gold']} 经济 | {player['hero_damage']} 伤害"
|
||||
desc = f"{player['nickname'] or player['personaname']}(Lv.**{player['level']}** {player['hero']}): **{player['kills']}** 杀 **{player['deaths']}** 死 **{player['assists']}** 助 | **{shorten_digits(player['total_gold'])}** 经济 | **{shorten_digits(player['hero_damage'])}** 伤害 "
|
||||
|
||||
if player['is_radiant']:
|
||||
radiant.append(desc)
|
||||
if radiant_highest_gold < player['total_gold']:
|
||||
radiant_highest_gold = player['total_gold']
|
||||
radiant_highest_gold_idx = len(radiant) - 1
|
||||
if radiant_highest_damage < player['hero_damage']:
|
||||
radiant_highest_damage = player['hero_damage']
|
||||
radiant_highest_damage_idx = len(radiant) - 1
|
||||
else:
|
||||
dire.append(desc)
|
||||
if dire_highest_gold < player['total_gold']:
|
||||
dire_highest_gold = player['total_gold']
|
||||
dire_highest_gold_idx = len(dire) - 1
|
||||
if dire_highest_damage < player['hero_damage']:
|
||||
dire_highest_damage = player['hero_damage']
|
||||
dire_highest_damage_idx = len(dire) - 1
|
||||
|
||||
radiant[radiant_highest_gold_idx] = radiant[radiant_highest_gold_idx] + '💰'
|
||||
radiant[radiant_highest_damage_idx] = radiant[radiant_highest_damage_idx] + '🩸'
|
||||
dire[dire_highest_gold_idx] = dire[dire_highest_gold_idx] + '💰'
|
||||
dire[dire_highest_damage_idx] = dire[dire_highest_damage_idx] + '🩸'
|
||||
|
||||
color = 6732650 if win else 16724787 # 66bb6a or FF3333
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user