@@ -33,7 +33,6 @@ def __init__(self, api_connection):
3333
3434 self .about = ""
3535 self .owner = ""
36- self .hide_commands = ["start" ]
3736
3837 self .before_help = []
3938 self .after_help = []
@@ -43,6 +42,9 @@ def __init__(self, api_connection):
4342 self ._lang = ""
4443 self ._lang_inst = None
4544
45+ # Support for the old, deprecated bot.hide_commands
46+ self ._hide_commands = []
47+
4648 # Set the default language to english
4749 self .lang = "en"
4850
@@ -128,10 +130,11 @@ def __(func):
128130 return func
129131 return __
130132
131- def command (self , name ):
133+ def command (self , name , hidden = False ):
132134 """Register a new command"""
133135 def __ (func ):
134- self ._main_component .add_command (name , func , _from_main = True )
136+ self ._main_component .add_command (name , func , hidden ,
137+ _from_main = True )
135138 return func
136139 return __
137140
@@ -193,17 +196,11 @@ def freeze(self):
193196 chains = components .merge_chains (self ._main_component ,
194197 * self ._components )
195198
196- # Get the list of commands for the bot
197- commands = self ._components [- 1 ]._get_commands ()
198- for component in reversed (self ._components [:- 1 ]):
199- commands .update (component ._get_commands ())
200- commands .update (self ._main_component ._get_commands ())
201-
202199 return frozenbot .FrozenBot (self .api , self .about , self .owner ,
203- self .hide_commands , self .before_help ,
200+ self ._hide_commands , self .before_help ,
204201 self .after_help , self .process_backlog ,
205202 self .lang , self .itself , self ._commands_re ,
206- commands , chains , self ._scheduler ,
203+ self . _commands , chains , self ._scheduler ,
207204 self ._main_component ._component_id ,
208205 self ._bot_id , self ._shared_memory )
209206
@@ -220,15 +217,35 @@ def lang(self, lang):
220217 self ._lang_inst = utils .get_language (lang )
221218 self ._lang = lang
222219
223- def _get_commands (self ):
220+ @property
221+ def _commands (self ):
224222 """Get all the commands this bot implements"""
225- result = {}
226- for component in self ._components :
227- result .update (component ._get_commands ())
228- result .update (self ._main_component ._get_commands ())
223+ # This is marked as a property so the available_commands method becomes
224+ # dynamic (it's static on FrozenBot instead)
225+ commands = self ._components [- 1 ]._get_commands ()
226+ for component in reversed (self ._components [:- 1 ]):
227+ commands .update (component ._get_commands ())
228+ commands .update (self ._main_component ._get_commands ())
229229
230+ result = {}
231+ for name , command in commands .items ():
232+ result [name ] = command .for_bot (self )
230233 return result
231234
235+ # These functions allows to use the old, deprecated bot.hide_commands
236+
237+ @property
238+ @utils .deprecated ("bot.hide_commands" , "1.0" , "Use @bot.command(\" name\" , "
239+ "hidden=True) instead" )
240+ def hide_commands (self ):
241+ return self ._hide_commands
242+
243+ @hide_commands .setter
244+ @utils .deprecated ("bot.hide_commands" , "1.0" , "Use @bot.command(\" name\" , "
245+ "hidden=True) instead" , back = 1 )
246+ def hide_commands (self , value ):
247+ self ._hide_commands = value
248+
232249
233250def create (api_key , * args , ** kwargs ):
234251 """Create a new bot"""
0 commit comments