modified: bot.py

This commit is contained in:
SimolZimol
2026-01-09 21:37:09 +01:00
parent cd64b5f1ee
commit d67453654a

61
bot.py
View File

@@ -86,9 +86,59 @@ def load_server_settings(guild_id):
conn.close() conn.close()
return result return result
# Ticket storage (in production, use a database) def get_next_ticket_id():
tickets = {} """Generate the next ticket ID based on existing tickets in database"""
ticket_counter = 1 conn = get_db_connection()
cursor = conn.cursor()
cursor.execute('SELECT COUNT(*) as count FROM tickets')
result = cursor.fetchone()
cursor.close()
conn.close()
count = result[0] if result else 0
return f"TICKET-{count + 1:04d}"
def save_ticket(ticket_id, ticket):
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute('''
REPLACE INTO tickets (ticket_id, message_id, channel_id, title, project, status, creator, created_at, reference_message_id, archived)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
''', (
ticket_id,
ticket['message_id'],
ticket['channel_id'],
ticket['title'],
ticket['project'],
ticket['status'],
ticket['creator'],
ticket['created_at'],
ticket.get('reference_message_id'),
ticket.get('archived', False)
))
conn.commit()
cursor.close()
conn.close()
def load_ticket(ticket_id):
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
cursor.execute('SELECT * FROM tickets WHERE ticket_id = %s', (ticket_id,))
result = cursor.fetchone()
cursor.close()
conn.close()
return result
def load_all_tickets(archived=None):
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
if archived is None:
cursor.execute('SELECT * FROM tickets')
else:
cursor.execute('SELECT * FROM tickets WHERE archived = %s', (archived,))
results = cursor.fetchall()
cursor.close()
conn.close()
return results
# Project cache for autocomplete # Project cache for autocomplete
project_cache = [] project_cache = []
@@ -201,9 +251,8 @@ async def create_ticket(
) )
return return
# Create ticket ID # Create ticket ID from database
ticket_id = f"TICKET-{ticket_counter:04d}" ticket_id = get_next_ticket_id()
ticket_counter += 1
# Create embed for the ticket # Create embed for the ticket
embed = discord.Embed( embed = discord.Embed(