# -- version --
__version__ = (1, 0, 0)
# -- version --
# ███╗░░░███╗███████╗░█████╗░██████╗░░█████╗░░██╗░░░░░░░██╗░██████╗░██████╗
# ████╗░████║██╔════╝██╔══██╗██╔══██╗██╔══██╗░██║░░██╗░░██║██╔════╝██╔════╝
# ██╔████╔██║█████╗░░███████║██║░░██║██║░░██║░╚██╗████╗██╔╝╚█████╗░╚█████╗░
# ██║╚██╔╝██║██╔══╝░░██╔══██║██║░░██║██║░░██║░░████╔═████║░░╚═══██╗░╚═══██╗
# ██║░╚═╝░██║███████╗██║░░██║██████╔╝╚█████╔╝░░╚██╔╝░╚██╔╝░██████╔╝██████╔╝
# ╚═╝░░░░░╚═╝╚══════╝╚═╝░░╚═╝╚═════╝░░╚════╝░░░░╚═╝░░░╚═╝░░╚═════╝░╚═════╝░
# © Copyright 2025
# ✈ https://t.me/mead0wssMods
# meta developer: @mead0wssMods
# scope: heroku_only
import herokutl
from .. import loader, utils
import aiohttp
@loader.tds
class DDNetPlayerTime(loader.Module):
"""Получение статистики отыгранного времени игрока DDNet с ddstats.tw"""
strings = {
"name": "DDNetPT",
"no_args": "❌ Укажите ник игрока!",
"api_error_or_player_not_found": "❌ Возможно данный игрок не найден либо ошибка на стороне API",
}
async def client_ready(self, client, db):
self.client = client
@loader.command()
async def ddpt(self, message):
"""<ник> | Получить статистику игрока"""
args = utils.get_args_raw(message)
if not args:
await utils.answer(message, self.strings["no_args"])
return
try:
async with aiohttp.ClientSession() as session:
async with session.get(f"https://ddstats.tw/player/json?player={args}") as resp:
if resp.status != 200:
await utils.answer(message, self.strings["api_error_or_player_not_found"])
return
data = await resp.json()
response = ""
gametypes = data.get("most_played_gametypes", [])
if gametypes:
gametypes_str = []
for gt in gametypes:
hours = round(gt.get("seconds_played", 0) / 3600)
gametypes_str.append(f"{gt.get('key', '?')} - {hours}ч")
response += f"👤 Игрок: {args}\n\n📌 Тип:\n" + "\n".join(gametypes_str) + "
\n\n"
# мапы
maps = data.get("most_played_maps", [])
if maps:
maps_str = []
for m in maps:
hours = round(m.get("seconds_played", 0) / 3600)
maps_str.append(f"{m.get('map_name', '?')} - {hours}ч")
response += "🗺 Карта:\n" + "\n".join(maps_str) + "
\n\n"
# категории
categories = data.get("most_played_categories", [])
if categories:
categories_str = []
for cat in categories:
hours = round(cat.get("seconds_played", 0) / 3600)
categories_str.append(f"{cat.get('key', '?')} - {hours}ч")
response += "📦 Категория:\n" + "\n".join(categories_str) + "
\n\n"
# время
general = data.get("general_activity", {})
if general:
total_hours = round(general.get("total_seconds_played", 0) / 3600)
avg_hours = round(general.get("average_seconds_played", 0) / 3600)
start_date = general.get("start_of_playtime", "?")
response += "⏰️ Время:\n"
response += f"Общее время игры - {total_hours}ч\n"
response += f"Дата начала игры - {start_date}\n"
response += f"Среднее время игры - {avg_hours}ч"
response += "
"
await utils.answer(message, response)
except Exception as e:
await utils.answer(message, f"{self.strings['api_error_or_player_not_found']}: {str(e)}")
# ебеший-ленеивый говнокод