Hanabi v0.0.1 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
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)
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"}}]]
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
Remove an user from the given channel.
Example
Hanabi.Control.remove_user_from_channel("#test", user_key, "Bye ~")
Set the topic of a channel given its name.,
Example
Hanabi.Control.set_topic("#testchannel", "Let's try a few things...")
Remove a “bridge” user from the server.