281 lines
8.2 KiB
Python
Executable File
281 lines
8.2 KiB
Python
Executable File
from datetime import datetime
|
|
from bs4 import BeautifulSoup
|
|
from discord.ext import commands
|
|
import core_utils
|
|
import discord
|
|
import os
|
|
import random
|
|
import requests
|
|
|
|
import tarkov
|
|
|
|
if os.getenv("DRAGON_ENV") == "prod":
|
|
channel_id = 1097567909640929340
|
|
else:
|
|
channel_id = 932476007439552522
|
|
|
|
|
|
class Tarkov(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot: commands.Bot = bot
|
|
|
|
tarkov = discord.SlashCommandGroup("tarkov", "Tarkov related commands")
|
|
|
|
async def get_all_bosses(ctx: discord.AutocompleteContext):
|
|
"""
|
|
Returns a list of boss names to be used in auto complete
|
|
"""
|
|
|
|
bosses = tarkov.request_wiki("Bosses", "Bosses")
|
|
return bosses
|
|
|
|
@tarkov.command(
|
|
guild_ids=core_utils.my_guilds,
|
|
name="traders",
|
|
description="Time until trader resets",
|
|
)
|
|
async def trader_resets(self, ctx: commands.Context):
|
|
await ctx.defer()
|
|
embed = discord.Embed(
|
|
description="-------", color=discord.Color.blue(), type="rich"
|
|
)
|
|
|
|
embed.set_author(name="PVE Trader Reset Times")
|
|
embed.set_thumbnail(
|
|
url="https://static.wikia.nocookie.net/escapefromtarkov_gamepedia/images/c/cc/NoFleaAugust2024.png/revision/latest/scale-to-width-down/1000?cb=20240813090927"
|
|
)
|
|
|
|
query = """
|
|
{
|
|
traders(gameMode:pve) {
|
|
name
|
|
resetTime
|
|
}
|
|
}
|
|
"""
|
|
|
|
headers = {"Content-Type": "application/json"}
|
|
response = tarkov.query_tarkov_api(query)["traders"]
|
|
|
|
# Loop through the dataset
|
|
for entry in response:
|
|
trader_name = entry["name"]
|
|
if trader_name in ["BTR Driver", "Lightkeeper"]:
|
|
break
|
|
|
|
# Convert to datetime object
|
|
reset_time = datetime.fromisoformat(
|
|
entry["resetTime"].replace("Z", "+00:00")
|
|
)
|
|
|
|
# Print the name and formatted time until reset
|
|
embed.add_field(
|
|
name=trader_name,
|
|
value=discord.utils.format_dt(reset_time, style="R"),
|
|
inline=True,
|
|
)
|
|
await ctx.send_followup(embed=embed)
|
|
|
|
@tarkov.command(
|
|
guild_ids=core_utils.my_guilds,
|
|
name="lottery",
|
|
description="Loadout lottery",
|
|
)
|
|
async def make_loadout(self, ctx: commands.Context):
|
|
weapons = tarkov.request_wiki("Weapons", "Weapons")
|
|
armors = tarkov.request_wiki("Armor_vests", "Armor vests")
|
|
helmet = tarkov.request_wiki("Headwear", "Headwear")
|
|
tarkov.request_wiki("Chest_rigs", "Chest rigs")
|
|
backpacks = tarkov.request_wiki("Backpacks", "Backpacks")
|
|
gun_mods_trader_level = [
|
|
"Use it as it comes from a trader",
|
|
tarkov.allowed_level_roll(),
|
|
]
|
|
tarkov.allowed_level_roll()
|
|
|
|
embed = discord.Embed(
|
|
title="🎲🎰 Loadout Lottery 🎰🎲",
|
|
description="Your loadout sir",
|
|
color=discord.Color.red(),
|
|
type="rich",
|
|
)
|
|
|
|
embed.set_thumbnail(url="https://i.ytimg.com/vi/8He5q7qOzNw/maxresdefault.jpg")
|
|
|
|
embed.add_field(
|
|
name="Armor",
|
|
inline=False,
|
|
value=random.choice(armors),
|
|
)
|
|
# if "plate carrier" in armors.lower():
|
|
# message += f"\nChest rig: {random.choice(chest_rigs)}"
|
|
|
|
# embed.add_field(
|
|
# name="Armor Trader Level",
|
|
# inline=False,
|
|
# value=armor_trader_level,
|
|
# )
|
|
embed.add_field(
|
|
name="Weapon",
|
|
inline=False,
|
|
value=random.choice(weapons),
|
|
)
|
|
|
|
embed.add_field(
|
|
name="Ammo Trader level",
|
|
inline=False,
|
|
value=tarkov.allowed_level_roll()
|
|
+ ", "
|
|
+ f"{str(random.randint(1,5))} magazines",
|
|
)
|
|
|
|
embed.add_field(
|
|
name="Gun mods trader level",
|
|
inline=False,
|
|
value=random.choice(gun_mods_trader_level),
|
|
)
|
|
embed.add_field(
|
|
name="Helmet",
|
|
inline=False,
|
|
value=random.choice(helmet),
|
|
)
|
|
embed.add_field(
|
|
name="Backpack",
|
|
inline=False,
|
|
value=random.choice(backpacks),
|
|
)
|
|
|
|
embed.add_field(name="Ears", inline=False, value=tarkov.allowed_level_roll())
|
|
|
|
embed.add_field(
|
|
name="Throwables", inline=False, value=tarkov.allowed_level_roll()
|
|
)
|
|
|
|
embed.add_field(name="Meds", inline=False, value=tarkov.allowed_level_roll())
|
|
|
|
await ctx.defer()
|
|
await ctx.send_followup(embed=embed)
|
|
|
|
@tarkov.command(
|
|
guild_ids=core_utils.my_guilds,
|
|
name="spawns",
|
|
description="Boss spawn chances per map",
|
|
)
|
|
async def boss_spawns(self, ctx: commands.Context):
|
|
await ctx.defer()
|
|
embed = discord.Embed(
|
|
description="-------", color=discord.Color.blue(), type="rich"
|
|
)
|
|
|
|
embed.set_author(name="Boss Spawn chances by map")
|
|
embed.set_thumbnail(url="https://i.ytimg.com/vi/Yis5rmgo_bM/maxresdefault.jpg")
|
|
|
|
query = """
|
|
{
|
|
maps(lang: en, gameMode: pve) {
|
|
name
|
|
bosses{
|
|
spawnChance
|
|
boss{
|
|
name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
dont_care = [
|
|
"assault",
|
|
"ExUsec",
|
|
"Infected",
|
|
"infectedPmc",
|
|
"BEAR",
|
|
"USEC",
|
|
"Rogue",
|
|
]
|
|
headers = {"Content-Type": "application/json"}
|
|
response = tarkov.query_tarkov_api(query)["maps"]
|
|
|
|
# Wasteful, but make a new dict to hold the info we care about
|
|
levels = {}
|
|
for level in response:
|
|
levels[level["name"]] = {
|
|
boss["boss"]["name"]: boss["spawnChance"]
|
|
for boss in level["bosses"]
|
|
if boss["boss"]["name"] not in dont_care
|
|
}
|
|
|
|
for key, value in levels.items():
|
|
embed.add_field(
|
|
name=key,
|
|
value="\n".join(
|
|
f"{k}: **{str(round(v*100, 2))}%**" for k, v in value.items()
|
|
),
|
|
inline=False,
|
|
)
|
|
embed.set_footer(text=f"Pulled from the api")
|
|
|
|
await ctx.send_followup(embed=embed)
|
|
|
|
@tarkov.command(
|
|
guild_ids=core_utils.my_guilds,
|
|
name="boss",
|
|
description="Boss Info",
|
|
)
|
|
async def boss_info(
|
|
self,
|
|
ctx: commands.Context,
|
|
boss_name: discord.Option(
|
|
str, autocomplete=discord.utils.basic_autocomplete(get_all_bosses)
|
|
),
|
|
):
|
|
await ctx.defer()
|
|
embed = discord.Embed(
|
|
description="-------",
|
|
color=discord.Color.blue(),
|
|
type="rich",
|
|
title=f"Boss info for {boss_name}",
|
|
)
|
|
|
|
wiki_url = "https://escapefromtarkov.fandom.com/wiki/"
|
|
|
|
response = requests.get(wiki_url + boss_name).text
|
|
soup = BeautifulSoup(response, "html.parser")
|
|
|
|
portraits = tarkov.query_tarkov_api(
|
|
"""{
|
|
bosses(lang: en, gameMode:pve) {
|
|
name
|
|
imagePortraitLink
|
|
}
|
|
}"""
|
|
)["bosses"]
|
|
|
|
for boss in portraits:
|
|
if boss["name"] == boss_name:
|
|
embed.set_thumbnail(url=boss["imagePortraitLink"])
|
|
break
|
|
|
|
health = soup.find("table", class_="wikitable").find_next("td").text.rstrip()
|
|
embed.add_field(name="Health", value=health, inline=False)
|
|
|
|
followers = "None"
|
|
if soup.find("span", id="Followers"):
|
|
# Find the amount of followers in the text
|
|
followers = soup.find("span", id="Followers").find_next("p").text
|
|
|
|
embed.add_field(name="Followers", value=followers, inline=False)
|
|
|
|
spawn_chance = "%\n".join(
|
|
soup.find("td", class_="va-infobox-label", string="Spawn chance")
|
|
.find_next("td", class_="va-infobox-content")
|
|
.text.split("%")
|
|
)
|
|
|
|
embed.add_field(name="Spawn Chance", value=f"**{spawn_chance}**", inline=False)
|
|
embed.set_footer(text=f"Pulled from the wiki {wiki_url + boss_name}")
|
|
await ctx.send_followup(embed=embed)
|
|
|
|
|
|
def setup(bot):
|
|
bot.add_cog(Tarkov(bot))
|