Documentation ¶
Overview ¶
Package config provides several ways to configure an irc bot. Some methods are inline fluent configuration, yaml reading from any io.Reader. It also provides config validation.
Index ¶
- func FlushConfigToFile(conf *Config, filename string) (err error)
- func FlushConfigToWriter(conf *Config, writer io.Writer) (err error)
- type Config
- func (c *Config) Altnick(altnick string) *Config
- func (c *Config) Channels(channels ...string) *Config
- func (c *Config) Clone() *Config
- func (c *Config) DisplayErrors()
- func (c *Config) FloodLenPenalty(floodlenPenalty uint) *Config
- func (c *Config) FloodStep(floodstep float64) *Config
- func (c *Config) FloodTimeout(floodtimeout float64) *Config
- func (c *Config) GetContext() *Server
- func (c *Config) GetFilename() (filename string)
- func (c *Config) GetServer(name string) *Server
- func (c *Config) GetStoreFile() (storefile string)
- func (c *Config) GlobalContext() *Config
- func (c *Config) Host(host string) *Config
- func (c *Config) IsValid() bool
- func (c *Config) KeepAlive(floodstep float64) *Config
- func (c *Config) Nick(nick string) *Config
- func (c *Config) NoReconnect(noreconnect bool) *Config
- func (c *Config) NoState(nostate bool) *Config
- func (c *Config) NoStore(nostore bool) *Config
- func (c *Config) NoVerifyCert(noverifycert bool) *Config
- func (c *Config) Port(port uint16) *Config
- func (c *Config) Prefix(prefix string) *Config
- func (c *Config) Realname(realname string) *Config
- func (c *Config) ReconnectTimeout(seconds uint) *Config
- func (c *Config) RemoveServer(name string) (deleted bool)
- func (c *Config) Server(name string) *Config
- func (c *Config) ServerContext(name string) *Config
- func (c *Config) Ssl(ssl bool) *Config
- func (c *Config) SslCert(cert string) *Config
- func (c *Config) StoreFile(storefile string) *Config
- func (c *Config) Userhost(userhost string) *Config
- func (c *Config) Username(username string) *Config
- type Server
- func (s *Server) GetAltnick() (altnick string)
- func (s *Server) GetChannels() (channels []string)
- func (s *Server) GetFloodLenPenalty() (floodLenPenalty uint)
- func (s *Server) GetFloodStep() (floodStep float64)
- func (s *Server) GetFloodTimeout() (floodTimeout float64)
- func (s *Server) GetHost() string
- func (s *Server) GetKeepAlive() (keepAlive float64)
- func (s *Server) GetName() string
- func (s *Server) GetNick() (nick string)
- func (s *Server) GetNoReconnect() (noReconnect bool)
- func (s *Server) GetNoState() (nostate bool)
- func (s *Server) GetNoStore() (nostore bool)
- func (s *Server) GetNoVerifyCert() (noverifyCert bool)
- func (s *Server) GetPort() (port uint16)
- func (s *Server) GetPrefix() (prefix rune)
- func (s *Server) GetRealname() (realname string)
- func (s *Server) GetReconnectTimeout() (reconnTimeout uint)
- func (s *Server) GetSsl() (ssl bool)
- func (s *Server) GetSslCert() (cert string)
- func (s *Server) GetUserhost() (userhost string)
- func (s *Server) GetUsername() (username string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FlushConfigToFile ¶
FlushConfigToFile writes a config out to a writer. If the filename is empty it will write to the file that this config was loaded from, or it will write to the defaultConfigFileName.
Types ¶
type Config ¶
type Config struct { Servers map[string]*Server Global *Server Storefile string Errors []error "-" // contains filtered or unexported fields }
Config holds all the information related to the bot including global settings default settings, and server specific settings.
func CreateConfigFromFile ¶
CreateConfigFromFile initializes a Config object from a file.
func CreateConfigFromReader ¶
CreateConfigFromReader initializes a Config object from a reader.
func (*Config) DisplayErrors ¶
func (c *Config) DisplayErrors()
DisplayErrors is a helper function to log the output of all config to the standard logger.
func (*Config) FloodLenPenalty ¶
FloodLenPenalty fluently sets flood lenPenalty for the current config context. This is how many characters in a message will generate an extra second of flood protection penalty.
func (*Config) FloodStep ¶
FloodStep fluently sets flood protect step for the current config context, this is how many seconds as a base are used to protect against flooding, but may be added on to by FloodLenPenalty for sufficiently long messages.
func (*Config) FloodTimeout ¶
FloodTimeout fluently sets flood timeout for the current config context, this is how many seconds of penalty must accumulate before flood protection is triggered, and also how long after flood protection activation it will continue to flood protect for.
func (*Config) GetContext ¶
GetContext retrieves the current configuration context, if no context has been set, returns the global setting object.
func (*Config) GetFilename ¶
GetFilename returns fileName of the configuration, or the default.
func (*Config) GetStoreFile ¶
GetStoreFile gets the global storefile or defaultStoreFile.
func (*Config) GlobalContext ¶
GlobalContext clears the configs server context
func (*Config) IsValid ¶
IsValid checks to see if the configuration is valid. If errors are found in the config the Config.Errors property is filled with the validation errors. These can be used to display to the user. See DisplayErrors for a display helper.
func (*Config) KeepAlive ¶
KeepAlive fluently sets keep alive timeout for the current config context, this is how many seconds to wait on an idle connection before sending a ping to see if the server is dead.
func (*Config) NoReconnect ¶
NoReconnect fluently sets reconnection for the current config context
func (*Config) NoState ¶
NoState fluently sets reconnection for the current config context, this turns off the irc state database (data package).
func (*Config) NoStore ¶
NoStore fluently sets reconnection for the current config context, this turns off the irc store database (data package).
func (*Config) NoVerifyCert ¶
NoVerifyCert fluently sets the noverifyCert for the current config context
func (*Config) ReconnectTimeout ¶
ReconnectTimeout fluently sets the port for the current config context
func (*Config) RemoveServer ¶
RemoveServer removes a server by name. Note that this does not work on host if a name has been set on the server.
func (*Config) Server ¶
Server fluently creates a server object and sets the context on the Config to the current instance. This automatically sets the Host() parameter to the same thing. If you have multiple servers connecting to the same host, you will have to use this to name the server, and Host() to set the host.
func (*Config) ServerContext ¶
ServerContext the configs server context, adds an error if the if server key is not found.
func (*Config) SslCert ¶
SslCert sets a filename that will be read in (pem format) to verify the server's certificate.
type Server ¶
type Server struct { // Name of this connection Name string // Irc Server connection info Host string Port uint16 // Ssl configuration Ssl string SslCert string NoVerifyCert string // State tracking NoState string NoStore string // Flood Protection FloodLenPenalty string FloodTimeout string FloodStep string // Keep alive KeepAlive string // Auto reconnection NoReconnect string ReconnectTimeout string // Irc User data Nick string Altnick string Username string Userhost string Realname string // Dispatching options Prefix string Channels []string // contains filtered or unexported fields }
Server states the all the details necessary to connect to an irc server Although all of these are exported so they can be deserialized into a yaml file, they are not for direct reading and the helper methods should ALWAYS be used to preserve correct global-value resolution.
func (*Server) GetAltnick ¶
GetAltnick gets Altnick of the server, or the global altnick, or empty string.
func (*Server) GetChannels ¶
GetChannels gets Channels of the server, or the global channels, or nil slice of string (check the length!).
func (*Server) GetFloodLenPenalty ¶
GetFloodLenPenalty gets FloodLenPenalty of the server, or the global floodLenPenalty, or defaultFloodLenPenalty
func (*Server) GetFloodStep ¶
GetFloodStep gets FloodStep of the server, or the global floodStep, or defaultFloodStep
func (*Server) GetFloodTimeout ¶
GetFloodTimeout gets FloodTimeout of the server, or the global floodTimeout, or defaultFloodTimeout
func (*Server) GetKeepAlive ¶
GetKeepAlive gets KeepAlive of the server, or the global keepAlive, or defaultKeepAlive.
func (*Server) GetNoReconnect ¶
GetNoReconnect gets NoReconnect of the server, or the global noReconnect, or false
func (*Server) GetNoState ¶
GetNoState gets NoState of the server, or the global nostate, or false
func (*Server) GetNoStore ¶
GetNoStore gets NoStore of the server, or the global nostore, or false
func (*Server) GetNoVerifyCert ¶
GetNoVerifyCert gets NoVerifyCert of the server, or the global verifyCert, or false
func (*Server) GetPort ¶
GetPort returns gets Port of the server, or the global port, or ircDefaultPort
func (*Server) GetPrefix ¶
GetPrefix gets Prefix of the server, or the global prefix, or defaultPrefix.
func (*Server) GetRealname ¶
GetRealname gets Realname of the server, or the global realname, or empty string.
func (*Server) GetReconnectTimeout ¶
GetReconnectTimeout gets ReconnectTimeout of the server, or the global reconnectTimeout, or defaultReconnectTimeout
func (*Server) GetSslCert ¶
GetSslCert returns the path to the certificate used when connecting.
func (*Server) GetUserhost ¶
GetUserhost gets Userhost of the server, or the global userhost, or empty string.
func (*Server) GetUsername ¶
GetUsername gets Username of the server, or the global username, or empty string.