Fixing the incdient code and also /ship

This commit is contained in:
Luke Robles 2023-10-12 11:54:06 -07:00
parent 9bd591e102
commit 9d1549559a
16 changed files with 98 additions and 69 deletions

View File

@ -3,7 +3,7 @@ ADD app/requirements.txt /requirements.txt
RUN pip install --disable-pip-version-check --verbose -r requirements.txt
FROM python:3.10-rc-slim
RUN apt-get update && apt-get install -y --no-install-recommends imagemagick
RUN apt-get update && apt-get install -y --no-install-recommends imagemagick vim jq
RUN pip install black && echo "black .; ./bot.py" >/usr/local/bin/start && chmod +x /usr/local/bin/start
COPY --from=0 /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
ADD app /app

0
Makefile Executable file → Normal file
View File

0
app/cogs/actual_utils.py Executable file → Normal file
View File

0
app/cogs/markov.py Executable file → Normal file
View File

0
app/cogs/poll.py Executable file → Normal file
View File

0
app/cogs/server_utils.py Executable file → Normal file
View File

0
app/cogs/stable_diffusion.py Executable file → Normal file
View File

139
app/cogs/star_citizen.py Executable file → Normal file
View File

@ -69,10 +69,9 @@ class StarCitizen(commands.Cog):
response = requests.get(url).text
soup = BeautifulSoup(response, "html.parser")
h2_heading = soup.find("h2", text='Pages in category "Ships"')
all_ships = [
a.text for a in soup.select("div.mw-category.mw-category-columns a")
]
all_ships = [link.text for link in h2_heading.find_next("div").find_all("a")]
return all_ships
@ -225,60 +224,72 @@ class StarCitizen(commands.Cog):
response = requests.get(status_url).text
soup = BeautifulSoup(response, "html.parser")
current_status = soup.find("div", {"class": "global-status"}).findNext("span")
rsi_incident_file = "/tmp/rsi_incident"
current_status = soup.find("div", {"class": "summary"})
if current_status.text != "Operational":
if current_status.text.strip() != "No issues detectedd":
# Find the lastest incident
latest_incident = current_status.findNext("h2")
current_incident_url = status_url + latest_incident.findNext("a")["href"]
details = latest_incident.findNext("div", {"class": "markdown"}).text
latest_incident = current_status.findNext("h3")
current_incident_url = (
latest_incident.find_next("div", class_="issue no-underline")
.get("onclick")
.split("=")[-1]
.replace("\\", "")
)
details = latest_incident.findNext("span", {"class": "issue__content"}).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:
if deets != details:
embed = discord.Embed(
description="-------",
color=discord.Color.yellow(),
type="rich",
)
if current_incident_url != incident_link:
print("Current incident url did not match wahts in the file")
embed = star_citizen.build_alert_embed(
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,
)
star_citizen.write_incident_file(
file_path=rsi_incident_file,
url=current_incident_url,
details=details,
)
embed.set_thumbnail(
url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png"
)
embed.set_author(
name="⚠️ THERE HAS BEEN AN UPDATE TO THE ONGOING INCIDENT ⚠️"
)
# embed.set_image(
# url="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif"
# )
embed.add_field(name="Details", value=deets, inline=True)
# # Testing channel
# await star_citizen.send_alert(
# self, channel=932476007439552522, embed=embed
# )
embed.add_field(
name="LINK",
value=incident_link,
inline=False,
)
await self.bot.get_channel(1097567909640929340).send(
embed=embed
)
# Testing channel
# await self.bot.get_channel(932476007439552522).send(
# embed=embed
# )
star_citizen.write_incident_file(
file_path=rsi_incident_file,
url=current_incident_url,
details=details,
)
# Actual channel
await star_citizen.send_alert(
self, channel=1097567909640929340, embed=embed
)
elif deets != details:
star_citizen.write_incident_file(
file_path=rsi_incident_file,
url=current_incident_url,
details=details,
)
embed = star_citizen.build_alert_embed(
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,
)
# # Testing channel
# await star_citizen.send_alert(
# self, channel=932476007439552522, embed=embed
# )
# Actual channel
await star_citizen.send_alert(
self, channel=1097567909640929340, embed=embed
)
else:
# Write the incident's body to a json file to read later
star_citizen.write_incident_file(
@ -287,32 +298,24 @@ class StarCitizen(commands.Cog):
details=details,
)
embed = discord.Embed(
description="-------", color=discord.Color.red(), type="rich"
embed = star_citizen.build_alert_embed(
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,
)
embed.set_thumbnail(
url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png"
)
embed.set_author(name="🚨 OH NO THERES AN INCIDENT 🚨")
embed.set_image(
url="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif"
)
embed.add_field(name="Details", value=details, inline=True)
embed.add_field(
name="LINK",
value=current_incident_url,
inline=False,
)
await self.bot.get_channel(1097567909640929340).send(embed=embed)
# Testing channel
# await self.bot.get_channel(932476007439552522).send(
# embed=embed
# # Testing channel
# await star_citizen.send_alert(
# self, channel=932476007439552522, embed=embed
# )
# Actual channel
await star_citizen.send_alert(
self, channel=1097567909640929340, embed=embed
)
def setup(bot):
bot.add_cog(StarCitizen(bot))

0
app/cogs/user_functions.py Executable file → Normal file
View File

View File

@ -12,6 +12,32 @@ pp = pprint.PrettyPrinter(indent=4)
wiki_url = "https://starcitizen.tools/"
async def send_alert(self, channel, embed):
await self.bot.get_channel(channel).send(embed=embed)
def build_alert_embed(thumbnail=None, author=None, image=None, details=None, link=None):
embed = discord.Embed(description="-------", color=discord.Color.red(), type="rich")
if thumbnail:
embed.set_thumbnail(url=thumbnail)
embed.set_author(name=author)
if image:
embed.set_image(url=image)
embed.add_field(name="Details", value=details, inline=True)
embed.add_field(
name="LINK",
value=link,
inline=False,
)
return embed
def write_incident_file(file_path, url, details):
info_dict = {
"incident_link": url,

0
dalebot-overview.py Executable file → Normal file
View File

0
helm/.helmignore Executable file → Normal file
View File

0
helm/Chart.yaml Executable file → Normal file
View File

0
helm/templates/_helpers.tpl Executable file → Normal file
View File

0
helm/templates/hpa.yaml Executable file → Normal file
View File

0
helm/templates/ingress.yaml Executable file → Normal file
View File