diff options
Diffstat (limited to 'bot')
-rw-r--r-- | bot/exts/holidays/halloween/scarymovie.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/bot/exts/holidays/halloween/scarymovie.py b/bot/exts/holidays/halloween/scarymovie.py index 74bcef90..442ed4a5 100644 --- a/bot/exts/holidays/halloween/scarymovie.py +++ b/bot/exts/holidays/halloween/scarymovie.py @@ -5,7 +5,7 @@ from discord import Embed from discord.ext import commands from bot.bot import Bot -from bot.constants import Tokens +from bot.constants import Colours, NEGATIVE_REPLIES, Tokens log = logging.getLogger(__name__) @@ -21,6 +21,13 @@ class ScaryMovie(commands.Cog): """Randomly select a scary movie and display information about it.""" async with ctx.typing(): selection = await self.select_movie() + if not selection: + await ctx.send(embed=Embed( + title=random.choice(NEGATIVE_REPLIES), + description=f":warning: Failed to select a movie from the API", + color=Colours.soft_red + )) + return movie_details = await self.format_metadata(selection) await ctx.send(embed=movie_details) @@ -44,10 +51,17 @@ class ScaryMovie(commands.Cog): total_pages = data.get("total_pages") # Get movie details from one random result on a random page - params["page"] = random.randint(1, total_pages) + params["page"] = max(random.randint(1, total_pages), 500) async with self.bot.http_session.get(url=url, params=params, headers=headers) as response: data = await response.json() - selection_id = random.choice(data.get("results")).get("id") + if (results := data.get("results")) is None: + log.warning(f"Failed to select a movie - data returned from API has no 'results' key") + return {} + selection_id = random.choice(results).get("id") + if selection_id is None: + log.warning(f"Failed to select a movie - selected film didn't have an id") + return {} + # Get full details and credits async with self.bot.http_session.get( |