ADDING autocomplete to ffxiv server selection

This commit is contained in:
Luke Robles 2023-09-29 12:57:13 -07:00
parent 73aeb78b8d
commit 5abddc620e
2 changed files with 33 additions and 7 deletions

View File

@ -10,4 +10,5 @@ RUN apt update && \
rm -rf /var/lib/apt/lists/* /root
COPY --from=0 /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
ADD app /app
RUN mkdir -p /root/.cache/py-finance
CMD python /app/bot.py

View File

@ -1,5 +1,8 @@
from bs4 import BeautifulSoup
from discord import option
from discord.ext import commands
import discord
import requests
class Games(commands.Cog):
@ -21,6 +24,27 @@ class Games(commands.Cog):
except Exception as e:
await ctx.send(e)
async def get_ffxiv_worlds(ctx: discord.AutocompleteContext):
url = "https://na.finalfantasyxiv.com/lodestone/worldstatus/"
# Send an HTTP GET request to the URL
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
# Find all elements with class "world-list__world_name"
world_name_elements = soup.find_all(class_="world-list__world_name")
# Initialize an empty list to store the contents of the elements
worlds = []
# Loop through each element and extract its contents
for element in world_name_elements:
# Extract the text content of the element
element_content = element.get_text(strip=True)
worlds.append(element_content)
return worlds
@commands.slash_command(
guild_ids=None,
name="ffxiv",
@ -29,13 +53,14 @@ class Games(commands.Cog):
@option(
"player_name", description="Your player's first and last name", required=True
)
@option(
"server",
description="Your player's data center",
required=True,
input_type="str",
)
async def ffxiv(self, ctx: commands.Context, player_name: str, server: str):
async def ffxiv(
self,
ctx: commands.Context,
player_name: str,
server: discord.Option(
str, autocomplete=discord.utils.basic_autocomplete(get_ffxiv_worlds)
),
):
import ffxiv
try: