summaryrefslogtreecommitdiff
path: root/commands/movie.py
diff options
context:
space:
mode:
Diffstat (limited to 'commands/movie.py')
-rw-r--r--commands/movie.py44
1 files changed, 31 insertions, 13 deletions
diff --git a/commands/movie.py b/commands/movie.py
index b7be8cd..256156f 100644
--- a/commands/movie.py
+++ b/commands/movie.py
@@ -12,13 +12,12 @@
from telegram import Update, error
from telegram.ext import ContextTypes
from imdb import Cinemagoer
-from pprint import pformat
-
-from utils import context_init
+from utils import context_init, choose_next_user
+from predicates import has_finished_event
from strings import MOVIE_NOT_PROVIDED, EXPECTED_ONE_MOVIE, \
MOVIE_ANOTHER_USER, FETCHING_MOVIE, FETCHING_ERROR, \
- MOVIE_REMOVE, MOVIE_SET
+ MOVIE_REMOVE, MOVIE_SET, MOVIES_LIST, NO_MOVIES, ADD_MORE_USERS
imdb = Cinemagoer()
@@ -30,9 +29,18 @@ async def movie(
) -> None:
context_init(context)
- chooser = context.chat_data["users"][0] or None
+ users = context.chat_data["users"]
+
+ if users == []:
+ raise error.TelegramError(ADD_MORE_USERS)
+
+ chooser = users[0]
username = update.message.from_user.username
+ if has_finished_event(context, chooser):
+ users = context.chat_data["users"] = choose_next_user(users)
+ raise error.TelegramError(MOVIE_ANOTHER_USER.format(users[0]))
+
if "@"+username != chooser:
raise error.TelegramError(MOVIE_ANOTHER_USER.format(user=chooser))
@@ -50,12 +58,15 @@ async def movie(
movie = imdb.get_movie(movie_id)
except:
raise error.TelegramError(FETCHING_ERROR)
-
+
movie_dict = dict(
title=movie.data.get("title"),
id=movie.getID(),
user=update.effective_user.username,
- poster=movie.data.get("cover url")
+ poster=movie.data.get("cover url"),
+ rating=movie.data.get("rating"),
+ genres=movie.data.get("genres"),
+ runtime=movie.data.get("runtimes"),
)
if len(context.chat_data["movies"]) > 0 and \
@@ -75,13 +86,21 @@ async def movies(
) -> None:
context_init(context)
- movies = context.chat_data["movies"].copy()
+ movies = context.chat_data["movies"]
+
+ movies_formatted: str = ""
for movie in movies:
- if movie["poster"] or None:
- del movie["poster"]
+ movies_formatted += MOVIES_LIST.format(
+ title=movie["title"],
+ id=movie["id"],
+ user=movie["user"]
+ )
- await update.message.reply_text(pformat(movies))
+ if movies_formatted == "":
+ movies_formatted = NO_MOVIES
+
+ await update.message.reply_text(movies_formatted)
async def remove_movies(
@@ -100,6 +119,5 @@ async def remove_movies(
if movie["id"] == movie_id:
context.chat_data["movies"].remove(movie)
await update.message.reply_text(
- MOVIE_REMOVE.format(title=movie["title"], id=["movie.id"])
+ MOVIE_REMOVE.format(title=movie["title"], id=movie["id"])
)
-