dragon-bot/app/cogs/tarkov.py
Luke Robles 39f0f7091a
Some checks failed
Build and push / changes (push) Successful in 6s
Build and push / Lint-Python (push) Failing after 10s
Build and push / Build-and-Push-Docker (push) Has been skipped
Build and push / sync-argocd-app (push) Has been skipped
ruff to fix unused imports
2024-10-17 19:19:25 -07:00

173 lines
5.1 KiB
Python
Executable File

from discord.ext import commands
import core_utils
import discord
import os
import random
import tarkov
if os.getenv("DRAGON_ENV") == "prod":
channel_id = 1097567909640929340
else:
channel_id = 932476007439552522
def format_timedelta(td):
total_seconds = int(td.total_seconds())
hours, remainder = divmod(total_seconds, 3600) # 3600 seconds in an hour
minutes, seconds = divmod(remainder, 60) # 60 seconds in a minute
return f"{hours}h {minutes}m {seconds}s"
class Tarkov(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot
tarkov = discord.SlashCommandGroup("tarkov", "Tarkov related commands")
@tarkov.command(
guild_ids=core_utils.my_guilds,
name="traders",
description="Time until trader resets",
)
async def trader_resets(self, ctx: commands.Context):
import requests
from datetime import datetime
from datetime import timezone
await ctx.defer()
# Define the target date and time
embed = discord.Embed(
description="-------", color=discord.Color.blue(), type="rich"
)
embed.set_author(name="PVE Trader Reset Times")
embed.set_thumbnail(url="https://i.ytimg.com/vi/8He5q7qOzNw/maxresdefault.jpg")
query = """
{
traders(gameMode:pve) {
name
resetTime
}
}
"""
headers = {"Content-Type": "application/json"}
response = requests.post(
"https://api.tarkov.dev/graphql", headers=headers, json={"query": query}
).json()["data"]["traders"]
# print(response)
current_time = datetime.now(timezone.utc)
# Loop through the dataset
for entry in response:
name = entry["name"]
if name in ["BTR Driver", "Lightkeeper"]:
break
reset_time = datetime.fromisoformat(
entry["resetTime"].replace("Z", "+00:00")
) # Convert to datetime object
time_until = reset_time - current_time # Calculate time until the reset
# Format the time until as human-readable
if time_until.total_seconds() > 0: # Only format if there's time remaining
readable_time = format_timedelta(time_until)
else:
readable_time = "Just Reset"
# Print the name and formatted time until reset
embed.add_field(
name=name,
value=f"`{readable_time}`",
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)
def setup(bot):
bot.add_cog(Tarkov(bot))