Skip to content

Commit

Permalink
Fix numerous bugs and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
joinemm committed Sep 16, 2024
1 parent 01db764 commit 35e6009
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cogs/errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def reinvoke_command(self, ctx: commands.Context):
if ctx.guild is not None:
await queries.save_command_usage(ctx)
return
except commands.CommandError as e:
except Exception as e:
return await self.on_command_error(ctx, e)

@staticmethod
Expand All @@ -70,7 +70,7 @@ async def send_embed(
try:
await ctx.send(
embed=discord.Embed(
description=f"{emoji} {message}",
description=f"{emoji} {message[:1500]}",
color=int(color, 16) if color else None,
),
**kwargs,
Expand Down
7 changes: 4 additions & 3 deletions cogs/kpop.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,10 @@ async def send_group(self, ctx: commands.Context, group_id):
""",
group_id,
)
content.add_field(
name="Members", value=", ".join(x[0] for x in member_list), inline=False
)
if member_list:
content.add_field(
name="Members", value=", ".join(x[0] for x in member_list), inline=False
)

if image_url is None or (today - image_scrape_date.date).days > 30:
search_term = f"{name} kpop group"
Expand Down
5 changes: 4 additions & 1 deletion cogs/lastfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,10 @@ async def colorchart(
chart_nodes = []

data = await self.get_all_albums(ctx.lfm.username)
albums = [LastFmImage.from_url(a["image"][-1]["#text"]) for a in data]
albums = filter(
lambda x: not x.is_missing(),
[LastFmImage.from_url(a["image"][-1]["#text"]) for a in data],
)

to_fetch = []
albumcolors = await self.bot.db.fetch(
Expand Down
19 changes: 12 additions & 7 deletions modules/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,18 @@ async def try_media(self, shortcode: str) -> list:
async def get_post(self, shortcode: str):
text = await self.request(f"{self.BASE_URL}/p/{shortcode}")
soup = BeautifulSoup(text, "lxml")
metadata = {
"url": soup.find("a").attrs["href"],
"description": soup.find("meta", {"property": "og:description"}).attrs[
"content"
],
"username": soup.find("meta", {"name": "twitter:title"}).attrs["content"],
}
try:
metadata = {
"url": soup.find("a").attrs["href"],
"description": soup.find("meta", {"property": "og:description"}).attrs[
"content"
],
"username": soup.find("meta", {"name": "twitter:title"}).attrs[
"content"
],
}
except AttributeError:
raise InstagramError("There was a problem fetching media for this post")

media = await self.try_media(shortcode)

Expand Down
6 changes: 6 additions & 0 deletions modules/media_embedders.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ async def create_message(
):
instafix = InstaFix(self.bot.session)
embedez = EmbedEz(self.bot.session)
error = None

for provider in [instafix, embedez]:
try:
Expand Down Expand Up @@ -427,10 +428,15 @@ async def create_message(
results = await asyncio.gather(*tasks)
except (InstagramError, DownloadError) as e:
logger.warning(f"{provider} failed with {e}")
error = e
continue
else:
error = None
break

if error is not None:
raise error

if post.user.name:
caption = f"{self.EMOJI} **{post.user.name}** `@{post.user.username}`"
else:
Expand Down
5 changes: 4 additions & 1 deletion modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ async def run(self, context: discord.abc.Messageable):
async def on_timeout(self):
self.on_arrow_forward.disabled = True
self.on_arrow_backward.disabled = True
await self.message.edit(view=self)
try:
await self.message.edit(view=self)
except discord.NotFound:
pass
self.stop()


Expand Down
4 changes: 2 additions & 2 deletions sql/init/1_kpop_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS kpop_group (
orig_members INT,
fanclub VARCHAR(64),
active ENUM('Yes', 'No', 'Hiatus'),
image_url VARCHAR(256),
image_url VARCHAR(1024),
image_scrape_date DATETIME,
PRIMARY KEY (group_id)
);
Expand All @@ -40,7 +40,7 @@ CREATE TABLE IF NOT EXISTS kpop_idol (
position VARCHAR(64),
instagram VARCHAR(64),
twitter VARCHAR(64),
image_url VARCHAR(256),
image_url VARCHAR(1024),
image_scrape_date DATETIME,
UNIQUE(group_name, stage_name),
PRIMARY KEY (idol_id)
Expand Down

0 comments on commit 35e6009

Please sign in to comment.