rewrite of the paldeck command to make a nice embed
This commit is contained in:
parent
d0736520f6
commit
fe78df580f
@ -1,6 +1,8 @@
|
|||||||
from discord import option
|
from discord import option
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
import discord
|
import discord
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
class PalWorld(commands.Cog):
|
class PalWorld(commands.Cog):
|
||||||
@ -16,22 +18,19 @@ class PalWorld(commands.Cog):
|
|||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
url = "https://game8.co/games/Palworld/archives/439556"
|
all_pals = []
|
||||||
|
|
||||||
|
url = "https://paldex.io/palworld/pals/"
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
|
|
||||||
soup = BeautifulSoup(response.text, "html.parser")
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
|
|
||||||
all_pals = []
|
x = soup.find_all(
|
||||||
|
"p",
|
||||||
table = soup.find("table", class_="a-table a-table a-table flexible-cell")
|
class_="text-base lg:text-lg group-hover:underline underline-offset-4 text-center",
|
||||||
if table:
|
)
|
||||||
rows = table.find_all("tr")
|
for pal in x:
|
||||||
for row in rows:
|
all_pals.append(pal.text)
|
||||||
first_a = row.find("a")
|
|
||||||
if first_a:
|
|
||||||
all_pals.append(first_a.text.strip())
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return all_pals
|
return all_pals
|
||||||
|
|
||||||
@ -49,7 +48,80 @@ class PalWorld(commands.Cog):
|
|||||||
description="Pal to look up",
|
description="Pal to look up",
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
await ctx.respond("https://palpedia.net/pals/%s" % pal.replace(" ", "+"))
|
pal_url = "https://paldex.io/palworld/pals/%s/" % pal.lower()
|
||||||
|
response = requests.get(pal_url)
|
||||||
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
|
|
||||||
|
color_lookup = {"Fire": discord.Color.red()}
|
||||||
|
|
||||||
|
pal_element_badge = soup.find("img", class_="rounded-full w-12 px-2 py-2")
|
||||||
|
element_text = pal_element_badge.find_next("p").text
|
||||||
|
element_icon = "https://paldex.io" + pal_element_badge["src"]
|
||||||
|
|
||||||
|
embed = discord.Embed(
|
||||||
|
description="-------",
|
||||||
|
color=discord.Color.blue(),
|
||||||
|
type="rich",
|
||||||
|
title=pal,
|
||||||
|
)
|
||||||
|
|
||||||
|
embed.set_author(
|
||||||
|
name=element_text,
|
||||||
|
icon_url=element_icon,
|
||||||
|
url=pal_url,
|
||||||
|
)
|
||||||
|
|
||||||
|
embed.set_thumbnail(
|
||||||
|
url=soup.find(
|
||||||
|
"img", class_="rounded-full w-32 sm:w-auto border-2 border-amber-500"
|
||||||
|
)["src"]
|
||||||
|
)
|
||||||
|
|
||||||
|
pal_description = soup.find("h3", class_="text-lg mt-2 text-slate-300").text
|
||||||
|
embed.add_field(name="**Description**", value=pal_description, inline=False)
|
||||||
|
|
||||||
|
embed.add_field(name="Work Skills", value="-----", inline=False)
|
||||||
|
|
||||||
|
# work skills
|
||||||
|
skills_emojis = {
|
||||||
|
"Kindling": "🔥",
|
||||||
|
"Watering": "💦",
|
||||||
|
"Planting": "🌱",
|
||||||
|
"Generating Electricity": "⚡️",
|
||||||
|
"Handwork": "🤚",
|
||||||
|
"Gathering": "🍃",
|
||||||
|
"Lumbering": "🪵",
|
||||||
|
"Mining": "⛏️",
|
||||||
|
"Medicine Production": "💉",
|
||||||
|
"Cooling": "❄️",
|
||||||
|
"Transporting": "📦",
|
||||||
|
"Farming": "🚜",
|
||||||
|
}
|
||||||
|
|
||||||
|
specialties = soup.find("div", class_="grid grid-cols-2 grid-rows-6 gap-2")
|
||||||
|
for work_skill in specialties.find_all(
|
||||||
|
"div",
|
||||||
|
class_="inline-flex flex-row gap-1 items-center bg-black-300 border border-amber-300 break-all",
|
||||||
|
):
|
||||||
|
skill_name = work_skill.text.split("Lv")[0]
|
||||||
|
skill_level = work_skill.text.split("Lv")[1]
|
||||||
|
|
||||||
|
embed.add_field(
|
||||||
|
name=skills_emojis[skill_name] + " " + skill_name,
|
||||||
|
value="%s" % (int(skill_level) * "⭐️"),
|
||||||
|
inline=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Drops
|
||||||
|
embed.add_field(name="Drops", value="-----", inline=False)
|
||||||
|
for div in soup.find("div", class_="flex flex-col gap-2"):
|
||||||
|
embed.add_field(
|
||||||
|
name=div.text.split("(")[0],
|
||||||
|
value="",
|
||||||
|
inline=False,
|
||||||
|
)
|
||||||
|
await ctx.defer()
|
||||||
|
await ctx.send_followup(embed=embed)
|
||||||
|
|
||||||
@palworld.command(
|
@palworld.command(
|
||||||
guild_ids=None,
|
guild_ids=None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user