Skip to content

Commit

Permalink
Merge pull request #77 from RotorJackets/TrackAndUrl
Browse files Browse the repository at this point in the history
Track and url
  • Loading branch information
Ian-Boraks authored Aug 12, 2023
2 parents e967be5 + 04d92a4 commit ef54660
Showing 1 changed file with 62 additions and 7 deletions.
69 changes: 62 additions & 7 deletions cogs/velocidrone/velocidrone.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,19 @@ async def on_ready(self):
async def leaderboard(
self,
interaction: discord.Interaction,
track_id: int,
leaderboard_url: str = None,
track_id: int = None,
):
if leaderboard_url is None and track_id is None:
await interaction.response.send_message(
f"You must provide either a leaderboard url or a track id",
ephemeral=True,
)
return

if leaderboard_url is not None:
track_id = int(leaderboard_url.split("/")[-2])

json_data = velocidrone_helper.get_leaderboard(
interaction.guild.id,
f"https://www.velocidrone.com/leaderboard_as_json2/{0}/{6}/{track_id}/{1.16}",
Expand Down Expand Up @@ -155,14 +166,23 @@ async def remove_whitelist(

@app_commands.command(
name="add_track",
description="Adds to the velocidrone tracks",
description="Adds to the velocidrone tracks. Use either the leaderboard url or the track id.",
)
async def add_track(
self,
interaction: discord.Interaction,
leaderboard_url: str,
leaderboard_url: str = None,
track_id: int = None,
):
track_id = int(leaderboard_url.split("/")[-2])
if leaderboard_url is None and track_id is None:
await interaction.response.send_message(
f"You must provide either a leaderboard url or a track id",
ephemeral=True,
)
return

if leaderboard_url is not None:
track_id = int(leaderboard_url.split("/")[-2])

role = get(interaction.guild.roles, name=config["velocidrone_edit_role"])

Expand Down Expand Up @@ -200,13 +220,24 @@ async def add_track(

@app_commands.command(
name="remove_track",
description="Removes to the velocidrone tracks",
description="Removes to the velocidrone tracks. Use either the leaderboard url or the track id.",
)
async def remove_track(
self,
interaction: discord.Interaction,
track_id: int,
leaderboard_url: str = None,
track_id: int = None,
):
if leaderboard_url is None and track_id is None:
await interaction.response.send_message(
f"You must provide either a leaderboard url or a track id",
ephemeral=True,
)
return

if leaderboard_url is not None:
track_id = int(leaderboard_url.split("/")[-2])

role = get(interaction.guild.roles, name=config["velocidrone_edit_role"])
if role not in interaction.user.roles:
await interaction.response.send_message(
Expand Down Expand Up @@ -235,7 +266,7 @@ async def remove_track(
return
else:
await message.edit(
content=f"Removed **{track}** from the Velocidrone track_id",
content=f"Removed **{track}** from the Velocidrone track list",
)
elif view.remove is False:
await message.edit(
Expand Down Expand Up @@ -386,6 +417,30 @@ async def reset_velocidrone(
tracks: bool = False,
):
# TODO: MAKE THE REMOVAL BOYS
view = Removal()
await interaction.response.send_message(
content=f"Are you sure you want to reset Velocidrone?",
view=view,
)

message = await interaction.original_response()
view.message = message
timeout = await view.wait()

if timeout is True:
await message.edit(content=f"Timed out")
elif view.remove is True:
velocidrone_helper.reset_velocidrone(
interaction.guild.id, whitelist, tracks
)
await message.edit(
content=f"Reset Velocidrone.",
)
elif view.remove is False:
await message.edit(
content="Cancelled",
)

velocidrone_helper.reset_velocidrone(interaction.guild.id, whitelist, tracks)

await interaction.response.send_message(
Expand Down

0 comments on commit ef54660

Please sign in to comment.