From ecf009f05153e94f79da290b522e0e219bd70e37 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 23 Sep 2023 09:41:45 -0700 Subject: [PATCH] Rmeoving unused code and adding a makefile --- Makefile | 11 ++++++ app/cogs/star_citizen.py | 75 ++++------------------------------------ format_code.sh | 1 - test-dragon-bot.sh | 14 -------- 4 files changed, 17 insertions(+), 84 deletions(-) create mode 100644 Makefile delete mode 100755 format_code.sh delete mode 100755 test-dragon-bot.sh diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..c90a8cb0 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +format: + docker run --rm -ti -v ${PWD}:/tmp/python/app python:alpine sh -c "cd /tmp/python; pip install -q black; black ." + +clean: + docker rm -f dragon-bot-test + rm -vr app/__pycache__ app/cogs/__pycache__ + +discord_token := "MzQ1MjkwMTI5OTQ4Mjc4Nzg0.G16mG8.vxgQLwnbusG9fSlXvAFV0wTUmRsJJlPnQ3bpco" +DRAGON_ENV := "test" +test: clean format + docker run -ti -v ${PWD}/app:/app --rm --name dragon-bot-test -e DRAGON_ENV=${DRAGON_ENV} -e discord_token=${discord_token} dragon-bot-test bash \ No newline at end of file diff --git a/app/cogs/star_citizen.py b/app/cogs/star_citizen.py index 7bf07b2d..cb087386 100644 --- a/app/cogs/star_citizen.py +++ b/app/cogs/star_citizen.py @@ -62,60 +62,6 @@ class StarCitizen(commands.Cog): embed = await star_citizen.calculate_trade_profies(commodity=commodity, scu=scu) 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 @@ -135,12 +81,12 @@ class StarCitizen(commands.Cog): latest_incident = current_status.findNext("h2") # Check if we've already notified - if os.path.exists(rsi_incident_file): - if ( - open(rsi_incident_file, "r").read() - == latest_incident.findNext("a")["href"] - ): - return + if ( + os.path.exists(rsi_incident_file) + and open(rsi_incident_file, "r").read() + == latest_incident.findNext("a")["href"] + ): + return f = open(rsi_incident_file, "w") f.write(latest_incident.findNext("a")["href"]) @@ -168,15 +114,6 @@ class StarCitizen(commands.Cog): ) await self.bot.get_channel(1097567909640929340).send(embed=embed) - # sent_embed = await self.bot.get_channel(932476007439552522).send( - # embed=embed - # ) - - # # If the devs update the content of the incident, update the embed with the new text - # if details.text != sent_embed.embeds[0].fields[0].value: - # sent_embed.embeds[0].set_field_at( - # index=0, name="Details", value=details.text, inline=True - # ) def setup(bot): diff --git a/format_code.sh b/format_code.sh deleted file mode 100755 index 87a39e44..00000000 --- a/format_code.sh +++ /dev/null @@ -1 +0,0 @@ -docker run --rm -ti -v $(pwd):/tmp/python/app python:alpine sh -c "cd /tmp/python ; pip install -q black; black ." diff --git a/test-dragon-bot.sh b/test-dragon-bot.sh deleted file mode 100755 index 284ee812..00000000 --- a/test-dragon-bot.sh +++ /dev/null @@ -1,14 +0,0 @@ -printf "\n[-] Formatting code\n" -./format_code.sh -printf "[+] Done\n" - -# Remove the running container so we can re-use the container name 'dragon-bot' -printf "\n[-] Deleting old dragon-bot container from system\n" -docker rm -f dragon-bot-test -printf "[+] Done\n" - -printf "\n[-] Running dragon bot in test mode\n" -chmod +x ./app/bot.py -docker build -f ./Dockerfile-test-env -t dragon-bot-test . || exit - -docker run -ti -v $(pwd)/app:/app --rm --name dragon-bot-test -e DRAGON_ENV=test -e token="MzQ1MjkwMTI5OTQ4Mjc4Nzg0.G16mG8.vxgQLwnbusG9fSlXvAFV0wTUmRsJJlPnQ3bpco" dragon-bot-test bash