def get_team_data_from_database(team_name):
conn = sqlite3.connect('database.sqlite') # Replace with your database name
cursor = conn.cursor()
query = "SELECT * FROM Team WHERE team_long_name = ?"
cursor.execute(query, (team_name,))
team_data = cursor.fetchone()
conn.close()
return team_data
def get_match_data_from_database(match_id):
conn = sqlite3.connect('database.sqlite') # Replace with your database name
cursor = conn.cursor()
query = "SELECT * FROM Match WHERE match_id = ?" # Adjust this query based on your table structure
cursor.execute(query, (match_id,))
match_data = cursor.fetchone()
conn.close()
return match_data
def get_list_of_teams_from_database():
conn = sqlite3.connect('database.sqlite') # Replace with your database name
cursor = conn.cursor()
# Execute a SELECT query to fetch the list of available teams
query = "SELECT DISTINCT team_long_name FROM Team" # Replace with your table name
cursor.execute(query)
teams = cursor.fetchall()
conn.close()
return [team[0] for team in teams]
def get_table_columns(table_name):
conn = sqlite3.connect('database.sqlite') # Replace with your database name
cursor = conn.cursor()
# Query to get table columns
query = f"PRAGMA table_info({table_name})"
cursor.execute(query)
columns = [row[1] for row in cursor.fetchall()]
conn.close()
return columns
def get_all_tables_in_database():
conn = sqlite3.connect('database.sqlite') # Replace with your database name
cursor = conn.cursor()
# Query to get all table names
query = "SELECT name FROM sqlite_master WHERE type='table'"
cursor.execute(query)
table_names = [row[0] for row in cursor.fetchall()]
tables_with_columns = {}
for table_name in table_names:
columns = get_table_columns(table_name)
tables_with_columns[table_name] = columns
conn.close()
return tables_with_columns
@client.command(name="list_tables")
async def list_tables(ctx):
tables_with_columns = get_all_tables_in_database()
response = "List of tables and their columns:\n"
for table_name, columns in tables_with_columns.items():
columns_str = ", ".join(columns)
table_info = f"Table: {table_name}\nColumns: {columns_str}\n\n"
# Check if adding the current table info would exceed the message limit
if len(response) + len(table_info) > 2000:
# If yes, send the current response and start a new response
await ctx.send(response)
response = ""
response += table_info
# Send any remaining response
if response:
await ctx.send(response)
@client.command(name="list_teams")
async def list_teams(ctx):
# Retrieve the list of available teams from your database
teams = get_list_of_teams_from_database() # Implement this function
team_list = "\n".join(teams)
embed = discord.Embed(title="Available Teams", description=team_list, color=discord.Color.blue())
await ctx.send(embed=embed)
@client.command(name="predict_match")
async def predict_match(ctx, team1, team2):
try:
# Retrieve the list of available teams from your database
available_teams = get_list_of_teams_from_database() # Implement this function
# Convert the provided team names to lowercase and remove extra spaces
team1 = team1.lower().strip()
team2 = team2.lower().strip()
# Convert each team name in the list to lowercase for case-insensitive comparison
available_teams_lower = [team.lower() for team in available_teams]
print("Available Teams:", available_teams)
print("Provided Team Names:", team1, team2)
# Check if both teams are available in a case-insensitive manner
if team1 in available_teams_lower and team2 in available_teams_lower:
# Fetch data for the selected teams from the database
team1_data = get_team_data_from_database(team1)
team2_data = get_team_data_from_database(team2)
if team1_data and team2_data:
# Call the predictive model function for match outcome
prediction = predict_match_outcome(team1_data, team2_data)
# Send the prediction result back to the Discord channel
await ctx.send(f"The predicted match outcome between {team1} and {team2} is: {prediction}")
else:
await ctx.send("Error retrieving team data from the database.")
else:
await ctx.send("One or both of the specified teams are not available.")
except Exception as e:
print("An error occurred during prediction:", e)
await ctx.send("An error occurred during prediction.")