aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/request.py
blob: 2ad71ba9199c08f327649d9c0f6d5841ea8ad665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import discord
from discord import app_commands
from discord.ext import commands
from typing import Literal

from utils.content_get import get_content
from utils.content_view import AddContentView
from utils.config import (
    RADARR_HOST_URL,
    RADARR_HEADERS,
    RADARR_ROOT_FOLDER_PATH,
    RADARR_QUALITY_PROFILE_ID,
    SONARR_HOST_URL,
    SONARR_HEADERS,
    SONARR_ROOT_FOLDER_PATH,
    SONARR_QUALITY_PROFILE_ID,
)


class Request(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @app_commands.command()
    @app_commands.describe(form="Are you requesting a Movie or Show?")
    @app_commands.describe(name="Name of the content")
    async def request(
        self,
        interaction: discord.Interaction,
        form: Literal["Movie", "Show"],
        name: str,
    ) -> None:
        """Request a movie or tv show to be added to the library"""
        # Get matching content from relevant service
        if form == "Movie":
            content_data = get_content(
                name, "radarr", RADARR_HOST_URL, RADARR_HEADERS
            )
        else:
            content_data = get_content(
                name, "sonarr", SONARR_HOST_URL, SONARR_HEADERS
            )

        if content_data == "NO RESULTS":
            embed = discord.Embed(
                title="No Results",
                description=(
                    # fmt: off
                    "No results found, please try again. Here are some tips:\n\n"
                    "1. Double check spelling\n"
                    "2. Add release year to the query\n"
                    "3. Double check the \"Movie\" or \"Show\" option"
                    # fmt: on
                ),
                color=0xD01B86,
            )
            return await interaction.response.send_message(
                embed=embed, ephemeral=True
            )

        if content_data == "ALREADY ADDED":
            embed = discord.Embed(
                title="Already Added",
                description=(
                    f"**{name}** is already added to the"
                    f" {'radarr' if form == 'Movie' else 'sonarr'} library. It"
                    " may be downloading, stalled, or not found. Check the"
                    " status of the content you have requested with"
                    " `/status`."
                ),
                color=0xD01B86,
            )
            return await interaction.response.send_message(
                embed=embed, ephemeral=True
            )

        embed = discord.Embed(
            title="Results Found",
            description=(
                f"Please select from the top {len(content_data)} results from"
                f" {'radarr' if form == 'Movie' else 'sonarr'} in the"
                " dropdown below."
            ),
            color=0xD01B86,
        )
        # Create view with the content data and relevant service info
        if form == "Movie":
            view = AddContentView(
                content_data,
                "radarr",
                RADARR_HOST_URL,
                RADARR_HEADERS,
                RADARR_ROOT_FOLDER_PATH,
                RADARR_QUALITY_PROFILE_ID,
            )
        else:
            view = AddContentView(
                content_data,
                "sonarr",
                SONARR_HOST_URL,
                SONARR_HEADERS,
                SONARR_ROOT_FOLDER_PATH,
                SONARR_QUALITY_PROFILE_ID,
            )

        await interaction.response.send_message(
            embed=embed, view=view, ephemeral=True
        )


async def setup(bot):
    await bot.add_cog(Request(bot))