-
Notifications
You must be signed in to change notification settings - Fork 3
Write a command
Create a new file with the name helloworld.py in the modules directory.
If you already know how to approach this, go on. If not, you can copy this code:
import lib.cmd
@lib.cmd.command(private=False, alias=['hello'])
def helloworld(msg):
"""My first command!."""
return 'Hello World! Echo: %s' % msg.paramsThe first line imports the library containing the decorator which makes the function a command. Line 3 actually declares the function as a command. The optional arguments tell qllbot to disallow usage of this command in private messages and to give access to this command under the alias "hello". The two possible invocations are #helloworld (function name) and #hello (alias). Note that the private parameter is True by default.
What does the command actually do? It receives a CommandMessage object (found in lib/cmd.py) and returns a dynamic string. The msg.params property contains all parameters to the command. Hence, calling the command with a parameter will echo it back:
<qll> #hello test
<qllbot> Hello World! Echo: test
The docstring will be read by the #help command:
<qll> #help hello
<qllbot> #hello: My first command!.
Now that we know how to write simple commands, let's take a look at event listeners:
Write an eventlistener