From a63b947d9e0090ef406af51130b9e682034681b3 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sun, 11 Jun 2023 14:48:06 -0700 Subject: [PATCH] disabling the medaia.discordapp change --- app/bot.py | 16 ----------- app/cogs/star_citizen.py | 60 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 20 deletions(-) mode change 100644 => 100755 app/bot.py diff --git a/app/bot.py b/app/bot.py old mode 100644 new mode 100755 index 696fc833..71a103ce --- a/app/bot.py +++ b/app/bot.py @@ -73,22 +73,6 @@ async def on_raw_reaction_add(payload): await member.add_roles(role) -@bot.listen("on_message") -async def fix_cdn_url(ctx): - # Ignore images - videos = ["mp4", "mov"] - if any(x in ctx.content for x in videos) and "media.discordapp.net" in ctx.content: - await ctx.delete() - await ctx.channel.send( - "%s said:\n\n%s" - % ( - ctx.author.mention, - ctx.content.replace("media.discordapp.net", "cdn.discordapp.com"), - ) - ) - return - - @bot.listen("on_message") async def convert_heic_to_jpg(ctx): from cmagick import cmagick diff --git a/app/cogs/star_citizen.py b/app/cogs/star_citizen.py index ec51dc1e..5ed55a6e 100644 --- a/app/cogs/star_citizen.py +++ b/app/cogs/star_citizen.py @@ -13,6 +13,7 @@ class StarCitizen(commands.Cog): def __init__(self, bot): self.bot: commands.Bot = bot self.poll_status_page.start() + # self.poll_for_patch_notes.start() @commands.slash_command( guild_ids=None, @@ -37,6 +38,60 @@ class StarCitizen(commands.Cog): embed = await star_citizen.get_ship(ship_name=ship) await ctx.send_followup(embed=embed) + @tasks.loop(seconds=5) + async def poll_for_patch_notes(self): + # Wait until the bot is ready before we actually start executing code + await self.bot.wait_until_ready() + + blog_url = "https://www.spaceloop.it/en/blog-en" + + headers = { + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/112.0" + } + + response = requests.get( + blog_url, + headers=headers, + ).text + + soup = BeautifulSoup(response, "html.parser") + + latest_post = soup.find("div", {"class": "posts-wrapper"}).findNext( + "h2", {"class": "blog-entry-title"} + ) + print(latest_post) + + if "Patch Notes" in latest_post.text: + patch_notes_page = requests.get( + latest_post.findNext("a")["href"], + headers=headers, + ).text + + soup = BeautifulSoup(patch_notes_page, "html.parser") + + patch_number = soup.find("h2", {"class": "wp-block-heading"}).text + print(patch_number) + + embed = discord.Embed( + description="-------", color=discord.Color.blue(), type="rich" + ) + + embed.set_thumbnail( + url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png" + ) + embed.set_author(name=patch_number) + + for bullet in soup.find_all("h3"): + if bullet.text == "Patch News": + break + embed.add_field( + name=bullet.text, + value="\n".join([x for x in bullet.findNext("ul").find_all("li")]), + inline=False, + ) + + await self.bot.get_channel(932476007439552522).send(embed=embed) + @tasks.loop(seconds=5) async def poll_status_page(self): # Wait until the bot is ready before we actually start executing code @@ -88,10 +143,7 @@ class StarCitizen(commands.Cog): inline=False, ) - channel = await self.bot.get_channel(1097567909640929340).send(embed=embed) - self.notified = 1 - else: - self.notified = 0 + await self.bot.get_channel(1097567909640929340).send(embed=embed) def setup(bot):