dragon-bot/app/tarkov.py

106 lines
2.8 KiB
Python
Executable File

from bs4 import BeautifulSoup
import requests
import random
def request_wiki(url, heading):
response = requests.get(
"https://escapefromtarkov.fandom.com/wiki/Category:" + url, timeout=25
).text
soup = BeautifulSoup(response, "html.parser")
h2_heading = soup.find("h2", string=f'Pages in category "{heading}"')
return [link.text for link in h2_heading.find_next("div").find_all("a")]
def allowed_level_roll():
message = "None"
allowed = random.randint(0, 1) == 1
if allowed:
message = "Allowed"
message += ", Trader level: " + random.choice(
[str(random.randint(1, 4)), "Any level"]
)
return message
def query_tarkov_api(query):
headers = {"Content-Type": "application/json"}
return requests.post(
"https://api.tarkov.dev/graphql", headers=headers, json={"query": query}
).json()["data"]
def tarkov_boss_info():
"""
Returns a dict of boss spawn chances per map, and their escorts
"""
query = """{
maps {
name
bosses {
name
spawnChance
escorts {
boss {
name
}
amount {
count
}
}
boss {
name
imagePortraitLink
}
}
}
}"""
dont_care = [
"assault",
"Infected",
"BEAR",
"USEC",
"Rogue",
]
response = 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"]: {
"escorts": sum(
escort["amount"][0]["count"] for escort in boss["escorts"]
),
"spawnChance": f"**{str(round(boss['spawnChance'] * 100, 2))}%**",
"picture": boss["boss"]["imagePortraitLink"],
}
for boss in level["bosses"]
if boss["boss"]["name"] not in dont_care
}
return levels
def compare_boss_spawns(dict1, dict2):
changes = {} # To store the changes
for level in dict1:
level_changes = {} # Store changes for each level
for boss in dict1.get(level, {}):
boss_info_1 = dict1[level].get(boss, {})
boss_info_2 = dict2[level].get(boss, {})
spawnChance_1 = boss_info_1.get("spawnChance", "N/A")
spawnChance_2 = boss_info_2.get("spawnChance", "N/A")
if spawnChance_1 != spawnChance_2:
level_changes[boss] = f"{spawnChance_1} -> {spawnChance_2}"
if level_changes:
changes[level] = level_changes
return changes