@@ -55,30 +55,60 @@ async def _slash(ctx): # Normal usage.
55
55
async def _pick(ctx, choice1, choice2): # Command with 1 or more args.
56
56
await ctx.send(text=str(random.choice([choice1, choice2])))
57
57
58
+ Example of formatting ``auto_convert``:
59
+
60
+ .. code-block:: python
61
+
62
+ {"option_role": "role", # For key put name of the option and for value put type of the option.
63
+ "option_user": 6, # Also can use number for type
64
+ "option_channel": "CHANNEL"} # and all upper case.
65
+
58
66
:param name: Name of the slash command.
59
- :param auto_convert: Not implemented .
67
+ :param auto_convert: Dictionary of how to convert option values .
60
68
:type auto_convert: dict
61
69
"""
62
70
def wrapper (cmd ):
63
- self .commands [cmd .__name__ if not name else name ] = cmd
71
+ self .commands [cmd .__name__ if not name else name ] = [ cmd , auto_convert ]
64
72
self .logger .debug (f"Added command `{ cmd .__name__ if not name else name } `" )
65
73
return cmd
66
74
return wrapper
67
75
68
- def process_options (self , options : dict ) -> list :
76
+ def process_options (self , guild : discord . Guild , options : list , auto_convert : dict ) -> list :
69
77
"""
70
- Not ready .
78
+ Processes Role, User, and Channel option types to discord.py's models .
71
79
80
+ :param guild: Guild of the command message.
81
+ :type guild: discord.Guild
72
82
:param options: Dict of options.
73
- :type options: dict
83
+ :type options: list
84
+ :param auto_convert: Dictionary of how to convert option values.
85
+ :type auto_convert: dict
74
86
:return: list
75
- :raises: :class:`NotImplementedError` - This is still not implemented.
76
87
"""
77
- raise NotImplementedError
88
+ converters = [guild .get_member , guild .get_role , guild .get_role ]
89
+ types = {
90
+ "user" : 0 ,
91
+ "USER" : 0 ,
92
+ 6 : 0 ,
93
+ "6" : 0 ,
94
+ "channel" : 1 ,
95
+ "CHANNEL" : 1 ,
96
+ 7 : 1 ,
97
+ "7" : 1 ,
98
+ "role" : 2 ,
99
+ "ROLE" : 2 ,
100
+ 8 : 2 ,
101
+ "8" : 2
102
+ }
103
+
104
+ to_return = []
78
105
79
106
for x in options :
80
- pass
81
- return []
107
+ selected = x
108
+ if selected ["name" ] in auto_convert .keys ():
109
+ loaded_converter = converters [types [auto_convert [selected ["name" ]]]]
110
+ to_return .append (loaded_converter (int (selected ["value" ])))
111
+ return to_return
82
112
83
113
async def on_socket_response (self , msg ):
84
114
"""
@@ -93,6 +123,7 @@ async def on_socket_response(self, msg):
93
123
return
94
124
to_use = msg ["d" ]
95
125
if to_use ["data" ]["name" ] in self .commands .keys ():
96
- args = [ x [ "value" ] for x in to_use ["data" ]["options" ]] if "options" in to_use [ "data" ] else [ ]
126
+ selected_cmd = self . commands [ to_use ["data" ]["name" ] ]
97
127
ctx = model .SlashContext (self .req , to_use , self ._discord )
98
- await self .commands [to_use ["data" ]["name" ]](ctx , * args )
128
+ args = self .process_options (ctx .guild , to_use ["data" ]["options" ], selected_cmd [1 ]) if "options" in to_use ["data" ] else []
129
+ await selected_cmd [0 ](ctx , * args )
0 commit comments