67 lines
1.9 KiB
Python
Executable File
67 lines
1.9 KiB
Python
Executable File
from discord import option
|
|
from discord.ext import commands, tasks
|
|
import discord
|
|
|
|
|
|
class PalWorld(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot: commands.Bot = bot
|
|
|
|
palworld = discord.SlashCommandGroup("palworld", "Palworld related commands")
|
|
|
|
async def get_all_pals(ctx: discord.AutocompleteContext):
|
|
"""
|
|
returns a list of all pals in the game, which can then be passed to the /ship command for auto complete
|
|
"""
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
|
|
url = "https://game8.co/games/Palworld/archives/439556"
|
|
response = requests.get(url)
|
|
|
|
soup = BeautifulSoup(response.text, "html.parser")
|
|
|
|
all_pals = []
|
|
|
|
table = soup.find("table", class_="a-table a-table a-table flexible-cell")
|
|
if table:
|
|
rows = table.find_all("tr")
|
|
for row in rows:
|
|
first_a = row.find("a")
|
|
if first_a:
|
|
all_pals.append(first_a.text.strip())
|
|
else:
|
|
pass
|
|
|
|
return all_pals
|
|
|
|
@palworld.command(
|
|
guild_ids=None,
|
|
name="paldeck",
|
|
description="Looks up data about a pal",
|
|
)
|
|
async def pal_lookup(
|
|
self,
|
|
ctx: commands.Context,
|
|
pal: discord.Option(
|
|
str,
|
|
autocomplete=discord.utils.basic_autocomplete(get_all_pals),
|
|
description="Pal to look up",
|
|
),
|
|
):
|
|
await ctx.respond("https://palpedia.net/pals/%s" % pal.replace(" ", "+"))
|
|
|
|
@palworld.command(
|
|
guild_ids=None,
|
|
name="elements",
|
|
description="Posts an infographic about which Pal elements are weak/strong against which",
|
|
)
|
|
async def post_medpen_guide(self, ctx: commands.Context):
|
|
await ctx.respond(
|
|
"https://img.game8.co/3822502/5ae8382d16bd390dd19f343e87680d51.png/show"
|
|
)
|
|
|
|
|
|
def setup(bot):
|
|
bot.add_cog(PalWorld(bot))
|