diff --git a/src/filman_discord/Dockerfile b/src/filman_discord/Dockerfile index 449bd19..8b8d168 100644 --- a/src/filman_discord/Dockerfile +++ b/src/filman_discord/Dockerfile @@ -1,3 +1,22 @@ +# FROM python:3.11-alpine + +# RUN apk update && apk add --no-cache \ +# gcc \ +# musl-dev \ +# libffi-dev \ +# openssl-dev \ +# mariadb-dev \ +# build-base + +# WORKDIR /src/filman_discord + +# COPY requirements.txt requirements.txt +# RUN pip install --no-cache-dir -r requirements.txt + +# COPY /src/filman_discord . + +# CMD [ "python3", "-OO", "main.py"] + FROM python:3.11-alpine RUN apk update && apk add --no-cache \ @@ -13,6 +32,8 @@ WORKDIR /src/filman_discord COPY requirements.txt requirements.txt RUN pip install --no-cache-dir -r requirements.txt -COPY /src/filman_discord . +COPY src /src + +ENV PYTHONPATH=/src -CMD [ "python3", "-OO", "main.py"] \ No newline at end of file +CMD ["python3", "-OO", "main.py"] \ No newline at end of file diff --git a/src/filman_discord/endpoints/filmweb.py b/src/filman_discord/endpoints/filmweb.py index b378184..9afa6c4 100644 --- a/src/filman_discord/endpoints/filmweb.py +++ b/src/filman_discord/endpoints/filmweb.py @@ -5,6 +5,7 @@ import logging + tracker_plugin = lightbulb.Plugin("Filmweb") @@ -331,62 +332,7 @@ async def cancel_subcommand(ctx: lightbulb.SlashContext) -> None: return -# https://www.reddit.com/r/Discordjs/comments/10377qg/adding_the_possibility_to_mention_multiple_users/ -# https://hikari-lightbulb.readthedocs.io/en/2.3.5/api_references/decorators.html#lightbulb.decorators.option - -# @tracker_group.child -# @lightbulb.option("users", "Wymień użytkowników, np. @User1 @User2", type=str, required=True) -# @lightbulb.command("w2s", "wylosuj film z listy chcę obejrzeć dla użytkownika/użytkowników", pass_options=True) -# @lightbulb.implements(lightbulb.SlashSubCommand) -# async def w2s_subcommand(ctx: lightbulb.SlashContext, users: str) -> None: -# mentions = ctx.options.users.split() -# user_ids = [] - -# for mention in mentions: -# if mention.startswith("<@") and mention.endswith(">"): -# mention = mention.strip("<@!>") -# if mention.isdigit(): -# user_ids.append(int(mention)) - -# if not user_ids: -# await ctx.respond("Nie podano żadnych prawidłowych oznaczeń użytkowników.") -# return - -# response = f"Oznaczono {len(user_ids)} użytkowników:\n" + "\n".join(f"<@{uid}>" for uid in user_ids) -# await ctx.respond(response) - - -# @tracker_group.child -# @lightbulb.option("user5", "Piąty użytkownik (opcjonalny)", type=hikari.User, required=False) -# @lightbulb.option("user4", "Czwarty użytkownik (opcjonalny)", type=hikari.User, required=False) -# @lightbulb.option("user3", "Trzeci użytkownik (opcjonalny)", type=hikari.User, required=False) -# @lightbulb.option("user2", "Drugi użytkownik (opcjonalny)", type=hikari.User, required=False) -# @lightbulb.option("user1", "Pierwszy użytkownik (wymagany)", type=hikari.User, required=True) -# @lightbulb.command("w2s", "wylosuj film z listy chcę obejrzeć dla użytkownika/użytkowników", pass_options=True) -# @lightbulb.implements(lightbulb.SlashCommand) -# async def w2s_subcommand( -# ctx: lightbulb.SlashContext, -# user1: hikari.User, -# user2: hikari.User = None, -# user3: hikari.User = None, -# user4: hikari.User = None, -# user5: hikari.User = None, -# ) -> None: -# response = f"Oznaczono {len([user1, user2, user3, user4, user5])} użytkowników:\n" + "\n".join( -# f"{user.mention}" for user in [user1, user2, user3, user4, user5] -# ) -# await ctx.respond(response) - -# TODO: add logic to process users in utils -# from src.filman_discord.utils.w2s_logic import process_users - - # users = [user1, user2, user3, user4, user5] - # await ctx.respond("Przetwarzanie...") - - # response = await process_users(users) - # await ctx.edit_last_response(response) - - +# todo: draw within common friends list @tracker_group.child @lightbulb.option("user5", "Piąty użytkownik (opcjonalny)", type=hikari.User, required=False) @lightbulb.option("user4", "Czwarty użytkownik (opcjonalny)", type=hikari.User, required=False) @@ -409,9 +355,13 @@ async def w2s_subcommand( response = f"Oznaczono {len(mentioned_users)} użytkowników:\n" + "\n".join(mentioned_users) await ctx.respond("Przetwarzanie...") - await asyncio.sleep(5) + logging.debug(f"Processing users: {users}") + + from filman_discord.utils.filmweb_w2s_logic import process_users + + + await ctx.edit_last_response(await process_users(users)) - await ctx.edit_last_response(response) @tracker_group.child @lightbulb.command("test", "Testowa komenda", pass_options=True) @@ -420,6 +370,5 @@ async def test_command(ctx: lightbulb.SlashContext) -> None: await ctx.respond("Działa!") - def load(bot: lightbulb.BotApp) -> None: bot.add_plugin(tracker_plugin) diff --git a/src/filman_discord/endpoints/info.py b/src/filman_discord/endpoints/info.py index 355f3b3..e9c78ba 100644 --- a/src/filman_discord/endpoints/info.py +++ b/src/filman_discord/endpoints/info.py @@ -14,7 +14,7 @@ async def info_command(ctx: lightbulb.SlashContext) -> None: embed.add_field( name="Wersja i ostatnia aktualizacja", - value="`1.1.8t dev` - `2024-12-27`", + value="`1.1.8t dev` - `2025-01-03`", ) embed.add_field( diff --git a/src/filman_discord/utils/filmweb_w2s_logic.py b/src/filman_discord/utils/filmweb_w2s_logic.py new file mode 100644 index 0000000..cd91bb2 --- /dev/null +++ b/src/filman_discord/utils/filmweb_w2s_logic.py @@ -0,0 +1,52 @@ +import asyncio +import random +import requests +import logging +import hikari + +logger = logging.getLogger(__name__) + +async def process_users(users): + mentioned_users = [user.mention for user in users if user is not None] + response = f"Mentioned {len(mentioned_users)} users:\n" + "\n".join(mentioned_users) + + logger.debug(f"Users: {mentioned_users}") + + filmweb_ids = {} + for user in users: + if user is not None: + logger.debug(f"Fetching Filmweb ID for user: {user.id}") + r = requests.get(f"http://filman_server:8000/filmweb/user/mapping/get", params={"discord_id": user.id}) + if r.status_code == 200: + filmweb_id = r.json().get("filmweb_id") + if filmweb_id: + filmweb_ids[filmweb_id] = user + logger.debug(f"Found Filmweb ID: {filmweb_id} for user: {user.id}") + else: + logger.warning(f"No Filmweb ID found for user: {user.id}") + else: + logger.error(f"Error fetching Filmweb ID for user: {user.id}, status: {r.status_code}") + + movies_to_watch = [] + for filmweb_id, user in filmweb_ids.items(): + logger.debug(f"Fetching list of movies to watch for Filmweb ID: {filmweb_id}") + r = requests.get(f"https://www.filmweb.pl/api/v1/user/{filmweb_id}/want2see/film") + if r.status_code == 200: + movie_entities = r.json() + for movie in movie_entities: + movie_id = movie.get("entity") + movie_url = f"https://www.filmweb.pl/film/x-1-{movie_id}" + movies_to_watch.append((movie_url, user)) + logger.debug(f"Added movie to list: {movie_url} from user: {user.id}") + else: + logger.error(f"Error fetching list of movies for Filmweb ID: {filmweb_id}, status: {r.status_code}") + + if movies_to_watch: + selected_movie, selected_user = random.choice(movies_to_watch) + response += f"\n\nSelected movie: {selected_movie} from {selected_user.mention}'s list" + logger.info(f"Selected movie: {selected_movie} from {selected_user.id}'s list") + else: + response += "\n\nNo movies found to watch." + logger.warning("No movies found to watch.") + + return response \ No newline at end of file