Spaces:
Paused
Paused
Update sportbet.py
Browse files- sportbet.py +31 -29
sportbet.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import discord
|
|
|
|
| 2 |
from discord import app_commands
|
| 3 |
import aiohttp
|
| 4 |
import asyncio
|
|
@@ -7,7 +8,7 @@ from cash import user_cash # Ensure you have a 'cash.py' module managing user_c
|
|
| 7 |
|
| 8 |
user_bets = {}
|
| 9 |
|
| 10 |
-
API_KEY = "jE7yBJVRNAwdDesMgTzTXUUSx1It41Fq"
|
| 11 |
|
| 12 |
async def fetch_nhl_scores():
|
| 13 |
today = datetime.now().strftime('%Y%m%d')
|
|
@@ -18,7 +19,7 @@ async def fetch_nhl_scores():
|
|
| 18 |
|
| 19 |
async def fetch_nfl_scores():
|
| 20 |
current_year = datetime.now().year
|
| 21 |
-
# Start by fetching
|
| 22 |
url = f"https://api.foxsports.com/bifrost/v1/nfl/scoreboard/segment/{current_year}-1-1?apikey={API_KEY}"
|
| 23 |
async with aiohttp.ClientSession() as session:
|
| 24 |
async with session.get(url) as response:
|
|
@@ -37,6 +38,11 @@ async def fetch_nfl_scores():
|
|
| 37 |
return data_current_week
|
| 38 |
return None # If no current week is found
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
class SportSelect(discord.ui.Select):
|
| 41 |
def __init__(self):
|
| 42 |
options = [
|
|
@@ -267,7 +273,7 @@ async def show_current_bets(interaction: discord.Interaction):
|
|
| 267 |
game_description = f"{game['lowerTeam']['longName']} vs {game['upperTeam']['longName']}"
|
| 268 |
start_time = game['eventTime']
|
| 269 |
score = f"{game['lowerTeam'].get('score', 'N/A')} - {game['upperTeam'].get('score', 'N/A')}"
|
| 270 |
-
status = "Final" if game.get('
|
| 271 |
|
| 272 |
embed.add_field(
|
| 273 |
name=f"Bet {i}: {league}",
|
|
@@ -283,40 +289,36 @@ async def show_current_bets(interaction: discord.Interaction):
|
|
| 283 |
)
|
| 284 |
|
| 285 |
view = discord.ui.View()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
cancel_select = discord.ui.Select(
|
| 287 |
placeholder="Select a bet to cancel",
|
| 288 |
min_values=1,
|
| 289 |
max_values=1,
|
| 290 |
-
options=
|
| 291 |
-
discord.SelectOption(label=f"Bet {i}", value=str(i-1)) for i in range(1, len(user_bets[user_id]) + 1)
|
| 292 |
-
]
|
| 293 |
)
|
| 294 |
-
view.add_item(cancel_select)
|
| 295 |
|
| 296 |
-
async def cancel_callback(
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
start_time = datetime.fromisoformat(cancelled_bet['game_data']['eventTime'].replace('Z', '+00:00'))
|
| 304 |
-
|
| 305 |
-
if datetime.now(timezone.utc) >= start_time:
|
| 306 |
-
await interaction_cancel.response.send_message("You cannot cancel your bet as the game has already started.", ephemeral=False)
|
| 307 |
-
return
|
| 308 |
-
|
| 309 |
-
user_cash[user_id] += cancelled_bet['amount']
|
| 310 |
-
user_bets[user_id].pop(bet_index)
|
| 311 |
-
await interaction_cancel.response.send_message(f"Bet cancelled. **${cancelled_bet['amount']}** has been refunded.", ephemeral=False)
|
| 312 |
-
if not user_bets[user_id]:
|
| 313 |
-
del user_bets[user_id]
|
| 314 |
|
| 315 |
cancel_select.callback = cancel_callback
|
|
|
|
| 316 |
|
| 317 |
await interaction.response.send_message(embed=embed, view=view, ephemeral=False)
|
| 318 |
|
| 319 |
-
@
|
| 320 |
-
async def
|
| 321 |
-
view
|
| 322 |
-
await interaction.response.send_message("Select a sport to bet on:", view=view, ephemeral=False)
|
|
|
|
| 1 |
import discord
|
| 2 |
+
from discord.ext import commands
|
| 3 |
from discord import app_commands
|
| 4 |
import aiohttp
|
| 5 |
import asyncio
|
|
|
|
| 8 |
|
| 9 |
user_bets = {}
|
| 10 |
|
| 11 |
+
API_KEY = "jE7yBJVRNAwdDesMgTzTXUUSx1It41Fq" # Replace with your actual API key
|
| 12 |
|
| 13 |
async def fetch_nhl_scores():
|
| 14 |
today = datetime.now().strftime('%Y%m%d')
|
|
|
|
| 19 |
|
| 20 |
async def fetch_nfl_scores():
|
| 21 |
current_year = datetime.now().year
|
| 22 |
+
# Start by fetching data to get quickNav
|
| 23 |
url = f"https://api.foxsports.com/bifrost/v1/nfl/scoreboard/segment/{current_year}-1-1?apikey={API_KEY}"
|
| 24 |
async with aiohttp.ClientSession() as session:
|
| 25 |
async with session.get(url) as response:
|
|
|
|
| 38 |
return data_current_week
|
| 39 |
return None # If no current week is found
|
| 40 |
|
| 41 |
+
intents = discord.Intents.default()
|
| 42 |
+
intents.message_content = True # Required for receiving message content
|
| 43 |
+
|
| 44 |
+
bot = commands.Bot(command_prefix='!', intents=intents)
|
| 45 |
+
|
| 46 |
class SportSelect(discord.ui.Select):
|
| 47 |
def __init__(self):
|
| 48 |
options = [
|
|
|
|
| 273 |
game_description = f"{game['lowerTeam']['longName']} vs {game['upperTeam']['longName']}"
|
| 274 |
start_time = game['eventTime']
|
| 275 |
score = f"{game['lowerTeam'].get('score', 'N/A')} - {game['upperTeam'].get('score', 'N/A')}"
|
| 276 |
+
status = "Final" if game.get('eventStatus') == 3 else f"Starts <t:{int(datetime.fromisoformat(start_time.replace('Z', '+00:00')).timestamp())}:R>"
|
| 277 |
|
| 278 |
embed.add_field(
|
| 279 |
name=f"Bet {i}: {league}",
|
|
|
|
| 289 |
)
|
| 290 |
|
| 291 |
view = discord.ui.View()
|
| 292 |
+
|
| 293 |
+
cancel_options = [
|
| 294 |
+
discord.SelectOption(
|
| 295 |
+
label=f"Bet {i}",
|
| 296 |
+
value=str(i-1),
|
| 297 |
+
description=f"{bet['league']} - {bet['team']} vs {bet['game_data']['lowerTeam']['longName']} vs {bet['game_data']['upperTeam']['longName']}"
|
| 298 |
+
)
|
| 299 |
+
for i, bet in enumerate(user_bets[user_id], 1)
|
| 300 |
+
]
|
| 301 |
+
|
| 302 |
cancel_select = discord.ui.Select(
|
| 303 |
placeholder="Select a bet to cancel",
|
| 304 |
min_values=1,
|
| 305 |
max_values=1,
|
| 306 |
+
options=cancel_options
|
|
|
|
|
|
|
| 307 |
)
|
|
|
|
| 308 |
|
| 309 |
+
async def cancel_callback(interaction: discord.Interaction):
|
| 310 |
+
index = int(cancel_select.values[0])
|
| 311 |
+
bet = user_bets[user_id][index]
|
| 312 |
+
refund_amount = bet['amount']
|
| 313 |
+
user_cash[user_id] += refund_amount
|
| 314 |
+
del user_bets[user_id][index]
|
| 315 |
+
await interaction.response.send_message(f"Bet on **{bet['team']}** has been canceled. **${refund_amount}** has been refunded to your account.", ephemeral=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
cancel_select.callback = cancel_callback
|
| 318 |
+
view.add_item(cancel_select)
|
| 319 |
|
| 320 |
await interaction.response.send_message(embed=embed, view=view, ephemeral=False)
|
| 321 |
|
| 322 |
+
@bot.tree.command(name="sportbet")
|
| 323 |
+
async def bet(interaction: discord.Interaction):
|
| 324 |
+
await interaction.response.send_message("Choose a sport to bet on:", view=SportBetView(), ephemeral=False)
|
|
|