|
4 | 4 | from discord import Message |
5 | 5 | from discord.ext import commands |
6 | 6 | from discord_slash import SlashCommand |
7 | | -from discord_slash.utils.manage_commands import create_option |
| 7 | +from discord_slash.utils.manage_commands import create_choice, create_option |
8 | 8 |
|
9 | 9 | import pymon_utils as utils |
10 | 10 |
|
|
27 | 27 | # Discord bot code |
28 | 28 | async def _react_on_mention(message: Message): |
29 | 29 | if client.user.mentioned_in(message) and not message.mention_everyone: |
30 | | - indices = utils.search(keyword_mapping, utils.generate_keywords(message.content)) |
| 30 | + indices = utils.search( |
| 31 | + keyword_mapping, utils.generate_keywords(message.content)) |
31 | 32 | if indices: |
32 | 33 | reply = list() |
33 | 34 | reply.extend([ |
@@ -110,6 +111,45 @@ async def _get(ctx, index: int): |
110 | 111 | await ctx.send(embed=embed) |
111 | 112 |
|
112 | 113 |
|
| 114 | +@slash.slash( |
| 115 | + name="study", |
| 116 | + description="Provides a study guide from a set of predetermined tags.", |
| 117 | + options=[ |
| 118 | + create_option( |
| 119 | + name="tag", |
| 120 | + description="Select a topic for your study guide.", |
| 121 | + required=True, |
| 122 | + option_type=3, |
| 123 | + choices=[ |
| 124 | + create_choice( |
| 125 | + value=tag, |
| 126 | + name=f"{tag} ({len(utils.get_queries_from_tag(queries, tag))})", |
| 127 | + ) |
| 128 | + for tag in sorted(utils.generate_tags_set(queries)) |
| 129 | + ] |
| 130 | + ) |
| 131 | + ] |
| 132 | +) |
| 133 | +async def _study(ctx, tag: str): |
| 134 | + """ |
| 135 | + Prints out a list of questions relevant to the tag. |
| 136 | +
|
| 137 | + :param ctx: the context to send messages to |
| 138 | + :return: None |
| 139 | + """ |
| 140 | + matches = utils.get_queries_from_tag(queries, tag) |
| 141 | + embed = discord.Embed( |
| 142 | + title=f"Pymon v{__version__}: Study Guide for {tag}", |
| 143 | + color=discord.Color.red(), |
| 144 | + description="\n".join( |
| 145 | + f"• ID-{match[0]}: {utils.create_md_link(match[1].get('resource'), match[1].get('query'))}" |
| 146 | + for match in matches |
| 147 | + ) |
| 148 | + ) |
| 149 | + |
| 150 | + await ctx.send(embed=embed) |
| 151 | + |
| 152 | + |
113 | 153 | @slash.slash( |
114 | 154 | name="refresh", |
115 | 155 | description="Refreshes the bot's knowledge base.", |
|
0 commit comments