Documentation
¶
Overview ¶
An IRC-Client library.
Index ¶
- Variables
- func Bold(input string) string
- func Color(color int) string
- func ColorString(color int, input string) string
- func GetModuleVersion() string
- func GetModules() map[string]string
- func GetVersion() (goversion string, gitcommit string, arch string, goos string)
- func IRCNick(from string) string
- func Italics(input string) string
- func Match(name1 string, name2 string) bool
- func Monospace(input string) string
- func NameLower(name string) string
- func RandomNick(nick string) string
- func Reset() string
- func Reverse(input string) string
- func ShowVersion()
- func StrInArray(strings []string, str string) bool
- func Strike(input string) string
- func Stripper(input string) string
- func Underline(input string) string
- type FloodTrack
- type IRCClient
- func (Config *IRCClient) Action(to string, message string)
- func (Config *IRCClient) Close()
- func (Config *IRCClient) Connect() bool
- func (Config *IRCClient) GetNick() string
- func (Config *IRCClient) IsAuto(channel string) bool
- func (Config *IRCClient) Msg(to string, message string)
- func (Config *IRCClient) Notice(to string, message string)
- func (Config *IRCClient) PriorityWrite(output string)
- func (Config *IRCClient) ReaderRoutine()
- func (Config *IRCClient) SetNick(nick string)
- func (Config *IRCClient) WriteTo(to string, output string)
- func (Config *IRCClient) WriterRoutine()
- type IRCConfig
- type IRCMsg
- type IRCWrite
- type ThrottleBuffer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var VERSION string = GetModuleVersion()
get client version information from runtime package.
Functions ¶
func ColorString ¶
Format a string with the given color code, and reset.
func GetModuleVersion ¶
func GetModuleVersion() string
func GetVersion ¶
Get Go version, arch, and OS. Get git commit hash.
func RandomNick ¶
Generate random nick to change to (upon collision/433)
Types ¶
type FloodTrack ¶
type FloodTrack struct { Pos int // Index to store next item Size int // Max number of Track items Timeout int // Timeout in seconds Track []time.Time }
Track when the client last sent something
func (*FloodTrack) Full ¶
func (F *FloodTrack) Full() bool
Are we full?
Expire records before checking.
func (*FloodTrack) Init ¶
func (F *FloodTrack) Init(size int, timeout int)
Initialize flood tracking
type IRCClient ¶
type IRCClient struct { IRCConfig MyNick string // Client's current nick OnExit func() // Called on exit Socket net.Conn // Connection to IRCD Reader *bufio.Reader // For reading a line at a time from the IRCD ReadChannel chan IRCMsg // Channel of parsed IRC Messages ReadEvents []string // WriteChannel chan IRCWrite // Channel for writing messages to IRCD DelChannel chan string // For deleting channel or nicks that are missing. Registered bool // Registered with services? ISupport map[string]string // IRCD capabilities (005) Mutex sync.Mutex // Guards MyNick // contains filtered or unexported fields }
func (*IRCClient) Connect ¶
Connect to IRCD and authenticate.
This starts the ReaderRoutine to handle processing the lines from the IRCD. You must setup ReadChannel if you want to process any messages.
Example ¶
package main import ( "fmt" ircclient "git.red-green.com/RedGreen/irc-client" ) func main() { var FromIRC chan ircclient.IRCMsg = make(chan ircclient.IRCMsg) var config ircclient.IRCConfig = ircclient.IRCConfig{Port: 6667, Hostname: "irc.libera.chat", Nick: "go-bot-test", Username: "gobot", Realname: "Bot Testing", AutoJoin: []string{"##bugz"}, } var irc ircclient.IRCClient = ircclient.IRCClient{IRCConfig: config, ReadChannel: FromIRC} irc.Connect() defer irc.Close() var Msg ircclient.IRCMsg for Msg = range irc.ReadChannel { // View all the commands: // fmt.Printf("%#v\n", Msg) switch Msg.Cmd { case "EndMOTD": // Ok! we're connected. fmt.Println("Connected") break case "333": // Joined channel, say something and quit. irc.Msg("##bugz", "Hello!") irc.WriteTo("", "QUIT") break case "PRIVMSG": break } } // Uncomment to test connection // Output: Connected }
Output:
func (*IRCClient) PriorityWrite ¶
PriorityWrite: Send output command to server immediately.
This is never throttled.
func (*IRCClient) ReaderRoutine ¶
func (Config *IRCClient) ReaderRoutine()
Goroutine reader routine
This reads a line at a time, delimited by '\n'. Auto-replies to server PING. Converts CTCP & ACTION messages to type CTCP/ACTION. Automatically answers /VERSION and /TIME. Handles SASL authentication. Rejoins AutoJoin channels kicked from.
func (*IRCClient) WriterRoutine ¶
func (Config *IRCClient) WriterRoutine()
WriterRoutine a goroutine that handles flood control
type IRCConfig ¶
type IRCConfig struct { Port int `json:"Port"` // IRC Connection port Hostname string `json:"Hostname"` // Hostname for connection UseTLS bool `json:"UseTLS"` // Use TLS Secure connection UseSASL bool `json:"UseSASL"` // Authenticate via SASL Insecure bool `json:"Insecure"` // Allow self-signed certificates Nick string `json:"Nick"` // Client's nick Username string `json:"Username"` // Client's username Realname string `json:"Realname"` // Client's realname Password string `json:"Password"` // Password for nickserv ServerPassword string `json:"ServerPassword"` // Password for server AutoJoin []string `json:"AutoJoin"` // Channels to auto-join RejoinDelay int `json:"RejoinDelay"` // ms to rejoin Version string `json:"Version"` // Version displayed Flood_Num int `json:"FloodNum"` // Number of lines sent before considered a flood Flood_Time int `json:"FloodTime"` // Number of Seconds to track previous messages Flood_Delay int `json:"FloodDelay"` // Delay between sending when flood protection on (Milliseconds) Debug_Output bool `json:"Debug"` // Enable debug output }
Configuration
type IRCMsg ¶
type IRCMsg struct { MsgParts []string // Message parts From string // Message From To string // Message To Cmd string // Command Msg string // Message }
IRC Message
type IRCWrite ¶
Sent to writer
The To part allows the writer to throttle messages to a specific target. When throttled, it delays and alternates between the targets.
type ThrottleBuffer ¶
type ThrottleBuffer struct { Life_sucks bool // Is throttle active? // contains filtered or unexported fields }
func (*ThrottleBuffer) Init ¶
func (T *ThrottleBuffer) Init()