modified: bot.py
This commit is contained in:
112
bot.py
112
bot.py
@@ -54,6 +54,8 @@ def init_db():
|
|||||||
creator BIGINT,
|
creator BIGINT,
|
||||||
created_at VARCHAR(32),
|
created_at VARCHAR(32),
|
||||||
reference_message_id VARCHAR(32),
|
reference_message_id VARCHAR(32),
|
||||||
|
original_text TEXT,
|
||||||
|
download_link VARCHAR(512),
|
||||||
archived BOOLEAN DEFAULT FALSE
|
archived BOOLEAN DEFAULT FALSE
|
||||||
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
|
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
|
||||||
''')
|
''')
|
||||||
@@ -115,8 +117,8 @@ def save_ticket(ticket_id, ticket):
|
|||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
REPLACE INTO tickets (ticket_id, message_id, channel_id, title, project, status, creator, created_at, reference_message_id, archived)
|
REPLACE INTO tickets (ticket_id, message_id, channel_id, title, project, status, creator, created_at, reference_message_id, original_text, download_link, archived)
|
||||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
''', (
|
''', (
|
||||||
ticket_id,
|
ticket_id,
|
||||||
ticket['message_id'],
|
ticket['message_id'],
|
||||||
@@ -127,6 +129,8 @@ def save_ticket(ticket_id, ticket):
|
|||||||
ticket['creator'],
|
ticket['creator'],
|
||||||
ticket['created_at'],
|
ticket['created_at'],
|
||||||
ticket.get('reference_message_id'),
|
ticket.get('reference_message_id'),
|
||||||
|
ticket.get('original_text'),
|
||||||
|
ticket.get('download_link'),
|
||||||
ticket.get('archived', False)
|
ticket.get('archived', False)
|
||||||
))
|
))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
@@ -268,28 +272,47 @@ async def create_ticket(
|
|||||||
# Create ticket ID from database
|
# Create ticket ID from database
|
||||||
ticket_id = get_next_ticket_id()
|
ticket_id = get_next_ticket_id()
|
||||||
|
|
||||||
# Create embed for the ticket
|
# Fetch original message if message_id provided
|
||||||
|
original_text = None
|
||||||
|
original_author = None
|
||||||
|
if message_id:
|
||||||
|
try:
|
||||||
|
ref_message = await interaction.channel.fetch_message(int(message_id))
|
||||||
|
original_text = ref_message.content[:500] # Limit to 500 chars
|
||||||
|
original_author = ref_message.author
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Create embed for the ticket with improved design
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title=f"🎫 {ticket_id}: {title}",
|
title=f"🎫 {title}",
|
||||||
description=f"**Project Update Request**",
|
description=f"**Project:** {project_name}\n**Ticket ID:** `{ticket_id}`",
|
||||||
color=discord.Color.blue(),
|
color=0x5865F2, # Discord Blurple
|
||||||
timestamp=datetime.utcnow()
|
timestamp=datetime.utcnow()
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.add_field(name="📋 Project", value=project_name, inline=True)
|
# Add original request if available
|
||||||
|
if original_text and original_author:
|
||||||
|
embed.add_field(
|
||||||
|
name="💬 Original Request",
|
||||||
|
value=f"> {original_text}\n\n— {original_author.mention}",
|
||||||
|
inline=False
|
||||||
|
)
|
||||||
|
|
||||||
|
# Status and creator info
|
||||||
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)
|
||||||
|
embed.add_field(name="📅 Created", value=f"<t:{int(datetime.utcnow().timestamp())}:R>", inline=True)
|
||||||
|
|
||||||
if message_id:
|
# Project links
|
||||||
embed.add_field(name="🔗 Reference Message ID", value=f"`{message_id}`", inline=False)
|
|
||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="🌐 Project Links",
|
name="🌐 Links",
|
||||||
value=f"[All Projects](https://devanturas.net/projects) | [Project Details](https://devanturas.net/projects/{project_name})",
|
value=f"[📦 All Projects](https://devanturas.net/projects) • [📋 {project_name}](https://devanturas.net/projects/{project_name})",
|
||||||
inline=False
|
inline=False
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.set_footer(text=f"Ticket ID: {ticket_id}")
|
embed.set_footer(text=f"Update Ticket System • {ticket_id}", icon_url="https://cdn.discordapp.com/emojis/1234567890.png")
|
||||||
|
embed.set_thumbnail(url="https://devanturas.net/assets/logo.png")
|
||||||
|
|
||||||
# Send to active channel
|
# Send to active channel
|
||||||
ticket_message = await active_channel.send(embed=embed)
|
ticket_message = await active_channel.send(embed=embed)
|
||||||
@@ -303,7 +326,9 @@ async def create_ticket(
|
|||||||
"status": TicketStatus.PENDING,
|
"status": TicketStatus.PENDING,
|
||||||
"creator": interaction.user.id,
|
"creator": interaction.user.id,
|
||||||
"created_at": datetime.utcnow().isoformat(),
|
"created_at": datetime.utcnow().isoformat(),
|
||||||
"reference_message_id": message_id
|
"reference_message_id": message_id,
|
||||||
|
"original_text": original_text,
|
||||||
|
"download_link": None
|
||||||
}
|
}
|
||||||
save_ticket(ticket_id, ticket)
|
save_ticket(ticket_id, ticket)
|
||||||
|
|
||||||
@@ -319,7 +344,8 @@ async def create_ticket(
|
|||||||
@bot.tree.command(name="status", description="Update ticket status")
|
@bot.tree.command(name="status", description="Update ticket status")
|
||||||
@app_commands.describe(
|
@app_commands.describe(
|
||||||
ticket_id="The ticket ID (e.g., TICKET-0001)",
|
ticket_id="The ticket ID (e.g., TICKET-0001)",
|
||||||
new_status="The new status for the ticket"
|
new_status="The new status for the ticket",
|
||||||
|
download_link="(Optional) Download link for update - use when marking as completed"
|
||||||
)
|
)
|
||||||
@app_commands.choices(new_status=[
|
@app_commands.choices(new_status=[
|
||||||
app_commands.Choice(name="⏳ Pending", value="pending"),
|
app_commands.Choice(name="⏳ Pending", value="pending"),
|
||||||
@@ -330,7 +356,8 @@ async def create_ticket(
|
|||||||
async def update_status(
|
async def update_status(
|
||||||
interaction: discord.Interaction,
|
interaction: discord.Interaction,
|
||||||
ticket_id: str,
|
ticket_id: str,
|
||||||
new_status: str
|
new_status: str,
|
||||||
|
download_link: str = None
|
||||||
):
|
):
|
||||||
"""Update the status of a ticket"""
|
"""Update the status of a ticket"""
|
||||||
|
|
||||||
@@ -356,6 +383,11 @@ async def update_status(
|
|||||||
old_status = ticket["status"]
|
old_status = ticket["status"]
|
||||||
new_status_text = status_map[new_status]
|
new_status_text = status_map[new_status]
|
||||||
ticket["status"] = new_status_text
|
ticket["status"] = new_status_text
|
||||||
|
|
||||||
|
# Add download link if provided and status is completed
|
||||||
|
if download_link and new_status == "completed":
|
||||||
|
ticket["download_link"] = download_link
|
||||||
|
|
||||||
save_ticket(ticket_id, ticket)
|
save_ticket(ticket_id, ticket)
|
||||||
|
|
||||||
# Get the ticket message
|
# Get the ticket message
|
||||||
@@ -379,18 +411,50 @@ async def update_status(
|
|||||||
|
|
||||||
# Change color based on status
|
# Change color based on status
|
||||||
if new_status == "completed":
|
if new_status == "completed":
|
||||||
embed.color = discord.Color.green()
|
embed.color = 0x57F287 # Green
|
||||||
elif new_status == "in_progress":
|
elif new_status == "in_progress":
|
||||||
embed.color = discord.Color.orange()
|
embed.color = 0xFEE75C # Yellow
|
||||||
elif new_status == "cancelled":
|
elif new_status == "cancelled":
|
||||||
embed.color = discord.Color.red()
|
embed.color = 0xED4245 # Red
|
||||||
|
else:
|
||||||
|
embed.color = 0x5865F2 # Blurple
|
||||||
|
|
||||||
|
# Add download link if provided
|
||||||
|
if download_link and new_status == "completed":
|
||||||
|
# Update or add download link field
|
||||||
|
download_field_exists = False
|
||||||
|
for i, field in enumerate(embed.fields):
|
||||||
|
if "Download" in field.name or "🔗" in field.name:
|
||||||
|
embed.set_field_at(i, name="🔗 Download", value=f"[Download Update]({download_link})", inline=False)
|
||||||
|
download_field_exists = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not download_field_exists:
|
||||||
|
embed.add_field(
|
||||||
|
name="🔗 Download",
|
||||||
|
value=f"[Download Update]({download_link})",
|
||||||
|
inline=False
|
||||||
|
)
|
||||||
|
|
||||||
# Add status update log
|
# Add status update log
|
||||||
embed.add_field(
|
timestamp_now = int(datetime.utcnow().timestamp())
|
||||||
name=f"📝 Status Updated",
|
update_text = f"{interaction.user.mention} • {old_status} → {new_status_text} • <t:{timestamp_now}:R>"
|
||||||
value=f"{interaction.user.mention} changed status from {old_status} to {new_status_text}",
|
|
||||||
inline=False
|
# Check if update history field exists
|
||||||
)
|
history_exists = False
|
||||||
|
for i, field in enumerate(embed.fields):
|
||||||
|
if "Update History" in field.name or "📝" in field.name:
|
||||||
|
current_history = field.value
|
||||||
|
embed.set_field_at(i, name="📝 Update History", value=f"{current_history}\n{update_text}", inline=False)
|
||||||
|
history_exists = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not history_exists:
|
||||||
|
embed.add_field(
|
||||||
|
name="📝 Update History",
|
||||||
|
value=update_text,
|
||||||
|
inline=False
|
||||||
|
)
|
||||||
|
|
||||||
await message.edit(embed=embed)
|
await message.edit(embed=embed)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user