Rmeoving unused code and adding a makefile

This commit is contained in:
Luke Robles 2023-09-23 09:41:45 -07:00
parent cf6060d540
commit a81c30b18c
4 changed files with 17 additions and 84 deletions

11
Makefile Normal file
View File

@ -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

View File

@ -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):

View File

@ -1 +0,0 @@
docker run --rm -ti -v $(pwd):/tmp/python/app python:alpine sh -c "cd /tmp/python ; pip install -q black; black ."

View File

@ -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