First pass at loadout lotery
All checks were successful
Build and push / changes (push) Successful in 4s
Build and push / Lint-Python (push) Successful in 6s
Build and push / Build-and-Push-Docker (push) Successful in 1m13s
Build and push / sync-argocd-app (push) Successful in 3s

This commit is contained in:
Luke R 2024-06-06 16:14:34 -07:00
parent 7e4b561a6f
commit ab2a5aade3
3 changed files with 128 additions and 1 deletions

View File

@ -78,7 +78,7 @@ class StarCitizen(commands.Cog):
url = "https://starcitizen.tools/Category:Ships"
response = requests.get(url, timeout=25).text
soup = BeautifulSoup(response, "html.parser")
h2_heading = soup.find("h2", text='Pages in category "Ships"')
h2_heading = soup.find("h2", string='Pages in category "Ships"')
return [link.text for link in h2_heading.find_next("div").find_all("a")]
@starcitizen.command(

116
app/cogs/tarkov.py Executable file
View File

@ -0,0 +1,116 @@
from discord import option
from discord.ext import commands, tasks
import core_utils
import discord
import json
import os
import random
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")
@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")
chest_rigs = 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",
random.randint(1, 4),
"Any level is allowed",
]
armor_trader_level = [random.randint(1, 4), "Any level trader armor is allowed"]
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=random.choice(
[random.randint(1, 4), "Any level trader ammo is allowed"]
),
)
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="Allowed" if random.randint(0, 1) == 1 else "None",
)
embed.add_field(
name="Throwables",
inline=False,
value="Allowed" if random.randint(0, 1) == 1 else "None",
)
embed.add_field(
name="Meds",
inline=False,
value="Allowed" if random.randint(0, 1) == 1 else "None",
)
await ctx.defer()
await ctx.send_followup(embed=embed)
def setup(bot):
bot.add_cog(Tarkov(bot))

11
app/tarkov.py Normal file
View File

@ -0,0 +1,11 @@
from bs4 import BeautifulSoup
import requests
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(f"h2", string=f'Pages in category "{heading}"')
return [link.text for link in h2_heading.find_next("div").find_all("a")]