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 discord
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
import star_citizen
|
import star_citizen
|
||||||
|
|
||||||
@ -50,8 +51,6 @@ class StarCitizen(commands.Cog):
|
|||||||
)
|
)
|
||||||
embed.set_author(name="Ranking of drugs by sell price")
|
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():
|
for k, v in sorted_dict.items():
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name=k,
|
name=k,
|
||||||
@ -250,19 +249,61 @@ class StarCitizen(commands.Cog):
|
|||||||
if current_status.text != "Operational":
|
if current_status.text != "Operational":
|
||||||
# Find the lastest incident
|
# Find the lastest incident
|
||||||
latest_incident = current_status.findNext("h2")
|
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):
|
||||||
if (
|
file_contents = json.loads(open(rsi_incident_file).read())
|
||||||
os.path.exists(rsi_incident_file)
|
deets = file_contents["details"]
|
||||||
and open(rsi_incident_file, "r").read()
|
incident_link = file_contents["incident_link"]
|
||||||
== latest_incident.findNext("a")["href"]
|
|
||||||
):
|
|
||||||
return
|
|
||||||
|
|
||||||
f = open(rsi_incident_file, "w")
|
if current_incident_url == incident_link:
|
||||||
f.write(latest_incident.findNext("a")["href"])
|
if deets != details:
|
||||||
|
embed = discord.Embed(
|
||||||
|
description="-------",
|
||||||
|
color=discord.Color.yellow(),
|
||||||
|
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.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,
|
||||||
|
)
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
details = latest_incident.findNext("div", {"class": "markdown"})
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
description="-------", color=discord.Color.red(), type="rich"
|
description="-------", color=discord.Color.red(), type="rich"
|
||||||
)
|
)
|
||||||
@ -270,22 +311,25 @@ class StarCitizen(commands.Cog):
|
|||||||
embed.set_thumbnail(
|
embed.set_thumbnail(
|
||||||
url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png"
|
url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png"
|
||||||
)
|
)
|
||||||
embed.set_author(
|
embed.set_author(name="🚨 OH NO THERES AN INCIDENT 🚨")
|
||||||
name="🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨\n🚨 OH NO THERES AN INCIDENT 🚨\n🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨"
|
|
||||||
)
|
|
||||||
embed.set_image(
|
embed.set_image(
|
||||||
url="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif"
|
url="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif"
|
||||||
)
|
)
|
||||||
embed.add_field(name="Details", value=details.text, inline=True)
|
embed.add_field(name="Details", value=details, inline=True)
|
||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="LINK",
|
name="LINK",
|
||||||
value=status_url + latest_incident.findNext("a")["href"],
|
value=current_incident_url,
|
||||||
inline=False,
|
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
|
||||||
|
# )
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(StarCitizen(bot))
|
bot.add_cog(StarCitizen(bot))
|
||||||
|
@ -2,6 +2,7 @@ from bs4 import BeautifulSoup
|
|||||||
import requests
|
import requests
|
||||||
import discord
|
import discord
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
# prints for debug
|
# prints for debug
|
||||||
import pprint
|
import pprint
|
||||||
@ -11,6 +12,15 @@ pp = pprint.PrettyPrinter(indent=4)
|
|||||||
wiki_url = "https://starcitizen.tools/"
|
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):
|
async def get_ship(ship_name):
|
||||||
try:
|
try:
|
||||||
wiki_ship_name = "_".join(elem for elem in ship_name.split())
|
wiki_ship_name = "_".join(elem for elem in ship_name.split())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user