discord-dota-bot/utils.py
Ching cd1fc45044 feat(bot.py, dota.py, utils.py): 增加查询某人战绩的命令
增加查询某人战绩的命令

Signed-off-by: Ching <loooching@gmail.com>
2023-09-18 16:55:24 +08:00

69 lines
1.9 KiB
Python

import datetime
import requests
import logging
# logger_file = '/root/develop/log/dotabot.log'
logger_file = 'dotabot.log'
logging.basicConfig(filename=logger_file, level=logging.INFO)
logger = logging.getLogger(__name__)
def convert_seconds_to_hms(total_seconds):
hours, remainder = divmod(total_seconds, 3600)
minutes, seconds = divmod(remainder, 60)
return hours, minutes, seconds
def is_workday():
return datetime.datetime.today().weekday() < 5
def is_game_time():
# game time is workday 21:00 - 1:00, weekend 10:00 - 1:00
if is_workday():
return datetime.datetime.now().hour >= 21 or datetime.datetime.now().hour < 1
else:
return datetime.datetime.now().hour >= 10 or datetime.datetime.now().hour < 1
def heartbeat():
try:
resp = requests.get('https://up.tunpok.com/api/push/BDb4MJWDVh?status=up&msg=OK&ping=')
except:
logger.error('fail to heartbeat, resp status: %s' % resp.status_code)
pass
def get_ranking(ranking_int):
# (10-15: Herald, 20-25: Guardian, 30-35: Crusader, 40-45: Archon, 50-55: Legend, 60-65: Ancient, 70-75: Divine, 80-85: Immortal).
stars = ranking_int % 10
if ranking_int < 20:
return '先锋 %s' % stars
elif ranking_int < 30:
return '卫士 %s' % stars
elif ranking_int < 40:
return '中军 %s' % stars
elif ranking_int < 50:
return '统帅 %s' % stars
elif ranking_int < 60:
return '传奇 %s' % stars
elif ranking_int < 70:
return '万古流芳 %s' % stars
elif ranking_int < 80:
return '超凡入圣 %s' % stars
elif ranking_int < 90:
return '不朽 %s' % stars
else:
return 'Unknown %s' % stars
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)