Hanabi v0.1.1 Hanabi.IRC View Source

IRC-related methods used for common tasks such as parsing/building/sending/validating.

Link to this section Summary

Functions

Build an IRC message given the message structure defined in Hanabi.IRC.Message

Parse an IRC message (= string) into a Hanabi.IRC.Message struct

Resolves and returns an hostname given the port identifier of a TCP socket

Send a message over the port TCP socket

Validates various IRC-related strutures/formats

Link to this section Functions

Build an IRC message given the message structure defined in Hanabi.IRC.Message.

Example

iex> msg = %Hanabi.IRC.Message{command: "PRIVMSG", middle: "Wiz", prefix: "Angel",
  trailing: "Hello are you receiving this message ?"}
iex> Hanabi.IRC.build msg
":Angel PRIVMSG Wiz :Hello are you receiving this message ?"

Parse an IRC message (= string) into a Hanabi.IRC.Message struct.

Example

iex> Hanabi.IRC.parse ":Angel PRIVMSG Wiz :Hello are you receiving this message ?"
%Hanabi.IRC.Message{command: "PRIVMSG", middle: "Wiz", prefix: "Angel",
  trailing: "Hello are you receiving this message ?"}
iex> Hanabi.IRC.parse ":WiZ NICK Kilroy"
%Hanabi.IRC.Message{command: "NICK", middle: "Kilroy", prefix: "WiZ",
  trailing: nil}
Link to this function resolve_hostname(client) View Source

Resolves and returns an hostname given the port identifier of a TCP socket.

If unable to determine the host, this methods returns the IP address. Used to populate the :hostname field of the Hanabi.User struct.

Example

iex>  {:ok, port} = :gen_tcp.connect String.to_charlist("fnux.ch"), 80, [:binary]
{:ok, #Port<0.6707>}
iex> Hanabi.IRC.resolve_hostname port
'kyrkja.fnux.ch'

Send a message over the port TCP socket.

  • If msg is a Hanabi.IRC.Message structure, it will be transformed into a properly formatted string using build/1
  • If msg already is string, it will directly be transmitted

This method takes care to append <crlf> at the end of the transmitted string.

Validates various IRC-related strutures/formats.

Nickname validation

validate(:nick, nick)

Return values :

  • {:ok, nick} if the nickname is valid and unused
  • {:err, @err_erroneusnickname} if the nickname is invalid
  • {:err, @err_nicknameinuse} if the nickname is valid but already in use

@err_erroneusnickname and @err_nicknameinuse are defined in Hanabi.IRC.Numeric.

iex> Hanabi.IRC.validate :nick, "fnux"
{:ok. "fnux"}
iex> Hanabi.IRC.validate :nick, "#fnux"
{:err, "432"}

Channel name validation

validate(:channel, name)

iex> Hanabi.IRC.validate :channel, "#hanabi"
true
iex> Hanabi.IRC.validate :channel, "hanabi"
false

User validation

validate(:user, user)

Validates a ‘registerable’ user, which means that the following fields of the user struct must be present : :key, :nick, :username, :realname, :hostname. Returns either true or false.