modified: bot.py

This commit is contained in:
SimolZimol
2026-01-09 20:36:13 +01:00
parent 796468d664
commit c36d6bb7e1

22
bot.py
View File

@@ -108,12 +108,21 @@ async def fetch_project_names():
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(PROJECTS_URL) as resp: async with session.get(PROJECTS_URL) as resp:
data = await resp.json() data = await resp.json()
names = [v["name"] for v in data.values() if "name" in v] keys = list(data.keys())
_project_cache = names _project_cache = keys
return names return keys
except Exception: except Exception:
return [] return []
async def fetch_project_display_name(project_key):
try:
async with aiohttp.ClientSession() as session:
async with session.get(PROJECTS_URL) as resp:
data = await resp.json()
return data.get(project_key, {}).get("name", project_key)
except Exception:
return project_key
@bot.event @bot.event
async def on_ready(): async def on_ready():
print(f'{bot.user} has connected to Discord!') print(f'{bot.user} has connected to Discord!')
@@ -154,7 +163,7 @@ async def setup(
@bot.tree.command(name="ticket", description="Create a new project update ticket") @bot.tree.command(name="ticket", description="Create a new project update ticket")
@app_commands.describe( @app_commands.describe(
project_name="Select the project for this ticket", project_name="Select the project key for this ticket (e.g. friends, joinme)",
title="Brief title for this update", title="Brief title for this update",
message_id="Optional: Discord message ID to reference" message_id="Optional: Discord message ID to reference"
) )
@@ -168,10 +177,11 @@ async def create_ticket(
valid_projects = await fetch_project_names() valid_projects = await fetch_project_names()
if project_name not in valid_projects: if project_name not in valid_projects:
await interaction.response.send_message( await interaction.response.send_message(
f"❌ Invalid project name. Please use one of: {', '.join(valid_projects)}", f"❌ Invalid project key. Please use one of: {', '.join(valid_projects)}",
ephemeral=True ephemeral=True
) )
return return
display_name = await fetch_project_display_name(project_name)
guild_id = interaction.guild.id if interaction.guild else None guild_id = interaction.guild.id if interaction.guild else None
settings = load_server_settings(guild_id) settings = load_server_settings(guild_id)
if not settings or not settings.get("active_channel_id"): if not settings or not settings.get("active_channel_id"):
@@ -199,7 +209,7 @@ async def create_ticket(
color=discord.Color.blue(), color=discord.Color.blue(),
timestamp=datetime.utcnow() timestamp=datetime.utcnow()
) )
embed.add_field(name="📋 Project", value=project_name, inline=True) embed.add_field(name="📋 Project", value=f"{display_name} ({project_name})", inline=True)
embed.add_field(name="📊 Status", value=TicketStatus.PENDING, inline=True) embed.add_field(name="📊 Status", value=TicketStatus.PENDING, inline=True)
embed.add_field(name="👤 Created By", value=interaction.user.mention, inline=True) embed.add_field(name="👤 Created By", value=interaction.user.mention, inline=True)
if message_id: if message_id: