shellbot.commands.base module¶
-
class
shellbot.commands.base.
Command
(engine=None, **kwargs)[source]¶ Bases:
object
Implements one command
-
execute
(bot, arguments=None, **kwargs)[source]¶ Executes this command
Parameters: - bot (Shellbot) – The bot for this execution
- arguments (str or
None
) – The arguments for this command
The function is invoked with a variable number of arguments. Therefore the need for
**kwargs
, so that your code is safe in all cases.The recommended signature for commands that handle textual arguments is the following:
``` def execute(self, bot, arguments=None, **kwargs):
... if arguments:
...In this situation,
arguments
contains all text typed after the verb itself. For example, when the commandmagic
is invoked with the string:magic rub the lamp
then the related command instance is called like this:
magic = shell.command('magic') magic.execute(bot, arguments='rub the lamp')
For commands that can handle file attachments, you could use following approach:
def execute(self, bot, arguments=None, attachment=None, url=None, **kwargs): ... if url: # a document has been uploaded with this command content = bot.space.download_attachment(url) ...
Reference information on parameters provided by the shell:
bot
- This is the bot instance for which the command is executed. From this you can update the chat withbot.say()
, or access data attached to the bot inbot.store
. The engine and all global items can be access withbot.engine
.arguments
- This is a string that contains everything after the command verb. Whenhello How are you doing?
is submitted to the shell,hello
is the verb, andHow are you doing?
are the arguments. This is the regular case. If there is no commandhello
then the command*default
is used instead, and arguments provided are the full linehello How are you doing?
.attachment
- When a file has been uploaded, this attribute provides its external name, e.g.,picture024.png
. This can be used in the executed command, if you keep in mind that the same name can be used multiple times in a conversation.url
- When a file has been uploaded, this is the handle by which actual content can be retrieved. Usually, ask the underlying space to get a local copy of the document.
This function should report on progress by sending messages with one or multiple
bot.say("Whatever response")
.
-
in_direct
= True¶
-
in_group
= True¶
-
information_message
= None¶
-
keyword
= None¶
-
on_init
()[source]¶ Handles extended initialisation
This function should be expanded in sub-class, where necessary.
Example:
def on_init(self): self.engine.register('stop', self)
-
usage_message
= None¶
-