From c401fb5187b6e561e92f0c575ccfb9dadeb85c48 Mon Sep 17 00:00:00 2001 From: Ching Date: Sun, 17 Sep 2023 17:24:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(dota.py):=20=E4=BF=AE=E6=94=B9=E6=AF=94?= =?UTF-8?q?=E8=B5=9B=E4=BF=A1=E6=81=AF=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=9C=80=E9=AB=98=E7=BB=8F=E6=B5=8E=E5=92=8C=E6=9C=80?= =?UTF-8?q?=E9=AB=98=E4=BC=A4=E5=AE=B3=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改比赛信息格式,增加最高经济和最高伤害标识 Signed-off-by: Ching --- dota.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/dota.py b/dota.py index 417e9d8..0211dad 100644 --- a/dota.py +++ b/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