11from __future__ import annotations
22
3+ import asyncio
34import dataclasses
45import inspect
56from typing import Literal , Optional , Union
@@ -146,7 +147,6 @@ async def set_command(
146147 self ,
147148 inter : disnake .GuildCommandInteraction ,
148149 option : str ,
149- value : str ,
150150 ) -> None :
151151 """
152152 [BETA] Edit the specified config option to the provided value.
@@ -164,6 +164,54 @@ async def set_command(
164164 if metadata .requires_bot :
165165 self .require_bot (inter )
166166
167+ # determine components
168+ label_component = []
169+ if metadata .type is bool :
170+ label_component = disnake .ui .StringSelect (
171+ custom_id = "value" ,
172+ options = [
173+ disnake .SelectOption (label = "Enabled" , value = "true" , default = old is True ),
174+ disnake .SelectOption (label = "Disabled" , value = "false" , default = old is False ),
175+ ],
176+ required = True ,
177+ max_values = 1 ,
178+ min_values = 1 ,
179+ )
180+ else :
181+ label_component = disnake .ui .TextInput (
182+ custom_id = "value" ,
183+ style = disnake .TextInputStyle .paragraph ,
184+ required = True ,
185+ value = old ,
186+ )
187+
188+ modal = disnake .ui .Modal (
189+ title = "Set Configuration Option" ,
190+ custom_id = f"config:set:{ option_name } :{ inter .id } " ,
191+ components = disnake .ui .Label (
192+ text = get_localised_response (inter , "{name}" , name = metadata .name ),
193+ description = get_localised_response (inter , "{name}" , name = metadata .description ),
194+ component = label_component ,
195+ ),
196+ )
197+
198+ await inter .response .send_modal (modal )
199+
200+ try :
201+ inter : disnake .ModalInteraction = await self .bot .wait_for (
202+ "modal_submit" ,
203+ check = lambda i : i .custom_id == f"config:set:{ option_name } :{ inter .id } "
204+ and i .author .id == inter .author .id
205+ and i .guild_id == inter .guild_id ,
206+ timeout = 300 ,
207+ )
208+ except asyncio .TimeoutError :
209+ return
210+
211+ value = inter .values ["value" ]
212+ if isinstance (value , list ):
213+ value = value [0 ]
214+
167215 try :
168216 # convert the value with the metadata.type
169217 param = inspect .Parameter (option_name , kind = inspect .Parameter .KEYWORD_ONLY )
@@ -277,35 +325,6 @@ async def clear_command(
277325 ephemeral = True ,
278326 )
279327
280- @set_command .autocomplete ("value" )
281- async def set_value_autocomplete (
282- self ,
283- inter : disnake .CommandInteraction ,
284- value : str ,
285- * ,
286- option : str = None ,
287- ) -> Union [dict [str , str ], list [str ]]:
288- """Show autocomplete for setting a config option."""
289- if not option :
290- return ["Please fill out the option parameter with a valid option." ]
291-
292- try :
293- metadata = METADATA [option ]
294- except KeyError :
295- try :
296- _ , metadata = await config_option (inter , option = option )
297- except commands .UserInputError :
298- return ["Please fill out the option parameter with a valid option." ]
299-
300- if metadata .type is bool :
301- return {
302- "Enabled" : "True" ,
303- "Disabled" : "False" ,
304- get_localised_response (inter , "{name}" , name = metadata .description ): "_" ,
305- }
306-
307- return [value or get_localised_response (inter , "{name}" , name = metadata .description )]
308-
309328 @set_command .autocomplete ("option" )
310329 @clear_command .autocomplete ("option" )
311330 @view_command .autocomplete ("option" )
0 commit comments