dragon-bot/app/cogs/game_apis.py
Luke Robles 99776dbae6
All checks were successful
Build and push / changes (push) Successful in 13s
Build and push / Lint-Python (push) Successful in 2s
Build and push / Build-and-Push-Docker (push) Successful in 1m13s
Build and push / sync-argocd-app (push) Successful in 3s
Build and push / post-failure-to-discord (push) Has been skipped
Build and push / post-success-to-discord (push) Successful in 1s
Use ruff and conert stock to fstrings
2025-05-07 15:23:32 -07:00

92 lines
2.9 KiB
Python
Executable File

from bs4 import BeautifulSoup
from discord.ext import commands
import discord
import requests
class Games(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot
async def get_ffxiv_worlds(ctx: discord.AutocompleteContext):
url = "https://na.finalfantasyxiv.com/lodestone/worldstatus/"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
# Loop through each element and extract its contents
worlds = [
element.get_text(strip=True)
for element in soup.find_all(class_="world-list__world_name")
]
return worlds
@commands.slash_command(
guild_ids=None,
name="apex",
description="Query the game's API for data about a player",
contexts={
discord.InteractionContextType.guild,
discord.InteractionContextType.bot_dm,
discord.InteractionContextType.private_channel,
},
integration_types={
discord.IntegrationType.guild_install,
discord.IntegrationType.user_install,
},
)
async def apex(self, ctx: discord.ApplicationContext, player):
import apex
try:
await ctx.defer()
embed = apex.get_player(player)
await ctx.send_followup(embed=embed)
except Exception as e:
await ctx.send(e)
# @commands.slash_command(
# guild_ids=None,
# name="ffxiv",
# description="Query the game's API for data about a player",
# )
# @option(
# "player_name", description="Your player's first and last name", required=True
# )
# async def ffxiv(
# self,
# ctx: discord.ApplicationContext,
# player_name: str,
# server: discord.Option(
# str, autocomplete=discord.utils.basic_autocomplete(get_ffxiv_worlds)
# ),
# ):
# import ffxiv
# try:
# embed = ffxiv.make_request(name=player_name.lower(), server=server.lower())
# await ctx.defer()
# await ctx.send_followup(embed=embed)
# except Exception:
# await ctx.send(
# "I encountered an error while searching for that player.\nPlease check that your player name and server are spelled correctly"
# )
# @commands.slash_command(
# guild_ids=None,
# name="2042",
# description="Query Battlefield 2042's API for data about a player",
# )
# @option("player_name", description="Your Origin/EA account name", required=True)
# async def battlefield(self, ctx: discord.ApplicationContext, player_name: str):
# import battlefield
# await ctx.defer()
# embed = battlefield.get_player(player=player_name.lower())
# await ctx.send_followup(embed=embed)
def setup(bot):
bot.add_cog(Games(bot))