Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultCommandMap() map[string]Command
- func DefaultMasterMap() map[string]Command
- type Command
- type Config
- type Connection
- func (c *Connection) AddCommand(name string, fn Command)
- func (c *Connection) AddMasterCommand(name string, fn Command)
- func (c *Connection) Close() error
- func (c *Connection) Connect() (err error)
- func (c *Connection) Database() *bolt.DB
- func (c *Connection) Diamond() *diamond.System
- func (c *Connection) MarshalConfig() []byte
- func (c *Connection) MasterCheck()
- func (c *Connection) RemoveCommand(name string)
- func (c *Connection) RemoveMasterCommand(name string)
- func (c *Connection) Respawn()
- func (c *Connection) Send(irc IRC)
- func (c *Connection) SendMaster(format string, i ...interface{})
- func (c *Connection) Write(b []byte) (n int, err error)
- type IRC
- type PluginInitFunc
Constants ¶
const ( Green = "\x033" Red = "\x035" Purple = "\x036" Yellow = "\x038" GreenBold = "\x039" )
Variables ¶
var ErrNoPlugin = fmt.Errorf("plugin not found")
ErrNoPlugin when plugin is not found
var ErrNoPluginSupport = fmt.Errorf("no plugin support")
ErrNoPluginSupport when compiled with no CGO or without 'plugins' tag
var ErrPluginInv = fmt.Errorf("invalid plugin")
ErrPluginInv when plugin does not have proper Init func
var LoadPlugin = func(c *Connection, s string) error { return ErrNoPluginSupport }
LoadPlugin loads the named plugin file This is a stub, and should be replaced if ircb is built with plugin support
Functions ¶
func DefaultCommandMap ¶
DefaultCommandMap returns default command map
func DefaultMasterMap ¶
DefaultMasterMap returns default master command map
Types ¶
type Command ¶
type Command func(c *Connection, irc *IRC)
Command is what executes using a parsed IRC message irc message '!echo arg1 arg2' gets parsed as:
'irc.Command = echo', 'irc.CommandArguments = []string{"arg1","arg2"}
Command will be executed if it is in CommandMap or MasterMap Map Commands before connecting:
ircb.CommandMap ircb.DefaultCommandMaps() // load defaults, optional. ircb.CommandMap["echo"] = CommandEcho // Add a new command called hello, executed with !hello
!hello responds in channel, using name of user commander
ircb.CommandMap["hello"] = func(c *Connection, irc *IRC){ irc.Reply(c, fmt.Sprintf("hello, %s!", irc.ReplyTo)) } // Command parser will deal with authentication. // This makes adding new master commands easy: ircb.MasterMap["stat"] = func(c *Connection, irc.*IRC){ irc.ReplyUser(c, fmt.Sprintf("lines received: %v", c.lines)) }
Reply with irc.ReplyUser (for /msg reply) or irc.Reply (for channel)
type Config ¶
type Config struct { Host string // in the form 'host:port' Nick string Master string // in the form 'master:prefix' CommandPrefix string Channels string // comma separated channels to autojoin UseSSL bool InvalidSSL bool ParseLinks bool Define bool Verbose bool Karma bool Diamond bool // use diamond system DiamondSocket string // path to socket Database string // path to boltdb (can be empty to use bolt.db) AuthMode int // 0 ACC (freenode, recommended), 1 STATUS, -1 none }
Config holds configurable variables for ircb client
func ConfigFromJSON ¶
ConfigFromJSON loads a new config from json encoded bytes. It starts with a NewDefaultConfig, so not all fields must be present in json code.
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
NewDefaultConfig returns the default config, minimal changes would be Host,Nick,Master for typical usage.
func (*Config) NewConnection ¶
func (config *Config) NewConnection() *Connection
NewConnection returns an unconnected client from the given config
type Connection ¶
type Connection struct { Log *log.Logger HTTPClient *http.Client // customize user agent, proxy, tls, redirects, etc CommandMap map[string]Command // map of command names to Command functions MasterMap map[string]Command // map of master command names to Command functions // contains filtered or unexported fields }
Connection will be divided into:
Client Connection
func (*Connection) AddCommand ¶
func (c *Connection) AddCommand(name string, fn Command)
AddCommand adds a new public command, named 'name' to the CommandMap
func (*Connection) AddMasterCommand ¶
func (c *Connection) AddMasterCommand(name string, fn Command)
AddMasterCommand adds a new master command, named 'name' to the MasterMap
func (*Connection) Close ¶
func (c *Connection) Close() error
Close all connections and databases, remove diamond.socket
func (*Connection) Database ¶
func (c *Connection) Database() *bolt.DB
Database returns ircb's database system, will be nil if not connected
func (*Connection) Diamond ¶
func (c *Connection) Diamond() *diamond.System
Diamond returns ircb's diamond system, will be nil if not connected or not configured with 'Diamond: true'
func (*Connection) MarshalConfig ¶
func (c *Connection) MarshalConfig() []byte
MarshalConfig encodes the connection's config as JSON
func (*Connection) MasterCheck ¶
func (c *Connection) MasterCheck()
MasterCheck sends a private message to NickServ to authenticate master user
-1 no auth mode 0 default, freenode and oragono ACC style 1 STATUS style
func (*Connection) RemoveCommand ¶
func (c *Connection) RemoveCommand(name string)
RemoveCommand removes a public command, named 'name' to the CommandMap
func (*Connection) RemoveMasterCommand ¶
func (c *Connection) RemoveMasterCommand(name string)
RemoveMasterCommand adds a new public command, named 'name' to the CommandMap
func (*Connection) Respawn ¶
func (c *Connection) Respawn()
Respawn closes connections after executing self, can be called at any time.
func (*Connection) Send ¶
func (c *Connection) Send(irc IRC)
Send IRC message (uses To and Message fields)
func (*Connection) SendMaster ¶
func (c *Connection) SendMaster(format string, i ...interface{})
SendMaster sends formatted text to master user
type IRC ¶
type IRC struct { Raw string // As received Verb string // Using 'Verb' because we took 'Command' :) ReplyTo string // From user or channel To string // can be c.config.Nick Channel string // From channel (can be user) IsCommand bool // Is a public command IsWhisper bool // Is not from channel Message string // Parsed message (can still include command prefix) Command string // Parsed command (stripped of command prefix) Arguments []string // Parsed arguments (can be nil) }
IRC is a parsed message received from IRC server
func Parse ¶
Parse input string into IRC struct. To parse fully, use config method cfg.Parse(input string)
:Name COMMAND parameter list
Where list could begin with ':', which states the rest of list is just one item Sending, we use this format:
:COMMAND argument :string\r\n :PRIVMSG ##ircb :hello world\r\n
func (IRC) Encode ¶
Encode prepares an IRC message to be sent to server Uses only the To and Message fields, so it is easy to write an IRC such as:
irc := IRC{To: "##ircb", Message: "hello"} c.Send(irc) c.Send(IRC{To:"username", Message:"hello"})
func (*IRC) Reply ¶
func (irc *IRC) Reply(c *Connection, s string)
Reply replies to an irc message, preferring a channel
func (*IRC) ReplyUser ¶
func (irc *IRC) ReplyUser(c *Connection, s string)
ReplyUser doesnt send to #channel, only sends
type PluginInitFunc ¶
type PluginInitFunc (func(c *Connection) error)
PluginInitFunc gets called when plugin is loaded. Init(c *Connection) error