139 lines
4.2 KiB
Python
Executable File
139 lines
4.2 KiB
Python
Executable File
from discord import option
|
|
from discord.ext import commands, tasks
|
|
import discord
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
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
|
|
|
|
all_pals = []
|
|
|
|
url = "https://paldex.io/palworld/pals/"
|
|
response = requests.get(url)
|
|
|
|
soup = BeautifulSoup(response.text, "html.parser")
|
|
|
|
x = soup.find_all(
|
|
"p",
|
|
class_="text-base lg:text-lg group-hover:underline underline-offset-4 text-center",
|
|
)
|
|
for pal in x:
|
|
all_pals.append(pal.text)
|
|
|
|
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",
|
|
),
|
|
):
|
|
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(
|
|
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))
|