gen_ircclient

A scaffold for Erlang IRC bots.


License
Apache-2.0

Documentation

gen_ircclient

A scaffold for Erlang IRC bots.

hex.pm Build Status

IRC Client Behaviour

To implement an IRC bot with gen_ircclient the following four callback functions need to be implemented:

  • init/1 initializes the bot's state
  • handle_privmsg/4 defines the reaction to a given message.
  • handle_join/2 defines the reaction to the joining of a new user.
  • handle_part/2 handles the leaving of a user.

init

-callback init( Arg :: _ ) -> State :: _.

handle_privmsg

-callback handle_privmsg( Mode :: private | public, Sender :: string(), Content :: string(), State :: _ ) ->
              {noreply, NewState :: _}
            | {reply, Reply :: string(), NewState :: _}
            | {spawn, F :: fun( () -> string() ), NewState :: _}.

handle_join

-callback handle_join( User :: string(), State :: _ ) -> _.

handle_part

-callback handle_part( User :: string(), State :: _ ) -> _.

Example Bot

-module( example_bot ).

-export( [init/1, handle_privmsg/4, handle_join/2, handle_part/2] ).

init( _Arg ) ->
  [].

handle_privmsg( public, _Sender, "hello", State ) ->
  {reply, "Hi there.", State};

handle_privmsg( private, _Sender, "hello", State ) ->
  {reply, "Psst!", State};

handle_privmsg( _, _, _, State ) ->
  {noreply, State}.

handle_join( _User, State ) ->
  State.

handle_part( _User, State ) ->
  State.

Usage

Server   = "irc.freenode.net",
Port     = 6667,
NickName = "adam0815",
UserName = "adam",
RealName = "Adam Canopy".
ConnInfo = {conn_info, Server, Port, NickName, UserName, RealName},
Channel = "#botwar",
UsrMod  = example_bot.
gen_ircclient:start_link( ConnInfo, Channel, UsrMod, [] ).

System Requirements

Authors

License

Apache 2.0