diff --git a/app/cogs/star_citizen.py b/app/cogs/star_citizen.py index bd678974..4c5cfa33 100755 --- a/app/cogs/star_citizen.py +++ b/app/cogs/star_citizen.py @@ -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( diff --git a/app/cogs/tarkov.py b/app/cogs/tarkov.py new file mode 100755 index 00000000..a9b5ec4d --- /dev/null +++ b/app/cogs/tarkov.py @@ -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)) diff --git a/app/tarkov.py b/app/tarkov.py new file mode 100644 index 00000000..51767018 --- /dev/null +++ b/app/tarkov.py @@ -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")]