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 ¶
- func NewircConn() *ircConn
- type ConfigPlugin
- func (cp *ConfigPlugin) Info() string
- func (cp *ConfigPlugin) ProcessCommand(cmd *IRCCommand)
- func (cp *ConfigPlugin) ProcessLine(msg *IRCMessage)
- func (cp *ConfigPlugin) Register(cl *IRCClient)
- func (cp *ConfigPlugin) String() string
- func (cp *ConfigPlugin) Unregister()
- func (cp *ConfigPlugin) Usage(cmd string) string
- type IRCClient
- func (ic *IRCClient) Connect() error
- func (ic *IRCClient) DelAccessLevel(host string)
- func (ic *IRCClient) Disconnect(quitmsg string)
- func (ic *IRCClient) GetAccessLevel(host string) int
- func (ic *IRCClient) GetIntOption(section, option string) (int, error)
- func (ic *IRCClient) GetOptions(section string) []string
- func (ic *IRCClient) GetPlugin(name string) Plugin
- func (ic *IRCClient) GetPlugins() map[string]Plugin
- func (ic *IRCClient) GetSocket() int
- func (ic *IRCClient) GetStringOption(section, option string) string
- func (ic *IRCClient) GetUsage(cmd string) string
- func (ic *IRCClient) InputLoop() error
- func (ic *IRCClient) IterHandlers() <-chan handler
- func (ic *IRCClient) RegisterCommandHandler(command string, minparams int, minaccess int, plugin Plugin) error
- func (ic *IRCClient) RegisterPlugin(p Plugin) error
- func (ic *IRCClient) RemoveOption(section, option string)
- func (ic *IRCClient) Reply(cmd *IRCCommand, message string)
- func (ic *IRCClient) ReplyMsg(msg *IRCMessage, message string)
- func (ic *IRCClient) SendLine(line string)
- func (ic *IRCClient) SetAccessLevel(host string, level int)
- func (ic *IRCClient) SetIntOption(section, option string, value int)
- func (ic *IRCClient) SetStringOption(section, option, value string)
- func (ic *IRCClient) Shutdown()
- type IRCCommand
- type IRCMessage
- type Plugin
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Does the same as GetStringOption(), but with integers. Returns an os.Error, if the given config option does not exist.
func (*IRCClient) GetOptions ¶
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 ¶
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 (*IRCClient) GetStringOption ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
See SetStringOption()
func (*IRCClient) SetStringOption ¶
Sets a single config option. Existing parameters are overriden, if necessary, a new config section is automatically added.
type IRCCommand ¶
func ParseCommand ¶
func ParseCommand(msg *IRCMessage) *IRCCommand
type IRCMessage ¶
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