diff --git a/Dockerfile-test-env b/Dockerfile-test-env index 6a8c76ac..90bb75d5 100755 --- a/Dockerfile-test-env +++ b/Dockerfile-test-env @@ -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 diff --git a/Makefile b/Makefile old mode 100755 new mode 100644 diff --git a/app/cogs/actual_utils.py b/app/cogs/actual_utils.py old mode 100755 new mode 100644 diff --git a/app/cogs/markov.py b/app/cogs/markov.py old mode 100755 new mode 100644 diff --git a/app/cogs/poll.py b/app/cogs/poll.py old mode 100755 new mode 100644 diff --git a/app/cogs/server_utils.py b/app/cogs/server_utils.py old mode 100755 new mode 100644 diff --git a/app/cogs/stable_diffusion.py b/app/cogs/stable_diffusion.py old mode 100755 new mode 100644 diff --git a/app/cogs/star_citizen.py b/app/cogs/star_citizen.py old mode 100755 new mode 100644 index bf097822..e1f468ce --- a/app/cogs/star_citizen.py +++ b/app/cogs/star_citizen.py @@ -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)) diff --git a/app/cogs/user_functions.py b/app/cogs/user_functions.py old mode 100755 new mode 100644 diff --git a/app/star_citizen.py b/app/star_citizen.py index 4066e531..ac8ca043 100755 --- a/app/star_citizen.py +++ b/app/star_citizen.py @@ -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, diff --git a/dalebot-overview.py b/dalebot-overview.py old mode 100755 new mode 100644 diff --git a/helm/.helmignore b/helm/.helmignore old mode 100755 new mode 100644 diff --git a/helm/Chart.yaml b/helm/Chart.yaml old mode 100755 new mode 100644 diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl old mode 100755 new mode 100644 diff --git a/helm/templates/hpa.yaml b/helm/templates/hpa.yaml old mode 100755 new mode 100644 diff --git a/helm/templates/ingress.yaml b/helm/templates/ingress.yaml old mode 100755 new mode 100644