use paldex.gg for pal info
All checks were successful
Build and push / changes (push) Successful in 4s
Build and push / Lint-Python (push) Successful in 2s
Build and push / Build-and-Push-Docker (push) Successful in 20s
Build and push / sync-argocd-app (push) Successful in 2s
Build and push / post-status-to-discord (push) Successful in 5s

This commit is contained in:
Luke Robles 2025-03-21 18:46:16 -07:00
parent 0dfadb5429
commit 7a6bfb64a7

View File

@ -21,21 +21,22 @@ class PalWorld(commands.Cog):
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
all_pals = [] url = "https://palworld.gg/pals"
response = requests.get(url).text
soup = BeautifulSoup(response, "html.parser")
url = "https://paldex.io/palworld/pals/" pal_list = []
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser") all_pals = soup.find_all("div", class_="pal")
try:
for pal in all_pals:
name = pal.find("div", class_="name").text.split("#", 1)[0].strip()
x = soup.find_all( pal_list.append(name)
"p", except:
class_="text-base lg:text-lg group-hover:underline underline-offset-4 text-center", pass
)
for pal in x:
all_pals.append(pal.text)
return sorted(set(all_pals)) return pal_list
@palworld.command( @palworld.command(
guild_ids=None, guild_ids=None,
@ -60,17 +61,16 @@ class PalWorld(commands.Cog):
description="Pal to look up", description="Pal to look up",
), ),
): ):
pal_url = "https://paldex.io/palworld/pals/%s/" % pal.lower().replace(" ", "-") pal_url = f"https://palworld.gg/pal/{pal.lower().replace(' ', '-')}"
response = requests.get(pal_url) response = requests.get(pal_url)
soup = BeautifulSoup(response.text, "html.parser") soup = BeautifulSoup(response.text, "html.parser")
elements = {} elements = {}
# Get the pal's primary element
pal_elements_div = soup.find("div", class_="elements")
pal_elements = soup.find("div", class_="flex flex-row flex-wrap gap-3") element_icon = "https://palworld.gg" + pal_elements_div.find("img")["src"]
for div in pal_elements: element_type = pal_elements_div.text
pal_element_badge = div.find("img", class_="rounded-full w-8 h-8 m-2")
element_type = pal_element_badge.find_next("p").text
element_icon = pal_element_badge["src"]
elements[element_type] = element_icon elements[element_type] = element_icon
primary_element = list(elements.keys())[0] primary_element = list(elements.keys())[0]
@ -84,7 +84,7 @@ class PalWorld(commands.Cog):
"Fire": discord.Color.red(), "Fire": discord.Color.red(),
"Leaf": discord.Color.green(), "Leaf": discord.Color.green(),
"Ice": discord.Color.blue(), "Ice": discord.Color.blue(),
"Normal": discord.Color.lighter_grey(), "Neutral": discord.Color.lighter_grey(),
"Water": discord.Color.dark_blue(), "Water": discord.Color.dark_blue(),
} }
@ -102,10 +102,8 @@ class PalWorld(commands.Cog):
) )
embed.set_thumbnail( embed.set_thumbnail(
url=soup.find( url="https://palworld.gg"
"img", + soup.find("div", class_="image").find_next("img")["src"]
class_="rounded-full w-32 h-32 border-2 border-amber-500 aspect-square",
)["src"]
) )
# embed.add_field(name="Work Skills", value="-----", inline=False) # embed.add_field(name="Work Skills", value="-----", inline=False)
@ -115,9 +113,9 @@ class PalWorld(commands.Cog):
"Farming": "🚜", "Farming": "🚜",
"Gathering": "🍃", "Gathering": "🍃",
"Generating Electricity": "⚡️", "Generating Electricity": "⚡️",
"Handwork": "🤚", "Handiwork": "🤚",
"Kindling": "🔥", "Kindling": "🔥",
"Lumbering": "🪵", "Deforesting": "🪵",
"Medicine Production": "💉", "Medicine Production": "💉",
"Mining": "⛏️", "Mining": "⛏️",
"Planting": "🌱", "Planting": "🌱",
@ -125,15 +123,14 @@ class PalWorld(commands.Cog):
"Watering": "💦", "Watering": "💦",
} }
skill_table = soup.find("div", class_="flex flex-col gap-2") work_suit = (
for div in skill_table.find_all( soup.find("h2", string="Work Suitability")
"div", class_=re.compile(".*border-amber-300\s+break-all") .find_next("div", class_="items")
): .find_all("div", class_="active item")
skill_name = div.find("p", class_="text-base sm:text-lg").text )
skill_level = div.find(
"p", class_="text-base sm:text-lg mr-2 md:mr-4"
).text.split("Lv")[-1]
for skill in work_suit:
skill_name, skill_level = skill.text.split("Lv")
embed.add_field( embed.add_field(
name=skills_emojis[skill_name] + " " + skill_name, name=skills_emojis[skill_name] + " " + skill_name,
value="%s" % (int(skill_level) * "⭐️"), value="%s" % (int(skill_level) * "⭐️"),
@ -142,27 +139,28 @@ class PalWorld(commands.Cog):
# Partner Skill # Partner Skill
embed.add_field(name="Partner Skill", value="-----", inline=False) embed.add_field(name="Partner Skill", value="-----", inline=False)
skill_name = soup.find("h2", string="Partner Skill").find_next( skill = soup.find("div", class_="passive skills")
"p", class_=re.compile(".*text-xl.*") skill_name = skill.find_next("div", class_="name").text
) skill_description = skill.find_next("p").text
skill_description = skill_name.find_next("p", class_="text-lg mr-4").text
embed.add_field( embed.add_field(
name=skill_name.text, name=skill_name,
value=skill_description, value=skill_description,
inline=False, inline=False,
) )
# Drops # Drops
embed.add_field(name="Drops", value="-----", inline=False) embed.add_field(name="Drops", value="-----", inline=False)
for div in soup.find_all( drops = [
"div", x.text
class_="inline-flex flex-col gap-1 items-center bg-black-300 border border-amber-300 break-all p-2", for x in soup.find("h2", string="Possible Drops")
): .find_next("table")
item = div.text .find_all("div", class_="name")
item_name = item.split("Quantity")[0].split("Drop Chance") ]
amount = item.split("Quantity")[-1].split("Drop Chance")
for item in drops:
embed.add_field( embed.add_field(
name=" ".join(item_name), name=item,
value="", value="",
inline=False, inline=False,
) )