Skip to content

Commit

Permalink
Merge pull request #106 from BBArikL/Beta
Browse files Browse the repository at this point in the history
v4.8
  • Loading branch information
BBArikL authored Jun 24, 2023
2 parents 2b47847 + e8fc336 commit 12d5c3d
Show file tree
Hide file tree
Showing 8 changed files with 530 additions and 385 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Discord bot that post bd strips. Simple as that!
- Compu-Toon https://www.gocomics.com/compu-toon
- Pixie and Brutus https://www.webtoons.com/en/challenge/pixie-and-brutus/list?title_no=452175
- Sarah's Scribbles https://www.gocomics.com/sarahs-scribbles
- Speed Bump https://www.gocomics.com/speedbump
- Wallace the Brave https://www.gocomics.com/wallace-the-brave/characters
- Ripley's believe it or Not https://www.gocomics.com/ripleysbelieveitornot


### Removed comics
Dilbert: See https://www.bbc.com/news/world-us-canada-64775250 . Functionality is still there but this is a public bot and I cannot take the risk of keeping it.
Expand Down
26 changes: 16 additions & 10 deletions bdbot/Web_requests_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from bs4 import BeautifulSoup
from requests import get
from rss_parser import Parser
from rss_parser.models.rss import RSS

from bdbot.utils import (
COMIC_LATEST_LINKS_PATH,
Expand Down Expand Up @@ -414,36 +415,41 @@ def get_comic_info_rss(
site_content = get(rss_site).text

if site_content is not None and site_content != "":
feed = Parser(xml=site_content, limit=comic_nb + 1).parse().feed[comic_nb]
rss: RSS = Parser.parse(data=site_content, schema=RSS)
feed = rss.channel.content.items[comic_nb].content
# Get information
tz: str
weekday: str
if strip_details["Main_website"] == "https://www.webtoons.com/en/":
if feed.title != "":
details["title"] = f"{feed.title}"
if feed.title.content != "":
details["title"] = feed.title.content
weekday = "A"
tz = "Z"
else:
weekday = "a"
tz = "z"

new_date = datetime.strptime(
feed.publish_date, f"%{weekday}, %d %b %Y %H:%M:%S %{tz}"
feed.pub_date.content, f"%{weekday}, %d %b %Y %H:%M:%S %{tz}"
)
details["day"] = new_date.strftime("%d")
details["month"] = new_date.strftime("%m")
details["year"] = new_date.strftime("%Y")

details["url"] = feed.link
details["url"] = feed.link.content

img_index = 0
if (
len(feed.description_images) > 1
): # general check for a second image to embed
details["sub_img_url"] = feed.description_images[img_index].source
description_soup = BeautifulSoup(feed.description.content, "html.parser")
description_images = [
{"alt": image.get("alt", ""), "source": image.get("src")}
for image in description_soup.findAll("img")
]

if len(description_images) > 1: # general check for a second image to embed
details["sub_img_url"] = description_images[img_index]["source"]
img_index += 1

details["img_url"] = feed.description_images[img_index].source
details["img_url"] = description_images[img_index]["source"]
else:
details = None

Expand Down
8 changes: 6 additions & 2 deletions bdbot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def main():
description="BDBot now supports slash commands! Re-invite the bot with /inv!",
)
handler = logging.FileHandler(
filename=f'{LOGS_DIRECTORY_PATH}discord_{datetime.now().strftime("%Y_%m_%d_%H_%M")}.log',
filename=os.path.join(
LOGS_DIRECTORY_PATH,
f"discord_{datetime.now().strftime('%Y_%m_%d_%H_%M')}.log",
),
encoding="utf-8",
mode="w",
)
Expand Down Expand Up @@ -85,7 +88,8 @@ async def run(bot: commands.Bot, logger: logging.Logger):

for filename in os.listdir("cogs"):
if filename.endswith("py") and filename != "__init__.py":
await bot.load_extension(f"bdbot.cogs.{filename[:-3]}")
file_name, _ = os.path.splitext(filename)
await bot.load_extension(f"bdbot.cogs.{file_name}")

logger.info("Cogs successfully loaded!")

Expand Down
8 changes: 2 additions & 6 deletions bdbot/discord_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def create_embed(comic_details: Optional[dict] = None):
:param comic_details:
:return:
"""
embed: discord.Embed
if comic_details is not None:
# Embeds the comic
comic_name = comic_details["Name"]
Expand Down Expand Up @@ -95,8 +96,6 @@ def create_embed(comic_details: Optional[dict] = None):
embed.set_image(url=img_url)

embed.set_footer(text=get_random_footer())

return embed
else:
# Error message
embed = discord.Embed(title="No comic found!")
Expand All @@ -106,7 +105,7 @@ def create_embed(comic_details: Optional[dict] = None):
value="Try another date / number!",
)

return embed
return embed


async def send_comic_info(
Expand Down Expand Up @@ -824,7 +823,6 @@ def remove_role(inter):

if gid in data:
if role in data[gid]:

data[gid].pop(role)
data[gid].pop(only_daily)

Expand Down Expand Up @@ -895,7 +893,6 @@ def get_sub_status(inter, position: int, database: Optional[dict] = None):
if guild_id in database:
guild_data = database[guild_id]
for channel in guild_data["channels"]:

if "latest" in guild_data["channels"][channel]:
if position in guild_data["channels"][channel]["latest"]:
return True
Expand Down Expand Up @@ -1247,7 +1244,6 @@ def clean_database(
to_remove = True
channels = data[guild]["channels"]
for chan in channels:

# Check if the channel has any latest comics scheduled
if "latest" in channels[chan]:
if len(channels[chan]["latest"]) != 0:
Expand Down
39 changes: 39 additions & 0 deletions bdbot/misc/comics_details.json
Original file line number Diff line number Diff line change
Expand Up @@ -595,5 +595,44 @@
"Color": "E8545A",
"Image": "https://avatar.amuniversal.com/feature_avatars/recommendation_images/features/sasc/mid_rec-201701251558.jpg",
"Helptxt": "Follow the funny life of Sarah Anderson where everyone can relate! "
},
"SpeedBump": {
"Name": "Speed Bump",
"Author": "Dave Coverly",
"Web_name": "speedbump",
"Main_website": "https://www.gocomics.com/",
"Working_type": "date",
"Description": "Dave Coverly admits there is no overriding theme, no tidy little philosophy that precisely describes what Speed Bump is about. \"Basically,\" he says, \"if life were a movie, these would be the outtakes.\"\nWebsite: https://www.speedbump.com/\nTwitter: http://twitter.com/speedbumpcomic\nAbout: https://www.gocomics.com/speedbump/about",
"Position": 46,
"First_date": "2002, 1, 1",
"Color": "DBCEAF",
"Image": "https://avatar.amuniversal.com/feature_avatars/ubadge_images/features/crspe/mid_u-201701251612.png",
"Helptxt": "Cartoons for idea people!"
},
"WallacetheBrave": {
"Name": "Wallace the Brave",
"Author": "Will Henry",
"Web_name": "wallace-the-brave",
"Main_website": "https://www.gocomics.com/",
"Working_type": "date",
"Description": "Welcome to Snug Harbor! Will Henry's \u201cWallace the Brave\u201d is a whimsical comic strip that centers around a bold and curious little boy named Wallace, his best friend Spud and the new girl in town, Amelia. Wallace lives in the quaint and funky town of Snug Harbor with his fisherman father, plant loving mother and feral little brother, Sterling.\nFacebook: http://facebook.com/WallacetheBrave/\nTwitter: http://twitter.com/MrWillHenry\nAbout: https://www.gocomics.com/wallace-the-brave/about",
"Position": 47,
"First_date": "2015, 6, 29",
"Color": "DCC7B5",
"Image": "https://avatar.amuniversal.com/feature_avatars/ubadge_images/features/wtb/mid_wtb_u_202204181313.png",
"Helptxt": "Follow the adventures of Wallace and his friends Spud and Amelia! "
},
"Ripley'sBelieveItorNot": {
"Name": "Ripley's Believe It or Not",
"Author": "Ripley's Believe It or Not!",
"Web_name": "ripleysbelieveitornot",
"Main_website": "https://www.gocomics.com/",
"Working_type": "date",
"Description": "Ripley's Believe It or Not! has been presenting the incredible and the unusual in illustrated form since Robert Ripley's first \"Champs and Chumps\" comic was published in the New York Globe on December 19, 1918. From there, Ripley set off to search the world for more incredibly hard to believe, but undeniably true stories to drawtraveling to 201 countries in 35 years.Today, artist Kieran Casta\u00f1o is the eighth cartoonist to take up the pen of this legacy panel. Kieran resides in Central Florida with his bird Rosie and pup Trini who can often be spotted in his work.\n\nSupporting Kieran is Ripley\u2019s Research Team, committed to finding the strangest stories, fact-checking sources, and filtering through the hundreds of weekly submissions that help bring this all-true cartoon to life. To submit your own Believe It or Not! fact, click here! \n\nDid you know the Ripley\u2019s cartoon has changed history in more ways than one? In a 1929 panel, Robert Ripley pointed out that America had no national anthem, which led to legislation making the Star Spangled Banner the county\u2019s official anthem!\n\nWebsite: https://www.ripleys.com/\nFacebook: http://facebook.com/RipleysBelieveItorNot\nTwitter: http://twitter.com/Ripleys\nAbout: https://www.ripleys.com/ripleys-attractions/",
"Position": 48,
"First_date": "1996, 1, 1",
"Color": "E91C2C",
"Image": "https://avatar.amuniversal.com/feature_avatars/ubadge_images/features/rp/mid_rp_u_202212280802.png",
"Helptxt": "The incredible and unusuals, all at the same place every day!"
}
}
28 changes: 16 additions & 12 deletions bdbot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@

from randomtimestamp import randomtimestamp

BASE_DATA_PATH = (
f"{os.getenv('LOCALAPPDATA')}/bdbot/"
PROD_DATA_PATH = (
os.path.join(os.getenv("LOCALAPPDATA"), "bdbot")
if os.name == "nt"
else f"/home/{os.getenv('USER')}/.local/bdbot/"
else os.path.join("home", os.getenv("USER"), ".local", "bdbot")
)
DETAILS_PATH = f"{BASE_DATA_PATH}misc/comics_details.json"
FOOTERS_FILE_PATH = f"{BASE_DATA_PATH}misc/random-footers.txt"
DATABASE_FILE_PATH = f"{BASE_DATA_PATH}data/data.json"
BACKUP_FILE_PATH = f"{BASE_DATA_PATH}data/backups/BACKUP_DATABASE_"
LOGS_DIRECTORY_PATH = f"{BASE_DATA_PATH}data/logs/"
REQUEST_FILE_PATH = f"{BASE_DATA_PATH}data/requests.txt"
COMIC_LATEST_LINKS_PATH = f"{BASE_DATA_PATH}data/latest_comics.json"
PID_FILE = f"{BASE_DATA_PATH}bdbot.pid"
ENV_FILE = f"{BASE_DATA_PATH}.env"
DEV_DATA_PATH = os.path.dirname(__file__)
BASE_DATA_PATH = PROD_DATA_PATH if not os.getenv("DEV") else DEV_DATA_PATH
MISC_PATH = os.path.join(BASE_DATA_PATH, "misc")
DATA_PATH = os.path.join(BASE_DATA_PATH, "data")
DETAILS_PATH = os.path.join(MISC_PATH, "comics_details.json")
FOOTERS_FILE_PATH = os.path.join(MISC_PATH, "random-footers.txt")
DATABASE_FILE_PATH = os.path.join(DATA_PATH, "data.json")
BACKUP_FILE_PATH = os.path.join(DATA_PATH, "backups", "BACKUP_DATABASE_")
LOGS_DIRECTORY_PATH = os.path.join(DATA_PATH, "logs/")
REQUEST_FILE_PATH = os.path.join(DATA_PATH, "requests.txt")
COMIC_LATEST_LINKS_PATH = os.path.join(BASE_DATA_PATH, "latest_comics.json")
PID_FILE = os.path.join(BASE_DATA_PATH, "bdbot.pid")
ENV_FILE = os.path.join(BASE_DATA_PATH, ".env")
date_tries = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su", "La"]
strip_details: dict = {}
link_cache: dict = {}
Expand Down
Loading

0 comments on commit 12d5c3d

Please sign in to comment.