Make sure to only notifiy about an incdient once

This commit is contained in:
Luke Robles 2023-05-05 16:02:13 -07:00
parent eb655c5a75
commit 5825e538b0
2 changed files with 44 additions and 31 deletions

View File

@ -2,6 +2,7 @@ from bs4 import BeautifulSoup
from discord import option from discord import option
from discord.ext import commands, tasks from discord.ext import commands, tasks
import discord import discord
import os
import requests import requests
@ -11,7 +12,7 @@ import star_citizen
class StarCitizen(commands.Cog): class StarCitizen(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot: commands.Bot = bot self.bot: commands.Bot = bot
# self.poll_status_page.start() self.poll_status_page.start()
@commands.slash_command( @commands.slash_command(
guild_ids=None, guild_ids=None,
@ -36,44 +37,56 @@ class StarCitizen(commands.Cog):
embed = await star_citizen.get_ship(ship_name=ship) embed = await star_citizen.get_ship(ship_name=ship)
await ctx.send_followup(embed=embed) await ctx.send_followup(embed=embed)
# @tasks.loop(seconds=5) @tasks.loop(seconds=5)
# async def poll_status_page(self): async def poll_status_page(self):
# # Wait until the bot is ready before we actually start executing code # Wait until the bot is ready before we actually start executing code
# await self.bot.wait_until_ready() await self.bot.wait_until_ready()
# status_url = "https://status.robertsspaceindustries.com/" status_url = "https://status.robertsspaceindustries.com"
# response = requests.get(status_url).text response = requests.get(status_url).text
# soup = BeautifulSoup(response, "html.parser") soup = BeautifulSoup(response, "html.parser")
# current_status = soup.find("div", {"class": "global-status"}).findNext("span") current_status = soup.find("div", {"class": "global-status"}).findNext("span")
# self.notified = 0 rsi_incident_file = "/tmp/rsi_incident"
# if current_status.text != "Operational" and self.notified == 0:
# # Find the lastest incident
# latest_incident = current_status.findNext("h2")
# details = latest_incident.findNext("div", {"class": "markdown"})
# embed = discord.Embed( if current_status.text != "Operational":
# description="-------", color=discord.Color.red(), type="rich" # Find the lastest incident
# ) latest_incident = current_status.findNext("h2")
# embed.set_thumbnail( # Check if we've already notified
# url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png" if os.path.exists(rsi_incident_file):
# ) if (
# embed.set_author(name="OH NO THERE IS AN INCIDENT") open(rsi_incident_file, "r").read()
# embed.add_field(name="Details", value=details.text, inline=True) == latest_incident.findNext("a")["href"]
):
return
# embed.add_field( f = open(rsi_incident_file, "w")
# name="LINK", f.write(latest_incident.findNext("a")["href"])
# value=status_url + latest_incident.findNext("a")["href"],
# inline=False,
# )
# channel = await self.bot.get_channel(1097567909640929340).send(embed=embed) details = latest_incident.findNext("div", {"class": "markdown"})
# self.notified = 1 embed = discord.Embed(
# else: description="-------", color=discord.Color.red(), type="rich"
# self.notified = 0 )
embed.set_thumbnail(
url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png"
)
embed.set_author(name="OH NO THERE IS AN INCIDENT")
embed.add_field(name="Details", value=details.text, inline=True)
embed.add_field(
name="LINK",
value=status_url + latest_incident.findNext("a")["href"],
inline=False,
)
channel = await self.bot.get_channel(932476007439552522).send(embed=embed)
self.notified = 1
else:
self.notified = 0
def setup(bot): def setup(bot):

0
app/stock.py Normal file → Executable file
View File