aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/help.py
blob: e64dce341290ed9fd0e929fd181510b58058cc46 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import discord
from discord.ext import commands
from discord import app_commands

from global_variables import BOT_COLOR, BOT_INVITE_LINK

commands_and_descriptions = {
    "play": {
        "description": "Plays the requested song",
        "arguments": {"query": "Name or link of the song you want to play"},
        "usage": "/play <query>",
    },
    "skip": {
        "description": "Skips the song that is currently playing",
        "optional_arguments": {
            "number": "The number of songs to skip - leave blank to skip just the current song"
        },
        "usage": "/skip (number)",
    },
    "queue": {
        "description": "Sends the songs currently added to the queue",
        "optional_arguments": {
            "page": "Page number of the queue to view - leave blank to see only the first page"
        },
        "usage": "/queue (page)",
    },
    "stop": {
        "description": "Stops all music, clears the queue, and leave the voice channel",
        "usage": "/stop",
    },
    "np": {"description": "Sends the song that is currently playing", "usage": "/np"},
    "clear": {"description": "Removes all songs from the queue", "usage": "/clear"},
    "remove": {
        "description": "Removes the specified song from the queue",
        "arguments": {
            "number": "The queue number of the song that should be removed from the queue"
        },
        "usage": "/remove <number>",
    },
    "autoplay": {
        "description": "Keep the music playing forever with music suggestions from OpenAI",
        "arguments": {
            "on": "Turn autoplay feature on",
            "off": "Turn autoplay feature off",
        },
        "usage": "/autoplay <on/off>",
    },
    "repeat": {
        "description": "Changes the looping state of the bot",
        "arguments": {
            "song": "Repeats the song that is currently playing until changed",
            "queue": "Continuously repeat the songs in the queue until turned off",
            "off": "Stop all song or queue repetition",
        },
        "usage": "/repeat <song/queue/off>",
    },
    "shuffle": {
        "description": "Turn song shuffling on or off",
        "arguments": {
            "on": "Turns randomized song shuffling on",
            "off": "Turns shuffling off",
        },
        "usage": "/shuffle <on/off>",
    },
    "bug": {
        "description": "Fill out a bug report form to alert the developer of issues",
        "usage": "/bug",
    },
    "feedback": {
        "description": "Fill out a form to give the developer feedback on the bot",
        "usage": "/feedback",
    },
}


class HelpView(discord.ui.View):
    def __init__(self, timeout=180.0):
        super().__init__(timeout=timeout)
        self.add_item(discord.ui.Button(label="Invite Me", url=BOT_INVITE_LINK, row=1))

    @discord.ui.button(
        label="View All Commands", style=discord.ButtonStyle.green, row=1
    )
    async def view_all_commands(
        self, interaction: discord.Interaction, button: discord.ui.Button
    ):
        embed = discord.Embed(
            title=":musical_note:  All Guava Commands  :musical_note:", color=BOT_COLOR
        )

        embed.add_field(
            name="All Commands",
            value=", ".join(
                [f"`{command}`" for command in commands_and_descriptions.keys()]
            ),
        )

        await interaction.response.edit_message(embed=embed, view=None)


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

    @app_commands.command()
    async def help(self, interaction: discord.Interaction, command: str = None):
        "Sends the bots commands"

        if command == None:
            embed = discord.Embed(
                title=f":musical_note:  Guava Help  :musical_note:", color=BOT_COLOR
            )

            embed.add_field(
                name="**Use Guava**",
                value="> To get started, use the </play:1224840890368000172> command and enter the name or link to the song of your choice.",
                inline=False,
            )
            embed.add_field(
                name="**Full Command List**",
                value='> To view of a list of all available commands, click the "View All Commands" button below.',
                inline=False,
            )
            embed.add_field(
                name="**Help for Specific Commands**",
                value="> If you want more information on how to use a specific command, use the </help:1224854217597124610> command and include the specific command.",
                inline=False,
            )

            embed.set_thumbnail(url=self.bot.user.avatar.url)

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

        elif command in commands_and_descriptions.keys():
            command = command.lower().strip()
            embed = discord.Embed(
                title=f"**{command}**",
                description=f"{commands_and_descriptions[command]['description']}",
                color=BOT_COLOR,
            )

            try:
                if commands_and_descriptions[command]["arguments"]:
                    arguments_value = ""
                    for argument, explanation in commands_and_descriptions[command][
                        "arguments"
                    ].items():
                        arguments_value += f"{argument}\n> {explanation}\n\n"

                    embed.add_field(
                        name="Arguments", value=arguments_value, inline=False
                    )
            except KeyError:
                pass

            try:
                if commands_and_descriptions[command]["optional_arguments"]:
                    arguments_value = ""
                    for argument, explanation in commands_and_descriptions[command][
                        "optional_arguments"
                    ].items():
                        arguments_value += f"{argument}\n> {explanation}\n\n"

                    embed.add_field(
                        name="Optional Arguments", value=arguments_value, inline=False
                    )
            except KeyError:
                pass

            embed.add_field(
                name="Usage", value=f"` {commands_and_descriptions[command]['usage']} `"
            )
            embed.set_thumbnail(url=self.bot.user.avatar.url)

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

        else:
            embed = discord.Embed(
                title="Command Doesn't Exist",
                description=f"The command you entered (` {command} `) does not exist, please try again with a different command name.",
                color=BOT_COLOR,
            )

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


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