Skip to content
nemunaire edited this page Sep 8, 2014 · 4 revisions

Nemubot consists of two major parts: a strong kernel containing a lot of usefull functionnalities, and a cloud of modules that provides intelligence to the bot.

Configure nemubot

Make sure your configuration file is correct. Try nemubot by writing on a channel it listens: nemubot: ping where nemubot is the nickname of your bot, choosen in the configuration file. It will respond you you: pong where you is your nickname.

Create files

First, go into the modules directory and create a new file named hello.py. hello will be the name of the module, to load it later, you will use this name.

Edit the file hello.py with your favorite editor:

"""Hello module"""

nemubotversion = 3.4

@hook("cmd_hook", "hello")
def receive_hello(msg):
    return Response(msg.sender, "Hello world!", channel=msg.channel)

With this code, nemubot will respond on the same channel as the one where the command !hello has been sent.

The first line is a basic description about the module. It will be display when the command !help is used to list modules.

The second line tells to the core which was the version the module was designed for. If this line is not present, it is assumed that is not a nemubot module, so the module will fail to load.

The line: @hook("cmd_hook", "hello") registers a command hook, the first argument is the hook's type, the second is the name of the command (for !hello, the name is hello).

When a hook is called, one argument is given: the message that match the hook.

The last line return a Response, a class for send back message to the channel or the user.

Load the module

Now type on the nemubot prompt: load hello. If your module is correct, nemubot displays:

Modulehello' successfully added.`

If something is wrong, a Python error message is shown. Try to fix it, and retype the same command.

Congratulations, you just made your first module :)

Hello world on first messages

Now you can send a private message to every new user speaking on a channel:

nemubotversion = 3.4

known_users = list()

@hook("msg_default")
def parselisten(msg):
  if msg.sender not in known_users:
    known_users.append(msg.sender)
	return Response(msg.sender, "Hello world!")

If you have added the code in the hello module, just type load hello on the prompt. The code will be refreshed.

Then, speak on a channel where nemubot listens. You will receive a private message when you speak for the first time.

If you reload the module (with the load command), nemubot will send you a private message again. See the next chapter: Preserve data between sessions to avoid this.