Another re-write of the monitoring code for starcitizen. This time taking advantage of the cstate API
This commit is contained in:
parent
8e9348fb24
commit
d9a89939e0
16
app/bot.py
16
app/bot.py
@ -133,20 +133,4 @@ async def fix_tiktok_links(ctx):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
|
||||||
async def on_command_completion(ctx):
|
|
||||||
channel = bot.get_channel(826547484632678453)
|
|
||||||
embed = discord.Embed(colour=discord.Color.green(), title="Command Executed")
|
|
||||||
embed.add_field(name="Command:", value=f"`{ctx.command}`")
|
|
||||||
embed.add_field(name="User:", value=f"`{ctx.author}`", inline=False)
|
|
||||||
embed.add_field(name="Channel:", value=f"{ctx.channel} **( <#{ctx.channel.id}> )**")
|
|
||||||
embed.add_field(
|
|
||||||
name="Link to Message:",
|
|
||||||
value="**(** [%s](%s) **)**" % (ctx.channel, ctx.message.jump_url),
|
|
||||||
)
|
|
||||||
embed.add_field(name="Server:", value=f"{ctx.guild} **( <#{ctx.channel.id}> )**")
|
|
||||||
if ctx.message.author.id != core_utils.my_id:
|
|
||||||
await channel.send(embed=embed)
|
|
||||||
|
|
||||||
|
|
||||||
bot.run(os.getenv("discord_token"))
|
bot.run(os.getenv("discord_token"))
|
||||||
|
@ -8,6 +8,11 @@ import json
|
|||||||
|
|
||||||
import star_citizen
|
import star_citizen
|
||||||
|
|
||||||
|
if os.getenv("DRAGON_ENV") == "prod":
|
||||||
|
channel_id = 1097567909640929340
|
||||||
|
else:
|
||||||
|
channel_id = 932476007439552522
|
||||||
|
|
||||||
|
|
||||||
class StarCitizen(commands.Cog):
|
class StarCitizen(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
@ -221,25 +226,19 @@ class StarCitizen(commands.Cog):
|
|||||||
|
|
||||||
status_url = "https://status.robertsspaceindustries.com"
|
status_url = "https://status.robertsspaceindustries.com"
|
||||||
|
|
||||||
response = requests.get(status_url).text
|
|
||||||
soup = BeautifulSoup(response, "html.parser")
|
|
||||||
|
|
||||||
rsi_incident_file = "/tmp/rsi_incident"
|
rsi_incident_file = "/tmp/rsi_incident"
|
||||||
current_status = soup.find("div", {"class": "summary"})
|
|
||||||
|
|
||||||
if current_status.text.strip() != "No issues detected":
|
if requests.get(status_url + "/index.json").json()["summaryStatus"] != "ok":
|
||||||
# Find the lastest incident
|
# Look at all the systems in the API and filter out the ones whos "unresolvedIssues" list is not empty,
|
||||||
latest_incident = current_status.findNext("h3")
|
# Then parse out the "permalink" value
|
||||||
|
current_incident_url = list(
|
||||||
|
filter(lambda x: len(x["unresolvedIssues"]), status_json["systems"])
|
||||||
|
)[0]["unresolvedIssues"][0]["permalink"].replace("'", "")
|
||||||
|
|
||||||
current_incident_url = (
|
response = requests.get(current_incident_url).text
|
||||||
latest_incident.find_next("div", class_="issue no-underline")
|
incident_soup = BeautifulSoup(response, "html.parser")
|
||||||
.get("onclick")
|
|
||||||
.split("=")[-1]
|
|
||||||
.replace("\\", "")
|
|
||||||
.replace("'", "")
|
|
||||||
)
|
|
||||||
|
|
||||||
details = latest_incident.findNext("span", {"class": "issue__content"}).text
|
details = incident_soup.find("div", class_="article__content").get_text()
|
||||||
|
|
||||||
if os.path.exists(rsi_incident_file):
|
if os.path.exists(rsi_incident_file):
|
||||||
file_contents = json.loads(open(rsi_incident_file).read())
|
file_contents = json.loads(open(rsi_incident_file).read())
|
||||||
@ -247,8 +246,11 @@ class StarCitizen(commands.Cog):
|
|||||||
incident_link = file_contents["incident_link"]
|
incident_link = file_contents["incident_link"]
|
||||||
|
|
||||||
if current_incident_url != incident_link:
|
if current_incident_url != incident_link:
|
||||||
print("Current incident url did not match wahts in the file")
|
print(
|
||||||
|
"Current incident url did not match whats in the file, must be a new incident, send alert"
|
||||||
|
)
|
||||||
embed = star_citizen.build_alert_embed(
|
embed = star_citizen.build_alert_embed(
|
||||||
|
color=discord.Color.red(),
|
||||||
thumbnail="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png",
|
thumbnail="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png",
|
||||||
author="🚨 OH NO THERES AN INCIDENT 🚨",
|
author="🚨 OH NO THERES AN INCIDENT 🚨",
|
||||||
image="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif",
|
image="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif",
|
||||||
@ -261,36 +263,25 @@ class StarCitizen(commands.Cog):
|
|||||||
details=details,
|
details=details,
|
||||||
)
|
)
|
||||||
|
|
||||||
# # Testing channel
|
await star_citizen.send_alert(self, channel=channel_id, embed=embed)
|
||||||
# await star_citizen.send_alert(
|
|
||||||
# self, channel=932476007439552522, embed=embed
|
|
||||||
# )
|
|
||||||
|
|
||||||
# Actual channel
|
|
||||||
await star_citizen.send_alert(
|
|
||||||
self, channel=1097567909640929340, embed=embed
|
|
||||||
)
|
|
||||||
elif deets != details:
|
elif deets != details:
|
||||||
|
# The details we have in the json file do not match what was recently posted to the website
|
||||||
|
# Update the json file on disk and then send an update alert to the channel
|
||||||
star_citizen.write_incident_file(
|
star_citizen.write_incident_file(
|
||||||
file_path=rsi_incident_file,
|
file_path=rsi_incident_file,
|
||||||
url=current_incident_url,
|
url=current_incident_url,
|
||||||
details=details,
|
details=details,
|
||||||
)
|
)
|
||||||
embed = star_citizen.build_alert_embed(
|
embed = star_citizen.build_alert_embed(
|
||||||
|
color=discord.Color.yellow(),
|
||||||
thumbnail="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png",
|
thumbnail="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png",
|
||||||
author="⚠️ THERE HAS BEEN AN UPDATE TO THE ONGOING INCIDENT ⚠️",
|
author="⚠️ THERE HAS BEEN AN UPDATE TO THE ONGOING INCIDENT ⚠️",
|
||||||
image="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif",
|
image="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif",
|
||||||
details=deets,
|
details=deets,
|
||||||
link=incident_link,
|
link=incident_link,
|
||||||
)
|
)
|
||||||
# # Testing channel
|
|
||||||
# await star_citizen.send_alert(
|
await star_citizen.send_alert(self, channel=channel_id, embed=embed)
|
||||||
# self, channel=932476007439552522, embed=embed
|
|
||||||
# )
|
|
||||||
# Actual channel
|
|
||||||
await star_citizen.send_alert(
|
|
||||||
self, channel=1097567909640929340, embed=embed
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# Write the incident's body to a json file to read later
|
# Write the incident's body to a json file to read later
|
||||||
star_citizen.write_incident_file(
|
star_citizen.write_incident_file(
|
||||||
@ -300,6 +291,7 @@ class StarCitizen(commands.Cog):
|
|||||||
)
|
)
|
||||||
|
|
||||||
embed = star_citizen.build_alert_embed(
|
embed = star_citizen.build_alert_embed(
|
||||||
|
color=discord.Color.red(),
|
||||||
thumbnail="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png",
|
thumbnail="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png",
|
||||||
author="🚨 OH NO THERES AN INCIDENT 🚨",
|
author="🚨 OH NO THERES AN INCIDENT 🚨",
|
||||||
image="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif",
|
image="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif",
|
||||||
@ -307,15 +299,7 @@ class StarCitizen(commands.Cog):
|
|||||||
link=current_incident_url,
|
link=current_incident_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
# # Testing channel
|
await star_citizen.send_alert(self, channel=channel_id, embed=embed)
|
||||||
# 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):
|
def setup(bot):
|
||||||
|
@ -16,8 +16,10 @@ async def send_alert(self, channel, embed):
|
|||||||
await self.bot.get_channel(channel).send(embed=embed)
|
await self.bot.get_channel(channel).send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
def build_alert_embed(thumbnail=None, author=None, image=None, details=None, link=None):
|
def build_alert_embed(
|
||||||
embed = discord.Embed(description="-------", color=discord.Color.red(), type="rich")
|
color, thumbnail=None, author=None, image=None, details=None, link=None
|
||||||
|
):
|
||||||
|
embed = discord.Embed(description="-------", color=color, type="rich")
|
||||||
|
|
||||||
if thumbnail:
|
if thumbnail:
|
||||||
embed.set_thumbnail(url=thumbnail)
|
embed.set_thumbnail(url=thumbnail)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user