modified: bot.py
This commit is contained in:
61
bot.py
61
bot.py
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user