@@ -26,18 +26,40 @@ class DocsCommandDefaultProjects:
26
26
def __init__ (self ):
27
27
self .projects = get_json (url = 'https://app.lizardbyte.dev/dashboard/readthedocs/projects.json' )
28
28
self .projects_options = []
29
+ # Track used values to prevent duplicates
30
+ used_values = set ()
31
+ self .value_to_project_map = {}
32
+
33
+ counter = 0
29
34
for project in self .projects :
30
35
try :
31
36
parent_project = project ['subproject_of' ]['name' ]
32
37
except (KeyError , TypeError ):
33
38
parent_project = None
34
39
40
+ # Extract repository name to use as value
41
+ original_value = project ['repository' ]['url' ].rsplit ('/' , 1 )[- 1 ].rsplit ('.git' , 1 )[0 ]
42
+ value = original_value
43
+
44
+ # make sure the value is unique
45
+ value = f"{ original_value } -{ counter } "
46
+
47
+ # Add to used values set
48
+ used_values .add (value )
49
+
50
+ # Store mapping of modified value to original project identifier
51
+ self .value_to_project_map [value ] = original_value
52
+
35
53
self .projects_options .append (
36
- discord .SelectOption (label = project ['name' ],
37
- value = project ['repository' ]['url' ].rsplit ('/' , 1 )[- 1 ].rsplit ('.git' , 1 )[0 ],
38
- description = f"Subproject of { parent_project } " if parent_project else None )
54
+ discord .SelectOption (
55
+ label = project ['name' ],
56
+ value = value ,
57
+ description = f"Subproject of { parent_project } " if parent_project else None
58
+ )
39
59
)
40
60
61
+ counter += 1
62
+
41
63
42
64
class DocsCommandView (discord .ui .View ):
43
65
"""
@@ -62,8 +84,12 @@ def __init__(self, ctx: discord.ApplicationContext):
62
84
self .docs_project = None
63
85
self .docs_version = None
64
86
87
+ # Create projects and store the mapping
88
+ projects_handler = DocsCommandDefaultProjects ()
89
+ self .project_value_map = projects_handler .value_to_project_map
90
+
65
91
# reset the first select menu because it remembers the last selected value
66
- self .children [0 ].options = DocsCommandDefaultProjects () .projects_options
92
+ self .children [0 ].options = projects_handler .projects_options
67
93
68
94
# check selections completed
69
95
def check_completion_status (self ) -> Tuple [bool , discord .Embed ]:
@@ -175,7 +201,10 @@ async def callback(self, select: Select, interaction: discord.Interaction):
175
201
child .options = [discord .SelectOption (label = '0' )]
176
202
177
203
if child == self .children [1 ]: # choose docs version
178
- readthedocs = self .children [0 ].values [0 ]
204
+ selected_value = self .children [0 ].values [0 ]
205
+
206
+ # Get the original project identifier from the mapping
207
+ readthedocs = self .project_value_map .get (selected_value , selected_value )
179
208
180
209
versions = get_json (
181
210
url = f'https://app.lizardbyte.dev/dashboard/readthedocs/versions/{ readthedocs } .json' )
@@ -189,7 +218,7 @@ async def callback(self, select: Select, interaction: discord.Interaction):
189
218
description = f"Docs for { version ['slug' ]} { version ['type' ]} "
190
219
))
191
220
192
- child .options = options
221
+ child .options = options [: 25 ] # limit to 25 options
193
222
194
223
index += 1
195
224
0 commit comments