Skip to content

Commit

Permalink
better movie menu
Browse files Browse the repository at this point in the history
  • Loading branch information
psykzz authored Dec 28, 2024
1 parent 09d14d2 commit 52a1142
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions movie_vote/movie_vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import httpx
from imdb import Cinemagoer
from redbot.core import Config, checks, commands
from redbot.core.utils.menus import menu

imdb = Cinemagoer()
RE_IMDB_LINK = re.compile(r"(https:\/\/www\.imdb\.com\/title\/tt\d+)")
Expand Down Expand Up @@ -248,27 +249,47 @@ async def _movievote_next(self, ctx):

await ctx.reply(embed=embed)

@movie.command(name="pinboard")
async def _movievote_pinboard(self, ctx):
"""
Get the movie pinboard.
The pinboard will be updated each time a movie is added or removed from the list and show the top 5 movies next to be watched.
"""

movies = await self.config.guild(ctx.guild).movies()
if not movies:
await ctx.send("No movies in the list.")
return

embed = await self.generate_leaderboard(ctx.guild, 5, True)
leaderboard = await ctx.send(embed=embed)
await leaderboard.pin()

leaderboard_id = await self.config.guild(message.guild).leaderboard()
if leaderboard_id:
leaderboard_msg = await message.channel.fetch_message(leaderboard_id)
await leaderboard_msg.unpin()
await leaderboard_msg.delete()

# Save the leaderboard message ID so we can edit it later
await self.config.guild(ctx.guild).leaderboard.set(leaderboard.id)

@movie.command(name="leaderboard")
async def _movievote_leaderboard(self, ctx, limit: int|str = 5, watched_only: bool = True, will_pin = False):
async def _movievote_leaderboard(self, ctx, watched_only = True):
"""
Get the movie leaderboard.
The leaderboard will be updated each time a movie is added or removed from the list.
"""

movies = await self.config.guild(ctx.guild).movies()
if not movies:
await ctx.send("No movies in the list.")
return

if limit == "all":
limit = 99999

embed = await self.generate_leaderboard(ctx.guild, limit, watched_only)
leaderboard = await ctx.send(embed=embed)
# filter out movies that have been watched
if watched_only:
movies = [movie for movie in movies if not movie.get("watched", False)]

if will_pin:
# Save the leaderboard message ID so we can edit it later
await self.config.guild(ctx.guild).leaderboard.set(leaderboard.id)
await menu(ctx, [f"{movie['title']} ({movie['year']}) | https://www.imdb.com/title/tt{movie['imdb_id']}" for m in movies])


@commands.Cog.listener()
Expand Down

0 comments on commit 52a1142

Please sign in to comment.