ircclient

package
v0.0.0-...-54b35f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2015 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package ircclient provides the main interface for library users It manages a single connection to the server and the associated configuration and plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewircConn

func NewircConn() *ircConn

Types

type ConfigPlugin

type ConfigPlugin struct {
	Conf *config.Config
	// Operations to the Config structure should be atomic
	sync.Mutex
	// contains filtered or unexported fields
}

func NewConfigPlugin

func NewConfigPlugin(filename string) *ConfigPlugin

func (*ConfigPlugin) Info

func (cp *ConfigPlugin) Info() string

func (*ConfigPlugin) ProcessCommand

func (cp *ConfigPlugin) ProcessCommand(cmd *IRCCommand)

func (*ConfigPlugin) ProcessLine

func (cp *ConfigPlugin) ProcessLine(msg *IRCMessage)

func (*ConfigPlugin) Register

func (cp *ConfigPlugin) Register(cl *IRCClient)

func (*ConfigPlugin) String

func (cp *ConfigPlugin) String() string

func (*ConfigPlugin) Unregister

func (cp *ConfigPlugin) Unregister()

func (*ConfigPlugin) Usage

func (cp *ConfigPlugin) Usage(cmd string) string

type IRCClient

type IRCClient struct {
	// contains filtered or unexported fields
}

func NewIRCClient

func NewIRCClient(configfile string) *IRCClient

Returns a new IRCClient connection with the given configuration options. It will not connect to the given server until Connect() has been called, so you can register plugins before connecting

func (*IRCClient) Connect

func (ic *IRCClient) Connect() error

Connects to the server specified on object creation. If the chosen nickname is already in use, it will automatically be suffixed with an single underscore until an unused nickname is found. This function blocks until the connection attempt has been finished.

func (*IRCClient) DelAccessLevel

func (ic *IRCClient) DelAccessLevel(host string)

Delete the given regular expression from auth database. The "host" parameter has to be exactly the string stored in the database, otherwise, the command will have no effect.

func (*IRCClient) Disconnect

func (ic *IRCClient) Disconnect(quitmsg string)

Disconnects from the server with the given quit message. All plugins wil be unregistered and pending messages in queue (e.g. because of floodprotection) will be flushed. This will also make InputLoop() return.

func (*IRCClient) GetAccessLevel

func (ic *IRCClient) GetAccessLevel(host string) int

Gets the highest matching access level for a given hostmask by comparing the mask against all authorization entries. Default return value is 0 (no access).

func (*IRCClient) GetIntOption

func (ic *IRCClient) GetIntOption(section, option string) (int, error)

Does the same as GetStringOption(), but with integers. Returns an os.Error, if the given config option does not exist.

func (*IRCClient) GetOptions

func (ic *IRCClient) GetOptions(section string) []string

Gets a list of all config keys for a given section. The return value is an empty slice if there are no options present _or_ if there is no section present. There is currently no way to check whether a section exists, it is automatically added when calling one of the SetOption() methods.

func (*IRCClient) GetPlugin

func (ic *IRCClient) GetPlugin(name string) Plugin

Get the pointer to a specific plugin that has been registered using RegisterPlugin() Name is the name the plugin identifies itself with when String() is called on it.

func (*IRCClient) GetPlugins

func (ic *IRCClient) GetPlugins() map[string]Plugin

func (*IRCClient) GetSocket

func (ic *IRCClient) GetSocket() int

Returns socket fd. Needed for kexec

func (*IRCClient) GetStringOption

func (ic *IRCClient) GetStringOption(section, option string) string

Gets one of the configuration options stored in the config object. Valid config options for section "Server" usually include:

  • nick
  • hostport (colon-seperated host and port to connect to)
  • realname (the real name)
  • ident
  • trigger

All other sections are managed by the library user. Returns an empty string if the option is empty, this means: you currently can't use empty config values - they will be deemed non-existent!

func (*IRCClient) GetUsage

func (ic *IRCClient) GetUsage(cmd string) string

Get the Usage string from the Plugin that has registered itself as handler for the Command cmd. we need to wrap this to ircclient because the handlers are not public, and GetPlugin doesn't help us either, because the plugin<->command mapping is not known

func (*IRCClient) InputLoop

func (ic *IRCClient) InputLoop() error

Starts the actual command processing. This function will block until the connection has either been lost or Disconnect() has been called (by a plugin or by the library user).

func (*IRCClient) IterHandlers

func (ic *IRCClient) IterHandlers() <-chan handler

Returns a channel on which all command handlers will be sent.

func (*IRCClient) RegisterCommandHandler

func (ic *IRCClient) RegisterCommandHandler(command string, minparams int, minaccess int, plugin Plugin) error

Registers a command handler. Plugin callbacks will only be called if the command matches. Note that only a single plugin per command may be registered. This function is not synchronized, e.g., it shall only be called during registration (as Plugin.Register()-calls are currently sequential).

func (*IRCClient) RegisterPlugin

func (ic *IRCClient) RegisterPlugin(p Plugin) error

Registers a new plugin. Plugins can be registered at any time, even before the actual connection attempt. The plugin's Unregister() function will already be called when the connection is lost.

func (*IRCClient) RemoveOption

func (ic *IRCClient) RemoveOption(section, option string)

Removes a single config option. Note: This does not delete the section, even if it's empty.

func (*IRCClient) Reply

func (ic *IRCClient) Reply(cmd *IRCCommand, message string)

Sends a reply to a parsed message from a user. This is mostly intended for plugins and will automatically distinguish between channel and query messages. Note: Notice replies will currently be sent to the client using PRIVMSG, this may change in the future.

func (*IRCClient) ReplyMsg

func (ic *IRCClient) ReplyMsg(msg *IRCMessage, message string)

func (*IRCClient) SendLine

func (ic *IRCClient) SendLine(line string)

Dumps a raw line to the server socket. This is usually called by plugins, but may also be used by the library user.

func (*IRCClient) SetAccessLevel

func (ic *IRCClient) SetAccessLevel(host string, level int)

Sets the access level for the given hostmask to level. Note that host may be a regular expression, if exactly the same expression is already present in the database, it is overridden.

func (*IRCClient) SetIntOption

func (ic *IRCClient) SetIntOption(section, option string, value int)

See SetStringOption()

func (*IRCClient) SetStringOption

func (ic *IRCClient) SetStringOption(section, option, value string)

Sets a single config option. Existing parameters are overriden, if necessary, a new config section is automatically added.

func (*IRCClient) Shutdown

func (ic *IRCClient) Shutdown()

type IRCCommand

type IRCCommand struct {
	Source  string
	Command string
	Target  string
	Args    []string
}

func ParseCommand

func ParseCommand(msg *IRCMessage) *IRCCommand

type IRCMessage

type IRCMessage struct {
	Source   string
	Target   string
	Command  string
	Args     []string
	Complete string
}

func ParseServerLine

func ParseServerLine(line string) *IRCMessage

type Plugin

type Plugin interface {
	// This function is called by IRCClient when registering the plugin.
	// It takes a pointer to the parent IRCClient object that is needed for
	// almost any kind of functionality, so you should definitively save it ;-)
	Register(cl *IRCClient)
	// Returns the name of the plugin, as a short string (e.g.: auth, lecture, ...)
	String() string
	// Returns the description of the plugin in human-readable form, about one line long.
	Info() string
	// Returns usage for the Command cmd
	Usage(cmd string) string
	// This method is called by the parent IRCClient when a new line from server
	// arrives, regardless of the other state of the connection. This means, if
	// the plugin is registered soon enough, this handler method is also called
	// during registration phase, when authentication hasn't been performed.
	ProcessLine(msg *IRCMessage)
	// This method is called when an command directed to the bot has been received
	// and parsed. It is NOT called during registration phase, specifically, the
	// initial NOTICEs are _NOT_ passed to this method. Replies can be easily sent
	// using the Reply() function of the parent IRCClient.
	ProcessCommand(cmd *IRCCommand)
	// Automatically called when the connection is lost. Should perform cleanup
	// work and not expect that the plugin is used again.
	Unregister()
}

The interface to be implemented by all plugins

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL