-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
76 lines (54 loc) · 2.42 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import discord
from discord import app_commands
from discord.ext import commands
from settings import *
from get_data import *
from embeds import *
intents = discord.Intents.default()
bot = commands.Bot(command_prefix="!livescores", intents=intents)
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}, bot is in {len(bot.guilds)} guilds.")
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} command(s)")
except Exception as e:
print(f"Failed to sync commands: {e}")
@bot.tree.command(name="team", description="Gets score data for a team")
@app_commands.describe(
team_id = "Team ID",
data_source = "Data Source"
)
async def team_command(interaction: discord.Interaction, team_id: str, data_source: str = "live scoreboard"):
await interaction.response.defer(ephemeral=False, thinking=True)
data = get_data(team_id, data_source)
if data['error']:
embed = make_error_embed("Error fetching data", data["error"])
else:
embed = make_team_embed(data, data_source)
await interaction.followup.send(embed=embed, ephemeral=False)
@bot.tree.command(name="leaderboard", description="Gets leaderboard data")
@app_commands.describe(
page = "Scoreboard page",
division = "Division",
location = "Location",
tier = "Tier",
per_page = "Teams per page",
data_source = "Data Source",
highlight_teams = "Team IDs to highlight (space separated)"
)
async def leaderboard_command(interaction: discord.Interaction, page: int = 1, division: str = "all", location: str = "all", tier: str = "all", per_page: int = 15, highlight_teams: str = "", data_source: str = "live scoreboard"):
await interaction.response.defer(ephemeral=False, thinking=True)
data = get_all_team_data(data_source)
if data['error']:
embed = make_error_embed("Error fetching data", data["error"])
else:
embed = make_leaderboard_embed(data, data_source, division, location, tier, page, per_page, highlight_teams)
await interaction.followup.send(embed=embed, ephemeral=False)
@bot.tree.command(name="datasources", description="Show all data sources")
async def datasources_command(interaction: discord.Interaction):
datasources = get_setting("valid_data_sources")
embed = make_datasources_embed(datasources)
await interaction.response.send_message(embed=embed, ephemeral=True)
def start_bot():
bot.run(get_setting("discord_secret"))