Re-doing the star citizen incident alert logic, it will now alert us to changes in the incident status
This commit is contained in:
parent
f3a3d426ee
commit
72346ff2c4
@ -4,6 +4,7 @@ from discord.ext import commands, tasks
|
||||
import discord
|
||||
import os
|
||||
import requests
|
||||
import json
|
||||
|
||||
import star_citizen
|
||||
|
||||
@ -50,8 +51,6 @@ class StarCitizen(commands.Cog):
|
||||
)
|
||||
embed.set_author(name="Ranking of drugs by sell price")
|
||||
|
||||
# embed.add_field(name="Details", value=details.text, inline=True)
|
||||
|
||||
for k, v in sorted_dict.items():
|
||||
embed.add_field(
|
||||
name=k,
|
||||
@ -250,41 +249,86 @@ class StarCitizen(commands.Cog):
|
||||
if current_status.text != "Operational":
|
||||
# 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
|
||||
|
||||
# Check if we've already notified
|
||||
if (
|
||||
os.path.exists(rsi_incident_file)
|
||||
and open(rsi_incident_file, "r").read()
|
||||
== latest_incident.findNext("a")["href"]
|
||||
):
|
||||
return
|
||||
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"]
|
||||
|
||||
f = open(rsi_incident_file, "w")
|
||||
f.write(latest_incident.findNext("a")["href"])
|
||||
if current_incident_url == incident_link:
|
||||
if deets != details:
|
||||
embed = discord.Embed(
|
||||
description="-------",
|
||||
color=discord.Color.yellow(),
|
||||
type="rich",
|
||||
)
|
||||
|
||||
details = latest_incident.findNext("div", {"class": "markdown"})
|
||||
embed = discord.Embed(
|
||||
description="-------", color=discord.Color.red(), type="rich"
|
||||
)
|
||||
embed.set_thumbnail(
|
||||
url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png"
|
||||
)
|
||||
embed.set_author(
|
||||
name="⚠️ THERE HAS BEEN AN UPDATE TO THE ONGOING INCIDENT ⚠️\n"
|
||||
)
|
||||
# embed.set_image(
|
||||
# url="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif"
|
||||
# )
|
||||
embed.add_field(name="Details", value=deets, inline=True)
|
||||
|
||||
embed.set_thumbnail(
|
||||
url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png"
|
||||
)
|
||||
embed.set_author(
|
||||
name="🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨\n🚨 OH NO THERES AN INCIDENT 🚨\n🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨"
|
||||
)
|
||||
embed.set_image(
|
||||
url="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif"
|
||||
)
|
||||
embed.add_field(name="Details", value=details.text, inline=True)
|
||||
embed.add_field(
|
||||
name="LINK",
|
||||
value=incident_link,
|
||||
inline=False,
|
||||
)
|
||||
|
||||
embed.add_field(
|
||||
name="LINK",
|
||||
value=status_url + latest_incident.findNext("a")["href"],
|
||||
inline=False,
|
||||
)
|
||||
await self.bot.get_channel(1097567909640929340).send(
|
||||
embed=embed
|
||||
)
|
||||
|
||||
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,
|
||||
)
|
||||
else:
|
||||
# Write the incident's body to a json file to read later
|
||||
star_citizen.write_incident_file(
|
||||
file_path=rsi_incident_file,
|
||||
url=current_incident_url,
|
||||
details=details,
|
||||
)
|
||||
|
||||
embed = discord.Embed(
|
||||
description="-------", color=discord.Color.red(), type="rich"
|
||||
)
|
||||
|
||||
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
|
||||
# )
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
@ -2,6 +2,7 @@ from bs4 import BeautifulSoup
|
||||
import requests
|
||||
import discord
|
||||
import os
|
||||
import json
|
||||
|
||||
# prints for debug
|
||||
import pprint
|
||||
@ -11,6 +12,15 @@ pp = pprint.PrettyPrinter(indent=4)
|
||||
wiki_url = "https://starcitizen.tools/"
|
||||
|
||||
|
||||
def write_incident_file(file_path, url, details):
|
||||
info_dict = {
|
||||
"incident_link": url,
|
||||
"details": details,
|
||||
}
|
||||
with open(file_path, "w") as out_file:
|
||||
out_file.write(json.dumps(info_dict))
|
||||
|
||||
|
||||
async def get_ship(ship_name):
|
||||
try:
|
||||
wiki_ship_name = "_".join(elem for elem in ship_name.split())
|
||||
|
Loading…
x
Reference in New Issue
Block a user