diff --git a/app/bot.py b/app/bot.py index 793f23ae..9cf05305 100755 --- a/app/bot.py +++ b/app/bot.py @@ -24,16 +24,8 @@ for cogfile in cogfiles: @bot.event async def on_ready(): print(f"{bot.user.name} has connected to Discord!") - game = discord.Game("Type !help") - await bot.change_presence( - status=discord.Status.online, - activity=discord.Activity( - type=discord.ActivityType.listening, name="type !help" - ), - ) - if os.getenv("DRAGON_ENV") == "prod": - await bot.get_channel(152921472304676865).send("I have reconnected") + # await bot.get_channel(152921472304676865).send("I have reconnected") # Waiting-room in zoid's server channel_id = 1026281775984549958 diff --git a/app/cogs/star_citizen.py b/app/cogs/star_citizen.py index a0a996cc..4390d75d 100644 --- a/app/cogs/star_citizen.py +++ b/app/cogs/star_citizen.py @@ -1,11 +1,17 @@ +from bs4 import BeautifulSoup from discord import option -from discord.ext import commands +from discord.ext import commands, tasks +import discord +import requests + + import star_citizen class StarCitizen(commands.Cog): def __init__(self, bot): self.bot: commands.Bot = bot + self.poll_status_page.start() @commands.slash_command( guild_ids=None, @@ -22,6 +28,41 @@ class StarCitizen(commands.Cog): embed = await star_citizen.get_ship(ship_name=ship) await ctx.send_followup(embed=embed) + @tasks.loop(seconds=60) + async def poll_status_page(self): + # Wait until the bot is ready before we actually start executing code + await self.bot.wait_until_ready() + + status_url = "https://status.robertsspaceindustries.com/" + + response = requests.get(status_url).text + soup = BeautifulSoup(response, "html.parser") + + current_status = soup.find("div", {"class": "global-status"}).findNext("span") + + if current_status.text != "Operational": + # Find the lastest incident + latest_incident = current_status.findNext("h2") + details = latest_incident.findNext("div", {"class": "markdown"}) + + embed = discord.Embed( + description="-------", color=discord.Color.red(), type="rich" + ) + + embed.set_thumbnail( + url="https://cdn.discordapp.com/attachments/1062905729532571719/1090721517790318612/Screenshot_20230329-222457__01__01.jpg" + ) + 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(1097567909640929340).send(embed=embed) + def setup(bot): bot.add_cog(StarCitizen(bot))