Skip to content
gdamjan edited this page Mar 4, 2011 · 5 revisions

I currently run the bot in a Ubuntu 9.10 virtual machine, connected to freenode (the nickname is erlbot--).

I'm running it with the help of runit and a small escript. Runit solves the problem of restarting the bot if it fails, and also captures stdout and stderr in a log file.

In the directory of the bot (a clone of this git repo), I've created a service subdirectory, and there I have the runit run script:

#!/bin/sh
exec 2>&1
export HOME=/home/damjan
cd ..
export ERL_LIBS=$PWD/deps
exec chpst -udamjan ./run.e

the service subdir is linked from runit's /etc/service/ directory. Since the bot has a plugin to log to a couchdb database, I've also installed couchbeam and its dependencies in the deps/ directory in the bot source, so that's why I need to have ERL_LIBS exported.

The ./run.e escript start the application and registers the bot so that it's available in a remote shell:

%% -*- erlang -*-
%%! -boot start_sasl -pa ebin -sname ircbot@localhost
main([]) ->
    main(["settings.cfg"]);

main([Filename]) ->
    io:setopts([{encoding, unicode}]),
    {ok, Settings} = file:consult(Filename),
    IrcBot = ircbot_fsm:new_link(Settings),
    register(ircbot, IrcBot:pid()),
    IrcBot:connect(),
    loop_forever().

loop_forever() ->
    receive _ -> ok end,
    loop_forever().

By default it's using the settings.cfg file in the source dir. An example of is included with the source.

To connect to the running bot, you can use the erlang remote shell:

$ erl -remsh ircbot@localhost -sname rem
1> IrcBot = ircbot_api:new(whereis(ircbot)).
2> IrcBot:privmsg("#erlbot_test", "testing").

Look at the ircbot_api.erl file for the available "methods".

Clone this wiki locally