module

package
v0.0.0-...-a977c90 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2014 License: MIT Imports: 14 Imported by: 16

Documentation

Index

Constants

View Source
const (
	UC_User userChan = true
	UC_Chan          = false
)
View Source
const (
	Poff = iota
	Pfatal
	Perror
	Pwarn
	Pinfo
	Pdebug
	Ptrace
	Pall
)

Priority used for identifying the severity of an event for Logger

View Source
const (
	Ldate         = log.Ldate         // the date: 2012/01/23
	Ltime         = log.Ltime         // the time: 01:23:23
	Lmicroseconds = log.Lmicroseconds // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile     = log.Llongfile     // full file name and line number: /a/b/c/d.go:23
	Lshortfile    = log.Lshortfile    // final file name element and line number: d.go:23. overrides Llongfile
	LstdFlags     = log.LstdFlags     // initial values for the standard logger
	Lpriority     = 1 << 5            // the priority: Debug
)

Logger flags used for identifying the format of an event. They are or'ed together to control what's printed. There is no control over the order they appear (the order listed here) or the format they present (as described in the comments). A colon appears after these items:

2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message

Variables

View Source
var (
	Events = make([]Event, 0, 5)
)

Events is a slice of Events which are registered when irclibrary.Connect() is called. This is export primarily for the use of irclibrary and should not need to be modified by the user

Functions

func SetLogDir

func SetLogDir(logdir string)

Types

type Console

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

Console struct to manage and parse commands

func (*Console) Parse

func (self *Console) Parse(cmd string)

Parse cmd and run associated functions. 'cmd' is lowered before parsing string triggers. String and regexp functions spawn goroutines

func (*Console) Register

func (self *Console) Register(trigger interface{}, fn func(string)) error

Register a `string` or `regexp.Regexp` returning an error if `trigger` is already registered

func (*Console) String

func (self *Console) String() []string

Returns a slice of strings of all string and regexp commands registered

func (*Console) Unregister

func (self *Console) Unregister(trigger interface{}) error

Unregister a `string` or `regexp.Regexp` returning an error if `trigger` was not registered

type Event

type Event string
const (
	E_REGISTER     Event = "REGISTER"
	E_CONNECTED    Event = "CONNECTED"
	E_DISCONNECTED Event = "DISCONNECTED"
	E_ACTION       Event = "ACTION"
	E_AWAY         Event = "AWAY"
	E_CTCP         Event = "CTCP"
	E_CTCPREPLY    Event = "CTCPREPLY"
	E_INVITE       Event = "INVITE"
	E_JOIN         Event = "JOIN"
	E_KICK         Event = "KICK"
	E_MODE         Event = "MODE"
	E_NICK         Event = "NICK"
	E_NOTICE       Event = "NOTICE"
	E_OPER         Event = "OPER"
	E_PART         Event = "PART"
	E_PASS         Event = "PASS"
	E_PING         Event = "PING"
	E_PONG         Event = "PONG"
	E_PRIVMSG      Event = "PRIVMSG"
	E_QUIT         Event = "QUIT"
	E_TOPIC        Event = "TOPIC"
	E_USER         Event = "USER"
	E_VERSION      Event = "VERSION"
	E_VHOST        Event = "VHOST"
	E_WHO          Event = "WHO"
	E_WHOIS        Event = "WHOIS"
)

IRC events to trigger on

func RegisteredEvents

func RegisteredEvents() []Event

type Logger

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

Logger defines our wrapper around the system logger

func (*Logger) ClearLogs

func (me *Logger) ClearLogs()

Clears saved logs slice, not those stored to disk

func (*Logger) Debug

func (me *Logger) Debug(v ...interface{})

Debug prints to the standard logger with the Debug level.

func (*Logger) Debugf

func (me *Logger) Debugf(format string, v ...interface{})

Debugf prints to the standard logger with the Debug level.

func (*Logger) Debugln

func (me *Logger) Debugln(v ...interface{})

Debugln prints to the standard logger with the Debug level.

func (*Logger) Error

func (me *Logger) Error(v ...interface{})

Error prints to the standard logger with the Error level.

func (*Logger) Errorf

func (me *Logger) Errorf(format string, v ...interface{})

Errorf prints to the standard logger with the Error level.

func (*Logger) Errorln

func (me *Logger) Errorln(v ...interface{})

Errorln prints to the standard logger with the Error level.

func (*Logger) Fatal

func (me *Logger) Fatal(v ...interface{})

Fatal prints the message it's given and quits the program

func (*Logger) Fatalf

func (me *Logger) Fatalf(format string, v ...interface{})

Fatalf prints the message it's given and quits the program

func (*Logger) Fatalln

func (me *Logger) Fatalln(v ...interface{})

Fatalln prints the message it's given and quits the program

func (*Logger) Flags

func (me *Logger) Flags() int

Flags returns the output layouts for the logger.

func (*Logger) Info

func (me *Logger) Info(v ...interface{})

Info prints to the standard logger with the Info level.

func (*Logger) Infof

func (me *Logger) Infof(format string, v ...interface{})

Infof prints to the standard logger with the Info level.

func (*Logger) Infoln

func (me *Logger) Infoln(v ...interface{})

Infoln prints to the standard logger with the Info level.

func (*Logger) LenLogs

func (me *Logger) LenLogs() int

func (*Logger) Logs

func (me *Logger) Logs(n int) []string

Return a copy of logs[:min(n, len(logs))]. If n is 0 a copy of logs is returned. Calling Logs() with n < 0 is the same as calling TailLogs(-n)

func (*Logger) Panic

func (me *Logger) Panic(v ...interface{})

Panic prints the message it's given and panic()s the program

func (*Logger) Panicf

func (me *Logger) Panicf(format string, v ...interface{})

Panicf prints the message it's given and panic()s the program

func (*Logger) Panicln

func (me *Logger) Panicln(v ...interface{})

Panicln prints the message it's given and panic()s the program

func (*Logger) Prefix

func (me *Logger) Prefix() string

Prefix returns the current logger prefix

func (*Logger) Priority

func (me *Logger) Priority() int32

Priority returns the output priority for the logger.

func (*Logger) SetFlags

func (me *Logger) SetFlags(layouts int)

SetFlags sets the output layouts for the logger.

func (*Logger) SetPrefix

func (me *Logger) SetPrefix(prefix string)

SetPrefix sets the output prefix for the logger.

func (*Logger) SetPriority

func (me *Logger) SetPriority(priority int32)

SetPriority sets the output priority for the logger.

func (*Logger) SetPriorityString

func (me *Logger) SetPriorityString(s string) error

SetPriorityString sets the output priority by the name of a debug level

func (*Logger) TailLogs

func (me *Logger) TailLogs(n int) []string

Returns a copy of logs[len(logs) - min(n, len(logs):]. Calling TailLogs(n) where n < 0 is equivalent to calling Logs(-n)

func (*Logger) Trace

func (me *Logger) Trace(v ...interface{})

Trace prints to the standard logger with the Trace level.

func (*Logger) Tracef

func (me *Logger) Tracef(format string, v ...interface{})

Tracef prints to the standard logger with the Trace level.

func (*Logger) Traceln

func (me *Logger) Traceln(v ...interface{})

Traceln prints to the standard logger with the Trace level.

func (*Logger) Warn

func (me *Logger) Warn(v ...interface{})

Warn prints to the standard logger with the Warn level.

func (*Logger) Warnf

func (me *Logger) Warnf(format string, v ...interface{})

Warnf prints to the standard logger with the Warn level.

func (*Logger) Warnln

func (me *Logger) Warnln(v ...interface{})

Warnln prints to the standard logger with the Warn level.

type Module

type Module struct {

	// IRC Connection. Conn is not assigned until it is registered
	Conn *irc.Conn

	// Connect functions to call before or after IRC connection
	// Disconnect is called after disconnected from IRC
	// Errors are logged to to the module Logger
	Preconnect, Connected, Disconnect func() error

	Console *Console // Console handler; commands are triggered with ":moduleName <command>"
	Logger  *Logger
	// contains filtered or unexported fields
}

Module repersents the state of the module

func New

func New(configFile string) (*Module, error)

Read a TOML file and return a configured Module. Errors indicate a failure to parse the file or an incomplete configuration

func (*Module) Allow

func (self *Module) Allow(target string) error

Allow user or channels; channels should begin with '#'. Returns an error if 'target' is already in the slice. Does not remove user or channel from allow(User|Chan) slices

func (*Module) ClearAllowed

func (self *Module) ClearAllowed(u userChan)

Clears allow(User|Chan) slices

func (*Module) ClearDenyed

func (self *Module) ClearDenyed(u userChan)

Clears deny(User|Chan) slices

func (*Module) Deny

func (self *Module) Deny(target string) error

Deny user or channels; channels should begin with '#'. Returns an error if 'target' is already in the slice. Does not remove user or channel from deny(User|Chan) slices

func (*Module) Description

func (self *Module) Description() string

Returns the module description

func (*Module) Disable

func (self *Module) Disable()

Helper function to disable the module. Calls `moduleConfig.SetEnabled(false)`

func (*Module) Enable

func (self *Module) Enable()

Helper function to enable the module. Calls `moduleConfig.SetEnabled(true)`

func (*Module) Enabled

func (self *Module) Enabled() bool

Returns `true` if the module is enabled

func (*Module) Exit

func (self *Module) Exit() error

Calls Disconnect(), cleans up, and exits. Errors returned by Disconnect() are logged and Exit() continues. If there is an error at any other point the error is returned and should be assumed that cleanup did not complete.

func (*Module) ForceExit

func (self *Module) ForceExit() []error

Calls Disconnect(), cleans up, and exits. ForceExit() continues on errors, which are aggregated and returned in a slice. If there are no errors `nil` is returned

func (*Module) GetAllowed

func (self *Module) GetAllowed(u userChan) []string

Returns a copy (not slice header) of allow(User|Chan) slices. If copies are too expensive look at GetROAllowed()

func (*Module) GetDenyed

func (self *Module) GetDenyed(u userChan) []string

Returns a copy (not slice header) of deny(User|Chan) slices. If copies are too expensive look at GetRODenyed()

func (*Module) GetROAllowed

func (self *Module) GetROAllowed(u userChan) ([]string, chan<- bool)

Returns a copy of the appropriate slice header to avoid copies. This is a promise by the user to not modify the slice and enforced by a RLock() on the slice. The lock is released by closing the chan or sending a boolean value

func (*Module) GetRODenyed

func (self *Module) GetRODenyed(u userChan) ([]string, chan<- bool)

Returns a copy of the appropriate slice header to avoid copies. This is a promise by the user to not modify the slice and enforced by a RLock() on the slice. The lock is released by closing the chan or sending a boolean value

func (*Module) Handle

func (self *Module) Handle(eventMode Event, trigger string, line *irc.Line)

Handles triggers if module is enabled and user/chan is allowed. This is mainly exported for use by library and should not have to be called by the user

func (*Module) InAllowed

func (self *Module) InAllowed(target string) bool

Returns true if 'target' is in allow(User|Chan); chans should begin with '#'

func (*Module) InDenyed

func (self *Module) InDenyed(target string) bool

Returns true if 'target' is in deny(User|Chan); chans should begin with '#'

func (*Module) LenAllowed

func (self *Module) LenAllowed(u userChan) int

Returns the length of allow(User|Chan)

func (*Module) LenDenyed

func (self *Module) LenDenyed(u userChan) int

Returns the length of allow(User|Chan)

func (*Module) LogDir

func (self *Module) LogDir() string

Returns the directory logs are saved to. Full log path is "moduleConfig.logDir/moduleConfig.name"

func (*Module) Name

func (self *Module) Name() string

Returns the module name

func (*Module) PreStart

func (self *Module) PreStart() error

Creates a Logger if necessay and calls Preconnect() if applicable. This is exported for use by library and most likely doesn't need to be called by the user. Error is non-nil if a logger could not be created or Preconnect() returned an error; errors returned by Preconnect() are logged

func (*Module) Register

func (self *Module) Register(eventMode Event, trigger interface{}, fn func(*irc.Line))

func (*Module) RemAllowed

func (self *Module) RemAllowed(target string) error

Removes user or channel from respective allowed slices; channels should begin with '#'. Returns an error if 'target' is not in the slice

func (*Module) RemDenyed

func (self *Module) RemDenyed(target string) error

Removes user or channel from respective denyed slices; channels should begin with '#'. Returns an error if 'target' is not in the slice

func (*Module) SetDescription

func (self *Module) SetDescription(desc string)

Set module description

func (*Module) SetEnabled

func (self *Module) SetEnabled(en bool)

Set the status of the module

func (*Module) SetLogDir

func (self *Module) SetLogDir(logDir string)

Sets the directory logs are saved to. This does not take effect until the module is restarted

func (*Module) Start

func (self *Module) Start() error

Creates a Logger if necessay and calls Connet() if applicable. This is exported for use by library and most likely does not need to be called by the user. Error is non-nil if a logger could not be created, module is already running or Connect() returned an error; errors returned by Connect() are logged

func (*Module) StringCommands

func (self *Module) StringCommands() []string

Returns a list of IRC commands registered

type ModuleInfo

type ModuleInfo struct {
	Name        string // Unique name or registering and triggering console commands
	Description string // Description of module
	LogDir      string // Directory to keep logs, defaults to ./logs/
	Enabled     bool   // Flag to see if module is enabled

	// Filtered by: denyUser, allowUser, denyChan, allowChan
	// ToLower is called on slices when creating a Module
	AllowUser, DenyUser []string // Slice of allowed or denyed users
	AllowChan, DenyChan []string // Slice of allowed or denyed chans
}

ModuleInfo repersents configuration fields that can be loaded from TOML files

func (*ModuleInfo) NewModule

func (self *ModuleInfo) NewModule() (*Module, error)

Returns a configured Module from ModuleInfo. ModuleInfo.Name and ModuleInfo.Description can not be an empty string

Jump to

Keyboard shortcuts

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