Hanabi v0.1.1 Hanabi.Channel View Source

Entry point to interact with channels.

Channels are represented using the following structure :

%Hanabi.Channel{
  name: nil,
  relay_to: [:irc, :virtual],
  topic: "",
  users: [],
  data: nil # allows you to store custom values
}

Hanabi maintains a registry storing all existing channels using their names (e.g. : #hanabi) as keys. This registry can be accessed using the get/1, get_all/0, update/2, set/2 and drop/1 methods.

Link to this section Summary

Functions

Add an user to a channel

Send the message msg to every user in the channel channel

Remove a channel from the registry given its identifier

Returns the channel structure registered under the identifier key

Returns a list containing all the pairs {key, channel_struct}

Returns a list containing all the registered keys (= channel names)

Remove an user from a channel

Convenience function to send a PRIVMSG to a channel

Save the channel struct in the registry under the given identifier. Any existing value will be overwritten

Update the values of an existing user struct stored in the registry

Link to this section Functions

Add an user to a channel.

  • user is either the user’s struct or identifier
  • channel is either the channel’s struct or identifier. A new channel will be created if there is no channel registered under the given identifier.

Return values :

  • {:ok, updated_channel}
  • {:err, :no_such_user}

Send the message msg to every user in the channel channel.

  • channel is a channel’s struct or identifier
  • msg is a message’s struct

Remove a channel from the registry given its identifier.

Returns the channel structure registered under the identifier key.

If no such identifier is found in the registry, returns nil.

Returns a list containing all the pairs {key, channel_struct}.

Returns a list containing all the registered keys (= channel names).

Link to this function remove_user(user, channel, part_msg \\ nil) View Source

Remove an user from a channel.

  • user is either the user’s struct or identifier
  • channel is either the channel’s struct or identifier
  • part_msg is a string if specified

Return values :

  • {:ok, updated_channel}
  • {:err, @err_notonchannel}
  • {:err, @err_nosuchchannel}
  • {:err, :no_such_user}

@err_notonchannel and @err_nosuchchannel are defined in Hanabi.IRC.Numeric.

Link to this function send_privmsg(sender, channel, content) View Source

Convenience function to send a PRIVMSG to a channel.

Save the channel struct in the registry under the given identifier. Any existing value will be overwritten.

Link to this function set_topic(channel, topic, name \\ "irc.localhost") View Source

Set the topic of a channel.

  • channel is either a channel’s struct or identifier
  • topic is a string
  • name is the one who changed the topic. Defaults to the server’s hostname

Return values :

  • :ok
  • :err if there is no such channel under the given key

Update the values of an existing user struct stored in the registry.

  • channel is either the channel’s identifier or struct.
  • value is a struct changeset, (topic: "my topic", %{topic: "my topic", users: [], ...})

Returns the updated struct or nil.