Move some alert building logic to core_utils
This commit is contained in:
parent
8d0ce55af8
commit
4d4d3005d5
@ -76,7 +76,7 @@ class StarCitizen(commands.Cog):
|
|||||||
returns a list of all ships in the game, which can then be passed to the /ship command for auto complete
|
returns a list of all ships in the game, which can then be passed to the /ship command for auto complete
|
||||||
"""
|
"""
|
||||||
url = "https://starcitizen.tools/Category:Ships"
|
url = "https://starcitizen.tools/Category:Ships"
|
||||||
response = requests.get(url).text
|
response = requests.get(url, timeout=5).text
|
||||||
soup = BeautifulSoup(response, "html.parser")
|
soup = BeautifulSoup(response, "html.parser")
|
||||||
h2_heading = soup.find("h2", text='Pages in category "Ships"')
|
h2_heading = soup.find("h2", text='Pages in category "Ships"')
|
||||||
return [link.text for link in h2_heading.find_next("div").find_all("a")]
|
return [link.text for link in h2_heading.find_next("div").find_all("a")]
|
||||||
@ -285,7 +285,7 @@ class StarCitizen(commands.Cog):
|
|||||||
print(
|
print(
|
||||||
"Current incident url did not match whats in the file, must be a new incident, send alert"
|
"Current incident url did not match whats in the file, must be a new incident, send alert"
|
||||||
)
|
)
|
||||||
embed = star_citizen.build_alert_embed(
|
embed = core_utils.build_alert_embed(
|
||||||
color=discord.Color.red(),
|
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 🚨",
|
||||||
@ -293,22 +293,22 @@ class StarCitizen(commands.Cog):
|
|||||||
details=details,
|
details=details,
|
||||||
link=current_incident_url,
|
link=current_incident_url,
|
||||||
)
|
)
|
||||||
star_citizen.write_incident_file(
|
core_utils.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,
|
||||||
)
|
)
|
||||||
|
|
||||||
await star_citizen.send_alert(self, channel=channel_id, embed=embed)
|
await core_utils.send_alert(self, channel=channel_id, 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
|
# 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
|
# Update the json file on disk and then send an update alert to the channel
|
||||||
star_citizen.write_incident_file(
|
core_utils.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 = core_utils.build_alert_embed(
|
||||||
color=discord.Color.yellow(),
|
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 ⚠️",
|
||||||
@ -317,16 +317,16 @@ class StarCitizen(commands.Cog):
|
|||||||
link=incident_link,
|
link=incident_link,
|
||||||
)
|
)
|
||||||
|
|
||||||
await star_citizen.send_alert(self, channel=channel_id, embed=embed)
|
await core_utils.send_alert(self, channel=channel_id, 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(
|
core_utils.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 = core_utils.build_alert_embed(
|
||||||
color=discord.Color.red(),
|
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 🚨",
|
||||||
@ -335,7 +335,7 @@ class StarCitizen(commands.Cog):
|
|||||||
link=current_incident_url,
|
link=current_incident_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
await star_citizen.send_alert(self, channel=channel_id, embed=embed)
|
await core_utils.send_alert(self, channel=channel_id, embed=embed)
|
||||||
|
|
||||||
@starcitizen.command(
|
@starcitizen.command(
|
||||||
guild_ids=core_utils.my_guilds,
|
guild_ids=core_utils.my_guilds,
|
||||||
|
@ -81,3 +81,40 @@ def waifu_pics(endpoint, nsfw=False):
|
|||||||
return requests.get("https://api.waifu.pics/%s/%s" % (pic_type, endpoint)).json()[
|
return requests.get("https://api.waifu.pics/%s/%s" % (pic_type, endpoint)).json()[
|
||||||
"url"
|
"url"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def send_alert(self, channel, embed):
|
||||||
|
await self.bot.get_channel(channel).send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
|
def build_alert_embed(
|
||||||
|
color, thumbnail=None, author=None, image=None, details=None, link=None
|
||||||
|
):
|
||||||
|
embed = discord.Embed(description="-------", color=color, 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,
|
||||||
|
"details": details,
|
||||||
|
}
|
||||||
|
with open(file_path, "w") as out_file:
|
||||||
|
out_file.write(json.dumps(info_dict))
|
||||||
|
@ -8,43 +8,6 @@ import requests
|
|||||||
wiki_url = "https://starcitizen.tools/"
|
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(
|
|
||||||
color, thumbnail=None, author=None, image=None, details=None, link=None
|
|
||||||
):
|
|
||||||
embed = discord.Embed(description="-------", color=color, 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,
|
|
||||||
"details": details,
|
|
||||||
}
|
|
||||||
with open(file_path, "w") as out_file:
|
|
||||||
out_file.write(json.dumps(info_dict))
|
|
||||||
|
|
||||||
|
|
||||||
async def rsi_find(player):
|
async def rsi_find(player):
|
||||||
base_url = "https://robertsspaceindustries.com"
|
base_url = "https://robertsspaceindustries.com"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user