Adding first pass at boss info command
All checks were successful
Build and push / changes (push) Successful in 4s
Build and push / Lint-Python (push) Successful in 7s
Build and push / Build-and-Push-Docker (push) Successful in 17s
Build and push / sync-argocd-app (push) Successful in 3s

This commit is contained in:
Luke R 2024-11-02 17:18:51 -07:00
parent df3ac251d5
commit d37151e097
2 changed files with 50 additions and 92 deletions

View File

@ -246,97 +246,6 @@ class StarCitizen(commands.Cog):
embed = await star_citizen.calculate_trade_profits(commodity=commodity, scu=scu)
await ctx.send_followup(embed=embed)
@tasks.loop(seconds=5)
async def poll_status_page(self):
# Wait until the bot is ready before we actually start executing code
await self.bot.wait_until_ready()
status_url = "https://status.robertsspaceindustries.com"
rsi_incident_file = "/tmp/rsi_incident"
status_json = requests.get(status_url + "/index.json").json()
if status_json["summaryStatus"] != "operational":
# Extract systems with unresolved issues
systems_with_issues = [
system
for system in status_json["systems"]
if system["unresolvedIssues"]
]
print(systems_with_issues)
unresolved_issue_permalink = systems_with_issues[0]["unresolvedIssues"][0][
"permalink"
]
# Remove any single quote characters from the URL
current_incident_url = unresolved_issue_permalink.replace("'", "")
response = requests.get(current_incident_url).text
incident_soup = BeautifulSoup(response, "html.parser")
details = incident_soup.find("div", class_="article__content").get_text()
if os.path.exists(rsi_incident_file):
file_contents = json.loads(open(rsi_incident_file).read())
deets = file_contents["details"]
incident_link = file_contents["incident_link"]
if current_incident_url != incident_link:
print(
"Current incident url did not match whats in the file, must be a new incident, send alert"
)
embed = core_utils.build_alert_embed(
color=discord.Color.red(),
thumbnail="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png",
author="🚨 OH NO THERES AN INCIDENT 🚨",
image="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif",
details=details,
link=current_incident_url,
)
core_utils.write_incident_file(
file_path=rsi_incident_file,
url=current_incident_url,
details=details,
)
await core_utils.send_alert(self, channel=channel_id, embed=embed)
elif deets != details:
# The details we have in the json file do not match what was recently posted to the website
# Update the json file on disk and then send an update alert to the channel
core_utils.write_incident_file(
file_path=rsi_incident_file,
url=current_incident_url,
details=details,
)
embed = core_utils.build_alert_embed(
color=discord.Color.yellow(),
thumbnail="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png",
author="⚠️ THERE HAS BEEN AN UPDATE TO THE ONGOING INCIDENT ⚠️",
image="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif",
details=deets,
link=incident_link,
)
await core_utils.send_alert(self, channel=channel_id, embed=embed)
else:
# Write the incident's body to a json file to read later
core_utils.write_incident_file(
file_path=rsi_incident_file,
url=current_incident_url,
details=details,
)
embed = core_utils.build_alert_embed(
color=discord.Color.red(),
thumbnail="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png",
author="🚨 OH NO THERES AN INCIDENT 🚨",
image="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif",
details=details,
link=current_incident_url,
)
await core_utils.send_alert(self, channel=channel_id, embed=embed)
@starcitizen.command(
guild_ids=core_utils.my_guilds,
name="rsifind",

View File

@ -1,4 +1,5 @@
from datetime import datetime
from bs4 import BeautifulSoup
from discord.ext import commands
import core_utils
import discord
@ -20,6 +21,14 @@ class Tarkov(commands.Cog):
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",
@ -149,7 +158,7 @@ class Tarkov(commands.Cog):
@tarkov.command(
guild_ids=core_utils.my_guilds,
name="bosses",
name="spawns",
description="Boss spawn chances per map",
)
async def boss_spawns(self, ctx: commands.Context):
@ -209,6 +218,46 @@ class Tarkov(commands.Cog):
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/"
# boss_name = "Tagilla"
response = requests.get(wiki_url + boss_name).text
soup = BeautifulSoup(response, "html.parser")
embed.set_thumbnail(url=soup.find("a", class_="image").get("href"))
health = soup.find("table", class_="wikitable").find_next("td").text.rstrip()
embed.add_field(name="Health", value=health, 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=spawn_chance, inline=False)
await ctx.send_followup(embed=embed)
def setup(bot):
bot.add_cog(Tarkov(bot))