Enhance Modrinth project tracking embeds with additional project details, including thumbnails, categories, and statistics. Improve update notifications by including project icons and version-specific information such as supported loaders and game versions.
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run

This commit is contained in:
Valerie 2025-05-23 05:11:53 -04:00
parent 767d656c8d
commit 1cb22dd8b7

View file

@ -72,11 +72,41 @@ class ModrinthTracker(commands.Cog):
if latest_version:
embed = discord.Embed(
title=f"Current Version of {project_data['title']}",
description=f"Version: {latest_version.get('version_number', 'Unknown')}\n\n{latest_version.get('changelog', 'No changelog provided')}",
description=f"Version: `{latest_version.get('version_number', 'Unknown')}`\n\n{latest_version.get('changelog', 'No changelog provided')}",
url=f"https://modrinth.com/project/{project_id}",
color=discord.Color.blue(),
timestamp=datetime.now()
)
# Add project icon as thumbnail if available
if project_data.get("icon_url"):
embed.set_thumbnail(url=project_data["icon_url"])
# Add featured gallery image if available
if project_data.get("gallery"):
for image in project_data["gallery"]:
if image.get("featured", False):
embed.set_image(url=image["url"])
break
# Add project details
categories = ", ".join(f"`{cat}`" for cat in project_data.get("categories", []))
if categories:
embed.add_field(name="Categories", value=categories, inline=True)
downloads = project_data.get("downloads", 0)
followers = project_data.get("followers", 0)
stats = f"📥 {downloads:,} Downloads\n👥 {followers:,} Followers"
embed.add_field(name="Statistics", value=stats, inline=True)
# Add version details
loaders = ", ".join(f"`{loader}`" for loader in latest_version.get("loaders", []))
if loaders:
embed.add_field(name="Supported Loaders", value=loaders, inline=True)
game_versions = ", ".join(f"`{ver}`" for ver in latest_version.get("game_versions", []))
if game_versions:
embed.add_field(name="Game Versions", value=game_versions, inline=True)
embed.set_footer(text="Tracking Started")
await channel.send(embed=embed)
else:
await channel.send("No version information is currently available for this project.")
@ -109,15 +139,43 @@ class ModrinthTracker(commands.Cog):
await ctx.send("No projects are currently being tracked.")
return
embed = discord.Embed(title="Tracked Modrinth Projects", color=discord.Color.blue())
embed = discord.Embed(
title="📋 Tracked Modrinth Projects",
color=discord.Color.blue(),
timestamp=datetime.now()
)
for project_id, data in tracked_projects.items():
channel = self.bot.get_channel(data["channel"])
channel_mention = channel.mention if channel else "Unknown channel"
embed.add_field(
name=data.get("name", project_id),
value=f"ID: `{project_id}`\nChannel: {channel_mention}",
inline=False
)
# Get current project info
try:
async with self.session.get(f"{BASE_URL}/project/{project_id}") as response:
if response.status == 200:
project_data = await response.json()
downloads = project_data.get("downloads", 0)
followers = project_data.get("followers", 0)
description = f"**ID:** `{project_id}`\n**Channel:** {channel_mention}\n📥 {downloads:,} Downloads\n👥 {followers:,} Followers"
embed.add_field(
name=data.get("name", project_id),
value=description,
inline=False
)
else:
embed.add_field(
name=data.get("name", project_id),
value=f"**ID:** `{project_id}`\n**Channel:** {channel_mention}",
inline=False
)
except Exception:
embed.add_field(
name=data.get("name", project_id),
value=f"**ID:** `{project_id}`\n**Channel:** {channel_mention}",
inline=False
)
embed.set_footer(text=f"Total Projects: {len(tracked_projects)}")
await ctx.send(embed=embed)
async def update_checker(self):
@ -133,6 +191,12 @@ class ModrinthTracker(commands.Cog):
tracked_projects = guild_data.get("tracked_projects", {})
for project_id, data in tracked_projects.items():
try:
# Get project info for the embed
async with self.session.get(f"{BASE_URL}/project/{project_id}") as response:
if response.status != 200:
continue
project_data = await response.json()
async with self.session.get(f"{BASE_URL}/project/{project_id}/version") as response:
if response.status != 200:
continue
@ -148,12 +212,31 @@ class ModrinthTracker(commands.Cog):
channel = self.bot.get_channel(data["channel"])
if channel:
embed = discord.Embed(
title=f"New Update for {data.get('name', project_id)}!",
description=f"Version: {latest_version.get('version_number', 'Unknown')}\n\n{latest_version.get('changelog', 'No changelog provided')}",
title=f"🆕 New Update for {data.get('name', project_id)}!",
description=f"**Version:** `{latest_version.get('version_number', 'Unknown')}`\n\n{latest_version.get('changelog', 'No changelog provided')}",
url=f"https://modrinth.com/project/{project_id}",
color=discord.Color.green(),
timestamp=datetime.now()
)
# Add project icon as thumbnail
if project_data.get("icon_url"):
embed.set_thumbnail(url=project_data["icon_url"])
# Add version details
loaders = ", ".join(f"`{loader}`" for loader in latest_version.get("loaders", []))
if loaders:
embed.add_field(name="Supported Loaders", value=loaders, inline=True)
game_versions = ", ".join(f"`{ver}`" for ver in latest_version.get("game_versions", []))
if game_versions:
embed.add_field(name="Game Versions", value=game_versions, inline=True)
# Add download info
downloads = project_data.get("downloads", 0)
embed.add_field(name="Total Downloads", value=f"📥 {downloads:,}", inline=True)
embed.set_footer(text="Update Released")
await channel.send(embed=embed)
tracked_projects[project_id]["latest_version"] = latest_version["id"]