Hanabi v0.0.2 Hanabi.Control View Source

This module allows you to interact with the IRC server.

Link to this section Summary

Functions

Add an user to the given channel, messages will be send to the process pid as for Hanabi.register_user/2

Find a channel given its name

Get all the active channels of the IRC server

Find an user on the IRC server given its nickname

Get all the users registered on the IRC server

Register a “bridge” user under the nickname nick. Any message send this user on IRC will be send to pid using Kernel.send/2. Returns either {:ok, struct(Hanabi.User)} or {:error, :nick_in_use}

Remove an user from the given channel

Set the topic of a channel given its name.,

Remove a “bridge” user from the server

Link to this section Functions

Link to this function add_user_to_channel(channel, user_key) View Source

Add an user to the given channel, messages will be send to the process pid as for Hanabi.register_user/2.

Example

user = {:bridge, "mynick", pid}
Hanabi.Control.add_user_to_channel("#testchannel", user)
Link to this function get_channel_by_name(name) View Source

Find a channel given its name.

Examples

iex> Hanabi.Control.get_channel_by_name("#testchannel")
{:ok,
%Hanabi.Channel{topic: "topic",
users: [{:irc, "fnux", #Port<0.6645>}, {:irc, "lambda", #Port<0.6679>}]}}

iex> Hanabi.Control.get_channel_by_name("#nonexistantchannel")
{:error, :not_found}

Get all the active channels of the IRC server.

Example

iex> Hanabi.Control.get_channels()
[[{"#testchannel",
 %Hanabi.Channel{topic: "topic",
  users: [{:irc, "fnux", #Port<0.6645>}, {:irc, "lambda", #Port<0.6679>}]}}],
[{"#secondtestchannel",
 %Hanabi.Channel{topic: ":vlurps", users: [{:irc, "fnux", #Port<0.6645>}]}}]]

Find an user on the IRC server given its nickname.

Example

iex> Hanabi.Control.get_user_by_nick("fnux")
[{#Port<0.6645>,
%Hanabi.User{channels: ["#testchannel", "#secondtestchannel"],
 hostname: 'localhost', nick: "fnux", realname: nil, type: :irc,
 username: "fnux"}}]

Get all the users registered on the IRC server.

Example

iex> Hanabi.Control.get_users()
[[{#Port<0.6679>,
 %Hanabi.User{channels: ["#testchannel"], hostname: 'localhost',
  nick: "lambda", realname: nil, type: :irc, username: "lambda"}}],
[{#Port<0.6645>,
 %Hanabi.User{channels: ["#testchannel", "#secondtestchannel"],
  hostname: 'localhost', nick: "fnux", realname: nil, type: :irc,
  username: "fnux"}}]]
Link to this function register_user(pid, nick, key \\ nil) View Source

Register a “bridge” user under the nickname nick. Any message send this user on IRC will be send to pid using Kernel.send/2. Returns either {:ok, struct(Hanabi.User)} or {:error, :nick_in_use}.

Messages

  • {:msg, message}
  • {:reply, code, message}

Example

defmodule MyUserHandler do
   use GenServer

  def start_link do
    GenServer.start_link(__MODULE__, :ok)
  end

  def init(:ok) do
    # Register itself as user "lambda"
    {:ok, _} = Hanabi.Control.register("lambda", self())
    {:ok, nil}
  end

  def handle_info(%{msg: msg}, state) do
    IO.puts "New message : #{msg}"
    # do stuff

    {:noreply, state}
  end

  def handle_info(_msg, state) do
    {:noreply, state}
  end
end
Link to this function remove_user_from_channel(channel, user_key, part_msg \\ "") View Source

Remove an user from the given channel.

Example

Hanabi.Control.remove_user_from_channel("#test", user_key, "Bye ~")
Link to this function set_topic(channel, topic) View Source

Set the topic of a channel given its name.,

Example

Hanabi.Control.set_topic("#testchannel", "Let's try a few things...")
Link to this function unregister_user(user_key) View Source

Remove a “bridge” user from the server.