Documentation ΒΆ
Overview ΒΆ
Package girc provides a high level, yet flexible IRC library for use with interacting with IRC servers. girc has support for user/channel tracking, as well as a few other neat features (like auto-reconnect).
Much of what girc can do, can also be disabled. The goal is to provide a solid API that you don't necessarily have to work with out of the box if you don't want to.
See the examples below for a few brief and useful snippets taking advantage of girc, which should give you a general idea of how the API works.
Example (Bare) ΒΆ
The bare-minimum needed to get started with girc. Just connects and idles.
package main import ( "log" "os" "github.com/lrstanley/girc" ) func main() { client := girc.New(girc.Config{ Server: "irc.byteirc.org", Port: 6667, Nick: "test", User: "user", Debug: os.Stdout, }) if err := client.Connect(); err != nil { log.Fatal(err) } }
Output:
Example (Commands) ΒΆ
Another basic example, however with this, we add simple !<command> responses to things. E.g. "!hello", "!stop", and "!restart".
package main import ( "log" "os" "strings" "github.com/lrstanley/girc" ) func main() { client := girc.New(girc.Config{ Server: "irc.byteirc.org", Port: 6667, Nick: "test", User: "user", Name: "Example bot", Out: os.Stdout, }) client.Handlers.Add(girc.CONNECTED, func(c *girc.Client, e girc.Event) { c.Cmd.Join("#channel", "#other-channel") }) client.Handlers.Add(girc.PRIVMSG, func(c *girc.Client, e girc.Event) { if strings.HasPrefix(e.Last(), "!hello") { c.Cmd.ReplyTo(e, girc.Fmt("{b}hello{b} {blue}world{c}!")) return } if strings.HasPrefix(e.Last(), "!stop") { c.Close() return } }) if err := client.Connect(); err != nil { log.Fatalf("an error occurred while attempting to connect to %s: %s", client.Server(), err) } }
Output:
Example (Simple) ΒΆ
Very simple example that connects, joins a channel, and responds to "hello" with "hello world!".
package main import ( "log" "os" "strings" "time" "github.com/lrstanley/girc" ) func main() { client := girc.New(girc.Config{ Server: "irc.byteirc.org", Port: 6667, Nick: "test", User: "user", Name: "Example bot", Debug: os.Stdout, }) client.Handlers.Add(girc.CONNECTED, func(c *girc.Client, e girc.Event) { c.Cmd.Join("#dev") }) client.Handlers.Add(girc.PRIVMSG, func(c *girc.Client, e girc.Event) { if strings.Contains(e.Last(), "hello") { c.Cmd.ReplyTo(e, "hello world!") return } if strings.Contains(e.Last(), "quit") { c.Close() } }) // An example of how you would add reconnect logic. for { if err := client.Connect(); err != nil { log.Printf("error: %s", err) log.Println("reconnecting in 30 seconds...") time.Sleep(30 * time.Second) } else { return } } }
Output:
Index ΒΆ
- Constants
- Variables
- func DefaultRecoverHandler(client *Client, err *HandlerError)
- func EncodeCTCP(ctcp *CTCPEvent) (out string)
- func EncodeCTCPRaw(cmd, text string) (out string)
- func Fmt(text string) string
- func Glob(input, match string) bool
- func IsValidChannel(channel string) bool
- func IsValidChannelMode(raw string) bool
- func IsValidNick(nick string) bool
- func IsValidUser(name string) bool
- func StripRaw(text string) string
- func ToRFC1459(input string) string
- func TrimFmt(text string) string
- type CMode
- type CModes
- type CTCP
- type CTCPEvent
- type CTCPHandler
- type Caller
- func (c *Caller) Add(cmd string, handler func(client *Client, event Event)) (cuid string)
- func (c *Caller) AddBg(cmd string, handler func(client *Client, event Event)) (cuid string)
- func (c *Caller) AddHandler(cmd string, handler Handler) (cuid string)
- func (c *Caller) AddTmp(cmd string, deadline time.Duration, ...) (cuid string, done chan struct{})
- func (c *Caller) Clear(cmd string)
- func (c *Caller) ClearAll()
- func (c *Caller) Count(cmd string) int
- func (c *Caller) Len() int
- func (c *Caller) Remove(cuid string) (success bool)
- func (c *Caller) String() string
- type Channel
- type Client
- func (c *Client) ChannelList() []string
- func (c *Client) Channels() []*Channel
- func (c *Client) Close()
- func (c *Client) ConnSince() (since *time.Duration, err error)
- func (c *Client) Connect() error
- func (c *Client) DialerConnect(dialer Dialer) error
- func (c *Client) DisableTracking()
- func (c *Client) GetHost() (host string)
- func (c *Client) GetID() string
- func (c *Client) GetIdent() string
- func (c *Client) GetNick() string
- func (c *Client) GetServerOption(key string) (result string, ok bool)
- func (c *Client) GetServerOptionInt(key string) (result int, ok bool)
- func (c *Client) HasCapability(name string) (has bool)
- func (c *Client) IsConnected() bool
- func (c *Client) IsInChannel(channel string) (in bool)
- func (c *Client) Latency() (delta time.Duration)
- func (c *Client) Lifetime() time.Duration
- func (c *Client) LookupChannel(name string) (channel *Channel)
- func (c *Client) LookupUser(nick string) (user *User)
- func (c *Client) MaxEventLength() (max int)
- func (c *Client) MockConnect(conn net.Conn) error
- func (c *Client) NetworkName() (name string)
- func (c *Client) Quit(reason string)
- func (c *Client) RunHandlers(event *Event)
- func (c *Client) Send(event *Event)
- func (c *Client) Server() string
- func (c *Client) ServerMOTD() (motd string)
- func (c *Client) ServerVersion() (version string)
- func (c *Client) String() string
- func (c *Client) TLSConnectionState() (*tls.ConnectionState, error)
- func (c *Client) Uptime() (up *time.Time, err error)
- func (c *Client) UserList() []string
- func (c *Client) Users() []*User
- type Commands
- func (cmd *Commands) Action(target, message string)
- func (cmd *Commands) Actionf(target, format string, a ...interface{})
- func (cmd *Commands) Away(reason string)
- func (cmd *Commands) Back()
- func (cmd *Commands) Ban(channel, mask string)
- func (cmd *Commands) Invite(channel string, users ...string)
- func (cmd *Commands) Join(channels ...string)
- func (cmd *Commands) JoinKey(channel, password string)
- func (cmd *Commands) Kick(channel, user, reason string)
- func (cmd *Commands) List(channels ...string)
- func (cmd *Commands) Message(target, message string)
- func (cmd *Commands) Messagef(target, format string, a ...interface{})
- func (cmd *Commands) Mode(target, modes string, params ...string)
- func (cmd *Commands) Monitor(modifier rune, args ...string)
- func (cmd *Commands) Nick(name string)
- func (cmd *Commands) Notice(target, message string)
- func (cmd *Commands) Noticef(target, format string, a ...interface{})
- func (cmd *Commands) Oper(user, pass string)
- func (cmd *Commands) Part(channels ...string)
- func (cmd *Commands) PartMessage(channel, message string)
- func (cmd *Commands) Ping(id string)
- func (cmd *Commands) Pong(id string)
- func (cmd *Commands) Reply(event Event, message string)
- func (cmd *Commands) ReplyTo(event Event, message string)
- func (cmd *Commands) ReplyTof(event Event, format string, a ...interface{})
- func (cmd *Commands) Replyf(event Event, format string, a ...interface{})
- func (cmd *Commands) SendCTCP(target, ctcpType, message string)
- func (cmd *Commands) SendCTCPReply(target, ctcpType, message string)
- func (cmd *Commands) SendCTCPReplyf(target, ctcpType, format string, a ...interface{})
- func (cmd *Commands) SendCTCPf(target, ctcpType, format string, a ...interface{})
- func (cmd *Commands) SendRaw(raw ...string) error
- func (cmd *Commands) SendRawf(format string, a ...interface{}) error
- func (cmd *Commands) Topic(channel, message string)
- func (cmd *Commands) Unban(channel, mask string)
- func (cmd *Commands) Who(users ...string)
- func (cmd *Commands) Whois(users ...string)
- func (cmd *Commands) Whowas(user string, amount int)
- type Config
- type Dialer
- type ErrEvent
- type ErrInvalidConfig
- type ErrParseEvent
- type ErrSTSUpgradeFailed
- type ErrTimedOut
- type Event
- func (e *Event) Bytes() []byte
- func (e *Event) Copy() *Event
- func (e *Event) Equals(ev *Event) bool
- func (e *Event) IsAction() bool
- func (e *Event) IsCTCP() (ok bool, ctcp *CTCPEvent)
- func (e *Event) IsFromChannel() bool
- func (e *Event) IsFromUser() bool
- func (e *Event) Last() string
- func (e *Event) Len() (length int)
- func (e *Event) LenOpts(includeTags bool) (length int)
- func (e *Event) Pretty() (out string, ok bool)
- func (e *Event) String() string
- func (e *Event) StripAction() string
- type Handler
- type HandlerError
- type HandlerFunc
- type Perms
- type SASLExternal
- type SASLMech
- type SASLPlain
- type Source
- type Tags
- func (t Tags) Bytes() []byte
- func (t Tags) Count() int
- func (t Tags) Equals(tt Tags) bool
- func (t Tags) Get(key string) (tag string, success bool)
- func (t Tags) Keys() (keys []string)
- func (t Tags) Len() (length int)
- func (t Tags) Remove(key string) (success bool)
- func (t Tags) Set(key, value string) error
- func (t Tags) String() string
- type User
- type UserPerms
- type WebIRC
Examples ΒΆ
Constants ΒΆ
const ( CTCP_ACTION = "ACTION" CTCP_PING = "PING" CTCP_PONG = "PONG" CTCP_VERSION = "VERSION" CTCP_USERINFO = "USERINFO" CTCP_CLIENTINFO = "CLIENTINFO" CTCP_SOURCE = "SOURCE" CTCP_TIME = "TIME" CTCP_FINGER = "FINGER" CTCP_ERRMSG = "ERRMSG" )
Standard CTCP based constants.
const ( UPDATE_STATE = "CLIENT_STATE_UPDATED" // when channel/user state is updated. UPDATE_GENERAL = "CLIENT_GENERAL_UPDATED" // when general state (client nick, server name, etc) is updated. ALL_EVENTS = "*" // trigger on all events CONNECTED = "CLIENT_CONNECTED" // when it's safe to send arbitrary commands (joins, list, who, etc), trailing is host:port INITIALIZED = "CLIENT_INIT" // verifies successful socket connection, trailing is host:port DISCONNECTED = "CLIENT_DISCONNECTED" // occurs when we're disconnected from the server (user-requested or not) CLOSED = "CLIENT_CLOSED" // occurs when Client.Close() has been called STS_UPGRADE_INIT = "STS_UPGRADE_INIT" // when an STS upgrade initially happens. STS_ERR_FALLBACK = "STS_ERR_FALLBACK" // when an STS connection fails and fallbacks are supported. )
Emulated event commands used to allow easier hooks into the changing state of the client.
const ( DefaultPrefixes = "(ov)@+" // the most common default prefixes ModeAddPrefix = "+" // modes are being added ModeDelPrefix = "-" // modes are being removed ChannelPrefix = "#" // regular channel DistributedPrefix = "&" // distributed channel OwnerPrefix = "~" // user owner +q (non-rfc) AdminPrefix = "&" // user admin +a (non-rfc) HalfOperatorPrefix = "%" // user half operator +h (non-rfc) OperatorPrefix = "@" // user operator +o VoicePrefix = "+" // user has voice +v )
User/channel prefixes :: RFC1459.
const ( UserModeInvisible = "i" // invisible UserModeOperator = "o" // server operator UserModeServerNotices = "s" // user wants to receive server notices UserModeWallops = "w" // user wants to receive wallops )
User modes :: RFC1459; section 4.2.3.2.
const ( ModeDefaults = "beI,k,l,imnpst" // the most common default modes ModeInviteOnly = "i" // only join with an invite ModeKey = "k" // channel password ModeLimit = "l" // user limit ModeModerated = "m" // only voiced users and operators can talk ModeOperator = "o" // operator ModePrivate = "p" // private ModeSecret = "s" // secret ModeTopic = "t" // must be op to set topic ModeVoice = "v" // speak during moderation mode ModeOwner = "q" // owner privileges (non-rfc) ModeAdmin = "a" // admin privileges (non-rfc) ModeHalfOperator = "h" // half-operator privileges (non-rfc) )
Channel modes :: RFC1459; section 4.2.3.1.
const ( ADMIN = "ADMIN" AWAY = "AWAY" CONNECT = "CONNECT" DIE = "DIE" ERROR = "ERROR" INFO = "INFO" INVITE = "INVITE" ISON = "ISON" JOIN = "JOIN" KICK = "KICK" KILL = "KILL" LINKS = "LINKS" LIST = "LIST" LUSERS = "LUSERS" MODE = "MODE" MOTD = "MOTD" NAMES = "NAMES" NICK = "NICK" NJOIN = "NJOIN" NOTICE = "NOTICE" OPER = "OPER" PART = "PART" PASS = "PASS" PING = "PING" PONG = "PONG" PRIVMSG = "PRIVMSG" QUIT = "QUIT" REHASH = "REHASH" RESTART = "RESTART" SERVER = "SERVER" SERVICE = "SERVICE" SERVLIST = "SERVLIST" SQUERY = "SQUERY" SQUIT = "SQUIT" STATS = "STATS" SUMMON = "SUMMON" TIME = "TIME" TOPIC = "TOPIC" TRACE = "TRACE" USER = "USER" USERHOST = "USERHOST" USERS = "USERS" VERSION = "VERSION" WALLOPS = "WALLOPS" WEBIRC = "WEBIRC" WHO = "WHO" WHOIS = "WHOIS" WHOWAS = "WHOWAS" )
IRC commands :: RFC2812; section 3 :: RFC2813; section 4.
const ( RPL_WELCOME = "001" RPL_YOURHOST = "002" RPL_CREATED = "003" RPL_MYINFO = "004" RPL_BOUNCE = "005" RPL_ISUPPORT = "005" RPL_USERHOST = "302" RPL_ISON = "303" RPL_AWAY = "301" RPL_UNAWAY = "305" RPL_NOWAWAY = "306" RPL_WHOISREGNICK = "307" RPL_WHOISUSER = "311" RPL_WHOISSERVER = "312" RPL_WHOISOPERATOR = "313" RPL_WHOISIDLE = "317" RPL_ENDOFWHOIS = "318" RPL_WHOISCHANNELS = "319" RPL_WHOWASUSER = "314" RPL_ENDOFWHOWAS = "369" RPL_WHOISSPECIAL = "320" RPL_LISTSTART = "321" RPL_LIST = "322" RPL_LISTEND = "323" //nolint:misspell // it's correct. RPL_UNIQOPIS = "325" RPL_CHANNELMODEIS = "324" RPL_WHOISACCOUNT = "330" RPL_NOTOPIC = "331" RPL_TOPIC = "332" RPL_INVITELIST = "336" RPL_ENDOFINVITELIST = "337" RPL_WHOISACTUALLY = "338" RPL_INVITING = "341" RPL_SUMMONING = "342" RPL_INVEXLIST = "346" RPL_ENDOFINVEXLIST = "347" RPL_EXCEPTLIST = "348" RPL_ENDOFEXCEPTLIST = "349" RPL_VERSION = "351" RPL_WHOREPLY = "352" RPL_ENDOFWHO = "315" RPL_NAMREPLY = "353" RPL_ENDOFNAMES = "366" RPL_LINKS = "364" RPL_ENDOFLINKS = "365" RPL_BANLIST = "367" RPL_ENDOFBANLIST = "368" RPL_INFO = "371" RPL_ENDOFINFO = "374" RPL_MOTDSTART = "375" RPL_MOTD = "372" RPL_ENDOFMOTD = "376" RPL_WHOISHOST = "378" RPL_WHOISMODES = "379" RPL_YOUREOPER = "381" RPL_REHASHING = "382" RPL_YOURESERVICE = "383" RPL_TIME = "391" RPL_USERSSTART = "392" RPL_USERS = "393" RPL_ENDOFUSERS = "394" RPL_NOUSERS = "395" RPL_TRACELINK = "200" RPL_TRACECONNECTING = "201" RPL_TRACEHANDSHAKE = "202" RPL_TRACEUNKNOWN = "203" RPL_TRACEOPERATOR = "204" RPL_TRACEUSER = "205" RPL_TRACESERVER = "206" RPL_TRACESERVICE = "207" RPL_TRACENEWTYPE = "208" RPL_TRACECLASS = "209" RPL_TRACERECONNECT = "210" RPL_TRACELOG = "261" RPL_TRACEEND = "262" RPL_STATSLINKINFO = "211" RPL_STATSCOMMANDS = "212" RPL_ENDOFSTATS = "219" RPL_STATSUPTIME = "242" RPL_STATSOLINE = "243" RPL_UMODEIS = "221" RPL_SERVLIST = "234" RPL_SERVLISTEND = "235" RPL_LUSERCLIENT = "251" RPL_LUSEROP = "252" RPL_LUSERUNKNOWN = "253" RPL_LUSERCHANNELS = "254" RPL_LUSERME = "255" RPL_ADMINME = "256" RPL_ADMINLOC1 = "257" RPL_ADMINLOC2 = "258" RPL_ADMINEMAIL = "259" RPL_TRYAGAIN = "263" RPL_WHOISCERTFP = "276" ERR_NOSUCHNICK = "401" ERR_NOSUCHSERVER = "402" ERR_NOSUCHCHANNEL = "403" ERR_CANNOTSENDTOCHAN = "404" ERR_TOOMANYCHANNELS = "405" ERR_WASNOSUCHNICK = "406" ERR_TOOMANYTARGETS = "407" ERR_NOSUCHSERVICE = "408" ERR_NOORIGIN = "409" ERR_NORECIPIENT = "411" ERR_NOTEXTTOSEND = "412" ERR_NOTOPLEVEL = "413" ERR_WILDTOPLEVEL = "414" ERR_BADMASK = "415" ERR_INPUTTOOLONG = "417" ERR_UNKNOWNCOMMAND = "421" ERR_NOMOTD = "422" ERR_NOADMININFO = "423" ERR_FILEERROR = "424" ERR_NONICKNAMEGIVEN = "431" ERR_ERRONEUSNICKNAME = "432" ERR_NICKNAMEINUSE = "433" ERR_NICKCOLLISION = "436" ERR_UNAVAILRESOURCE = "437" ERR_USERNOTINCHANNEL = "441" ERR_NOTONCHANNEL = "442" ERR_USERONCHANNEL = "443" ERR_NOLOGIN = "444" ERR_SUMMONDISABLED = "445" ERR_USERSDISABLED = "446" ERR_NOTREGISTERED = "451" ERR_NEEDMOREPARAMS = "461" ERR_ALREADYREGISTRED = "462" ERR_NOPERMFORHOST = "463" ERR_PASSWDMISMATCH = "464" ERR_YOUREBANNEDCREEP = "465" ERR_YOUWILLBEBANNED = "466" ERR_KEYSET = "467" ERR_CHANNELISFULL = "471" ERR_UNKNOWNMODE = "472" ERR_INVITEONLYCHAN = "473" ERR_BANNEDFROMCHAN = "474" ERR_BADCHANNELKEY = "475" ERR_BADCHANMASK = "476" ERR_NOCHANMODES = "477" ERR_BANLISTFULL = "478" ERR_NOPRIVILEGES = "481" ERR_CHANOPRIVSNEEDED = "482" ERR_CANTKILLSERVER = "483" ERR_RESTRICTED = "484" ERR_UNIQOPPRIVSNEEDED = "485" ERR_NOOPERHOST = "491" ERR_UMODEUNKNOWNFLAG = "501" ERR_USERSDONTMATCH = "502" )
Numeric IRC reply mapping :: RFC2812; section 5.
const ( AUTHENTICATE = "AUTHENTICATE" MONITOR = "MONITOR" STARTTLS = "STARTTLS" CAP = "CAP" CAP_ACK = "ACK" CAP_CLEAR = "CLEAR" CAP_END = "END" CAP_LIST = "LIST" CAP_LS = "LS" CAP_NAK = "NAK" CAP_REQ = "REQ" CAP_NEW = "NEW" CAP_DEL = "DEL" CAP_CHGHOST = "CHGHOST" CAP_AWAY = "AWAY" CAP_ACCOUNT = "ACCOUNT" CAP_TAGMSG = "TAGMSG" )
IRCv3 commands and extensions :: http://ircv3.net/irc/.
const ( RPL_LOGGEDIN = "900" RPL_LOGGEDOUT = "901" RPL_NICKLOCKED = "902" RPL_SASLSUCCESS = "903" ERR_SASLFAIL = "904" ERR_SASLTOOLONG = "905" ERR_SASLABORTED = "906" ERR_SASLALREADY = "907" RPL_SASLMECHS = "908" RPL_STARTTLS = "670" ERR_STARTTLS = "691" RPL_MONONLINE = "730" RPL_MONOFFLINE = "731" RPL_MONLIST = "732" RPL_ENDOFMONLIST = "733" ERR_MONLISTFULL = "734" )
Numeric IRC reply mapping for ircv3 :: http://ircv3.net/irc/.
const ( RPL_STATSCLINE = "213" RPL_STATSNLINE = "214" RPL_STATSILINE = "215" RPL_STATSKLINE = "216" RPL_STATSQLINE = "217" RPL_STATSYLINE = "218" RPL_SERVICEINFO = "231" RPL_ENDOFSERVICES = "232" RPL_SERVICE = "233" RPL_STATSVLINE = "240" RPL_STATSLLINE = "241" RPL_STATSHLINE = "244" RPL_STATSSLINE = "245" RPL_STATSPING = "246" RPL_STATSBLINE = "247" RPL_STATSDLINE = "250" RPL_NONE = "300" RPL_WHOISCHANOP = "316" RPL_KILLDONE = "361" RPL_CLOSING = "362" RPL_CLOSEEND = "363" RPL_INFOSTART = "373" RPL_MYPORTIS = "384" ERR_NOSERVICEHOST = "492" )
Numeric IRC event mapping :: RFC2812; section 5.3.
const ( ERR_TOOMANYMATCHES = "416" // IRCNet. RPL_GLOBALUSERS = "266" // aircd/hybrid/bahamut, used on freenode. RPL_LOCALUSERS = "265" // aircd/hybrid/bahamut, used on freenode. RPL_TOPICWHOTIME = "333" // ircu, used on freenode. RPL_WHOSPCRPL = "354" // ircu, used on networks with WHOX support. RPL_CREATIONTIME = "329" )
Misc.
Variables ΒΆ
var ( // DefaultMaxLineLength is the default maximum length for an event. 510 (+2 for line endings) // is used as a default as this is used by many older implementations. // // See also: RFC 2812 // IRC messages are always lines of characters terminated with a CR-LF // (Carriage Return - Line Feed) pair, and these messages SHALL NOT // exceed 512 characters in length, counting all characters including // the trailing CR-LF. DefaultMaxLineLength = 510 // DefaultMaxPrefixLength defines the default max ":nickname!user@host " length // that's used to calculate line splitting. DefaultMaxPrefixLength = defaultPrefixPadding + defaultNickLength + defaultUserLength + defaultHostLength )
var ErrConnNotTLS = errors.New("underlying connection is not tls")
ErrConnNotTLS is returned when Client.TLSConnectionState() is called, and the connection to the server wasn't made with TLS.
var ErrInvalidSource = errors.New("event has nil or invalid source address")
ErrInvalidSource is returned when a method needs to know the origin of an event, however Event.Source is unknown (e.g. sent by the user, not the server.)
var ErrNotConnected = errors.New("client is not connected to server")
ErrNotConnected is returned if a method is used when the client isn't connected.
Functions ΒΆ
func DefaultRecoverHandler ΒΆ
func DefaultRecoverHandler(client *Client, err *HandlerError)
DefaultRecoverHandler can be used with Config.RecoverFunc as a default catch-all for panics. This will log the error, and the call trace to the debug log (see Config.Debug), or os.Stdout if Config.Debug is unset.
func EncodeCTCP ΒΆ
EncodeCTCP encodes a CTCP event into a string, including delimiters.
func EncodeCTCPRaw ΒΆ
EncodeCTCPRaw is much like EncodeCTCP, however accepts a raw command and string as input.
func Fmt ΒΆ
Fmt takes format strings like "{red}" or "{red,blue}" (for background colors) and turns them into the resulting ASCII format/color codes for IRC. See format.go for the list of supported format codes allowed.
For example:
client.Message("#channel", Fmt("{red}{b}Hello {red,blue}World{c}"))
func Glob ΒΆ
Glob will test a string pattern, potentially containing globs, against a string. The glob character is *.
func IsValidChannel ΒΆ
IsValidChannel validates if channel is an RFC compliant channel or not.
NOTE: If you are using this to validate a channel that contains a channel ID, (!<channelid>NAME), this only supports the standard 5 character length.
NOTE: If you do not need to validate against servers that support unicode, you may want to ensure that all channel chars are within the range of all ASCII printable chars. This function will NOT do that for compatibility reasons.
channel = ( "#" / "+" / ( "!" channelid ) / "&" ) chanstring [ ":" chanstring ] chanstring = 0x01-0x07 / 0x08-0x09 / 0x0B-0x0C / 0x0E-0x1F / 0x21-0x2B chanstring = / 0x2D-0x39 / 0x3B-0xFF ; any octet except NUL, BELL, CR, LF, " ", "," and ":" channelid = 5( 0x41-0x5A / digit ) ; 5( A-Z / 0-9 )
func IsValidChannelMode ΒΆ
IsValidChannelMode validates a channel mode (CHANMODES).
func IsValidNick ΒΆ
IsValidNick validates an IRC nickname. Note that this does not validate IRC nickname length.
nickname = ( letter / special ) *8( letter / digit / special / "-" ) letter = 0x41-0x5A / 0x61-0x7A digit = 0x30-0x39 special = 0x5B-0x60 / 0x7B-0x7D
func IsValidUser ΒΆ
IsValidUser validates an IRC ident/username. Note that this does not validate IRC ident length.
The validation checks are much like what characters are allowed with an IRC nickname (see IsValidNick()), however an ident/username can:
1. Must either start with alphanumberic char, or "~" then alphanumberic char.
2. Contain a "." (period), for use with "first.last". Though, this may not be supported on all networks. Some limit this to only a single period.
Per RFC:
user = 1*( %x01-09 / %x0B-0C / %x0E-1F / %x21-3F / %x41-FF ) ; any octet except NUL, CR, LF, " " and "@"
func StripRaw ΒΆ
StripRaw tries to strip all ASCII format codes that are used for IRC. Primarily, foreground/background colors, and other control bytes like reset, bold, italic, reverse, etc. This also is done in a specific way in order to ensure no truncation of other non-irc formatting.
func ToRFC1459 ΒΆ
ToRFC1459 converts a string to the stripped down conversion within RFC 1459. This will do things like replace an "A" with an "a", "[]" with "{}", and so forth. Useful to compare two nicknames or channels. Note that this should not be used to normalize nicknames or similar, as this may convert valid input characters to non-rfc-valid characters. As such, it's main use is for comparing two nicks.
Types ΒΆ
type CMode ΒΆ
type CMode struct {
// contains filtered or unexported fields
}
CMode represents a single step of a given mode change.
type CModes ΒΆ
type CModes struct {
// contains filtered or unexported fields
}
CModes is a representation of a set of modes. This may be the given state of a channel/user, or the given state changes to a given channel/user.
func NewCModes ΒΆ
NewCModes returns a new CModes reference. channelModes and userPrefixes would be something you see from the server's "CHANMODES" and "PREFIX" ISUPPORT capability messages (alternatively, fall back to the standard) DefaultPrefixes and ModeDefaults.
func (*CModes) Apply ΒΆ
Apply merges two state changes, or one state change into a state of modes. For example, the latter would mean applying an incoming MODE with the modes stored for a channel.
func (*CModes) Get ΒΆ
Get returns the arguments for a given mode within this session, if it supports args.
type CTCP ΒΆ
type CTCP struct {
// contains filtered or unexported fields
}
CTCP handles the storage and execution of CTCP handlers against incoming CTCP events.
func (*CTCP) ClearAll ΒΆ
func (c *CTCP) ClearAll()
ClearAll removes all currently setup and re-sets the default handlers.
type CTCPEvent ΒΆ
type CTCPEvent struct { // Origin is the original event that the CTCP event was decoded from. Origin *Event `json:"origin"` // Source is the author of the CTCP event. Source *Source `json:"source"` // Command is the type of CTCP event. E.g. PING, TIME, VERSION. Command string `json:"command"` // Text is the raw arguments following the command. Text string `json:"text"` // Reply is true if the CTCP event is intended to be a reply to a // previous CTCP (e.g, if we sent one). Reply bool `json:"reply"` }
CTCPEvent is the necessary information from an IRC message.
func DecodeCTCP ΒΆ
DecodeCTCP decodes an incoming CTCP event, if it is CTCP. nil is returned if the incoming event does not have valid CTCP encoding.
type CTCPHandler ΒΆ
CTCPHandler is a type that represents the function necessary to implement a CTCP handler.
type Caller ΒΆ
type Caller struct {
// contains filtered or unexported fields
}
Caller manages internal and external (user facing) handlers.
func (*Caller) Add ΒΆ
Add registers the handler function for the given event. cuid is the handler uid which can be used to remove the handler with Caller.Remove().
func (*Caller) AddBg ΒΆ
AddBg registers the handler function for the given event and executes it in a go-routine. cuid is the handler uid which can be used to remove the handler with Caller.Remove().
func (*Caller) AddHandler ΒΆ
AddHandler registers a handler (matching the handler interface) for the given event. cuid is the handler uid which can be used to remove the handler with Caller.Remove().
func (*Caller) AddTmp ΒΆ
func (c *Caller) AddTmp(cmd string, deadline time.Duration, handler func(client *Client, event Event) bool) (cuid string, done chan struct{})
AddTmp adds a "temporary" handler, which is good for one-time or few-time uses. This supports a deadline and/or manual removal, as this differs much from how normal handlers work. An example of a good use for this would be to capture the entire output of a multi-response query to the server. (e.g. LIST, WHOIS, etc)
The supplied handler is able to return a boolean, which if true, will remove the handler from the handler stack.
Additionally, AddTmp has a useful option, deadline. When set to greater than 0, deadline will be the amount of time that passes before the handler is removed from the stack, regardless of if the handler returns true or not. This is useful in that it ensures that the handler is cleaned up if the server does not respond appropriately, or takes too long to respond.
Note that handlers supplied with AddTmp are executed in a goroutine to ensure that they are not blocking other handlers. However, if you are creating a temporary handler from another handler, it should be a background handler.
Use cuid with Caller.Remove() to prematurely remove the handler from the stack, bypassing the timeout or waiting for the handler to return that it wants to be removed from the stack.
func (*Caller) Clear ΒΆ
Clear clears all of the handlers for the given event. This ignores internal handlers.
func (*Caller) ClearAll ΒΆ
func (c *Caller) ClearAll()
ClearAll clears all external handlers currently setup within the client. This ignores internal handlers.
func (*Caller) Count ΒΆ
Count is much like Caller.Len(), however it counts the number of registered handlers for a given command.
type Channel ΒΆ
type Channel struct { // Name of the channel. Must be rfc1459 compliant. Name string `json:"name"` // Topic of the channel. Topic string `json:"topic"` // UserList is a sorted list of all users we are currently tracking within // the channel. Each is the nickname, and is rfc1459 compliant. UserList []string `json:"user_list"` // Joined represents the first time that the client joined the channel. Joined time.Time `json:"joined"` // Modes are the known channel modes that the bot has captured. Modes CModes `json:"modes"` }
Channel represents an IRC channel and the state attached to it.
func (Channel) Admins ΒΆ
Admins returns a list of users which have half-op (if supported), or greater permissions (op, admin, owner, etc) in the given channel. See Perms.IsAdmin() for more information.
func (*Channel) Lifetime ΒΆ
Lifetime represents the amount of time that has passed since we have first joined the channel.
func (Channel) Trusted ΒΆ
Trusted returns a list of users which have voice or greater in the given channel. See Perms.IsTrusted() for more information.
type Client ΒΆ
type Client struct { // Config represents the configuration. Please take extra caution in that // entries in this are not edited while the client is connected, to prevent // data races. This is NOT concurrent safe to update. Config Config // Handlers is a handler which manages internal and external handlers. Handlers *Caller // CTCP is a handler which manages internal and external CTCP handlers. CTCP *CTCP // Cmd contains various helper methods to interact with the server. Cmd *Commands // contains filtered or unexported fields }
Client contains all of the information necessary to run a single IRC client.
func New ΒΆ
New creates a new IRC client with the specified server, name and config.
Example ΒΆ
package main import ( "log" "os" "github.com/lrstanley/girc" ) func main() { client := girc.New(girc.Config{ Server: "irc.byteirc.org", Port: 6667, Nick: "test", User: "user", SASL: &girc.SASLPlain{User: "user1", Pass: "securepass1"}, Out: os.Stdout, }) if err := client.Connect(); err != nil { log.Fatal(err) } }
Output:
func (*Client) ChannelList ΒΆ
ChannelList returns the (sorted) active list of channel names that the client is in. Panics if tracking is disabled.
func (*Client) Channels ΒΆ
Channels returns the (sorted) active channels that the client is in. Panics if tracking is disabled.
func (*Client) Close ΒΆ
func (c *Client) Close()
Close closes the network connection to the server, and sends a CLOSED event. This should cause Connect() to return with nil. This should be safe to call multiple times. See Connect()'s documentation on how handlers and goroutines are handled when disconnected from the server.
func (*Client) ConnSince ΒΆ
ConnSince is the duration that has past since the client successfully connected to the server.
func (*Client) Connect ΒΆ
Connect attempts to connect to the given IRC server. Returns only when an error has occurred, or a disconnect was requested with Close(). Connect will only return once all client-based goroutines have been closed to ensure there are no long-running routines becoming backed up.
Connect will wait for all non-goroutine handlers to complete on error/quit, however it will not wait for goroutine-based handlers.
If this returns nil, this means that the client requested to be closed (e.g. Client.Close()). Connect will panic if called when the last call has not completed.
func (*Client) DialerConnect ΒΆ
DialerConnect allows you to specify your own custom dialer which implements the Dialer interface.
An example of using this library would be to take advantage of the golang.org/x/net/proxy library:
proxyUrl, _ := proxyURI, err = url.Parse("socks5://1.2.3.4:8888") dialer, _ := proxy.FromURL(proxyURI, &net.Dialer{Timeout: 5 * time.Second}) _ := girc.DialerConnect(dialer)
func (*Client) DisableTracking ΒΆ
func (c *Client) DisableTracking()
DisableTracking disables all channel/user-level/CAP tracking, and clears all internal handlers. Useful for highly embedded scripts with single purposes. This cannot be un-done on a client.
func (*Client) GetHost ΒΆ
GetHost returns the current host of the active connection. Panics if tracking is disabled. May be empty, as this is obtained from when we join a channel, as there is no other more efficient method to return this info.
func (*Client) GetID ΒΆ
GetID returns an RFC1459 compliant version of the current nickname. Panics if tracking is disabled.
func (*Client) GetIdent ΒΆ
GetIdent returns the current ident of the active connection. Panics if tracking is disabled. May be empty, as this is obtained from when we join a channel, as there is no other more efficient method to return this info.
func (*Client) GetNick ΒΆ
GetNick returns the current nickname of the active connection. Panics if tracking is disabled.
func (*Client) GetServerOption ΒΆ
GetServerOption retrieves a server capability setting that was retrieved during client connection. This is also known as ISUPPORT (or RPL_PROTOCTL). Will panic if used when tracking has been disabled. Examples of usage:
nickLen, success := GetServerOption("MAXNICKLEN")
func (*Client) GetServerOptionInt ΒΆ
GetServerOptionInt retrieves a server capability setting (as an integer) that was retrieved during client connection. This is also known as ISUPPORT (or RPL_PROTOCTL). Will panic if used when tracking has been disabled. Examples of usage:
nickLen, success := GetServerOption("MAXNICKLEN")
func (*Client) HasCapability ΒΆ
HasCapability checks if the client connection has the given capability. If you want the full list of capabilities, listen for the girc.CAP_ACK event. Will panic if used when tracking has been disabled.
func (*Client) IsConnected ΒΆ
IsConnected returns true if the client is connected to the server.
func (*Client) IsInChannel ΒΆ
IsInChannel returns true if the client is in channel. Panics if tracking is disabled.
func (*Client) Latency ΒΆ
Latency is the latency between the server and the client. This is measured by determining the difference in time between when we ping the server, and when we receive a pong.
func (*Client) Lifetime ΒΆ
Lifetime returns the amount of time that has passed since the client was created.
func (*Client) LookupChannel ΒΆ
LookupChannel looks up a given channel in state. If the channel doesn't exist, nil is returned. Panics if tracking is disabled.
func (*Client) LookupUser ΒΆ
LookupUser looks up a given user in state. If the user doesn't exist, nil is returned. Panics if tracking is disabled.
func (*Client) MaxEventLength ΒΆ
MaxEventLength returns the maximum supported server length of an event. This is the maximum length of the command and arguments, excluding the source/prefix supported by the protocol. If state tracking is enabled, this will utilize ISUPPORT/IRCv3 information to more accurately calculate the maximum supported length (i.e. extended length events).
func (*Client) MockConnect ΒΆ
MockConnect is used to implement mocking with an IRC server. Supply a net.Conn that will be used to spoof the server. A useful way to do this is to so net.Pipe(), pass one end into MockConnect(), and the other end into bufio.NewReader().
For example:
client := girc.New(girc.Config{ Server: "dummy.int", Port: 6667, Nick: "test", User: "test", Name: "Testing123", }) in, out := net.Pipe() defer in.Close() defer out.Close() b := bufio.NewReader(in) go func() { if err := client.MockConnect(out); err != nil { panic(err) } }() defer client.Close(false) for { in.SetReadDeadline(time.Now().Add(300 * time.Second)) line, err := b.ReadString(byte('\n')) if err != nil { panic(err) } event := girc.ParseEvent(line) if event == nil { continue } // Do stuff with event here. }
func (*Client) NetworkName ΒΆ
NetworkName returns the network identifier. E.g. "EsperNet", "ByteIRC". May be empty if the server does not support RPL_ISUPPORT (or RPL_PROTOCTL). Will panic if used when tracking has been disabled.
func (*Client) Quit ΒΆ
Quit sends a QUIT message to the server with a given reason to close the connection. Underlying this event being sent, Client.Close() is called as well. This is different than just calling Client.Close() in that it provides a reason as to why the connection was closed (for bots to tell users the bot is restarting, or shutting down, etc).
NOTE: servers may delay showing of QUIT reasons, until you've been connected to the server for a certain period of time (e.g. 5 minutes). Keep this in mind.
func (*Client) RunHandlers ΒΆ
RunHandlers manually runs handlers for a given event.
func (*Client) Send ΒΆ
Send sends an event to the server. Send will split events if the event is longer than what the server supports, and is an event that supports splitting. Use Client.RunHandlers() if you are simply looking to trigger handlers with an event.
func (*Client) Server ΒΆ
Server returns the string representation of host+port pair for the connection.
func (*Client) ServerMOTD ΒΆ
ServerMOTD returns the servers message of the day, if the server has sent it upon connect. Will panic if used when tracking has been disabled.
func (*Client) ServerVersion ΒΆ
ServerVersion returns the server software version, if the server has supplied this information during connection. May be empty if the server does not support RPL_MYINFO. Will panic if used when tracking has been disabled.
func (*Client) TLSConnectionState ΒΆ
func (c *Client) TLSConnectionState() (*tls.ConnectionState, error)
TLSConnectionState returns the TLS connection state from tls.Conn{}, which is useful to return needed TLS fingerprint info, certificates, verify cert expiration dates, etc. Will only return an error if the underlying connection wasn't established using TLS (see ErrConnNotTLS), or if the client isn't connected.
func (*Client) Uptime ΒΆ
Uptime is the time at which the client successfully connected to the server.
type Commands ΒΆ
type Commands struct {
// contains filtered or unexported fields
}
Commands holds a large list of useful methods to interact with the server, and wrappers for common events.
func (*Commands) Action ΒΆ
Action sends a PRIVMSG ACTION (/me) to target (either channel, service, or user).
func (*Commands) Actionf ΒΆ
Actionf sends a formated PRIVMSG ACTION (/me) to target (either channel, service, or user).
func (*Commands) Away ΒΆ
Away sends a AWAY query to the server, suggesting that the client is no longer active. If reason is blank, Client.Back() is called. Also see Client.Back().
func (*Commands) Back ΒΆ
func (cmd *Commands) Back()
Back sends a AWAY query to the server, however the query is blank, suggesting that the client is active once again. Also see Client.Away().
func (*Commands) Join ΒΆ
Join attempts to enter a list of IRC channels, at bulk if possible to prevent sending extensive JOIN commands.
func (*Commands) Kick ΒΆ
Kick sends a KICK query to the server, attempting to kick nick from channel, with reason. If reason is blank, one will not be sent to the server.
func (*Commands) List ΒΆ
List sends a LIST query to the server, which will list channels and topics. Supports multiple channels at once, in hopes it will reduce extensive LIST queries to the server. Supply no channels to run a list against the entire server (warning, that may mean LOTS of channels!)
func (*Commands) Messagef ΒΆ
Messagef sends a formated PRIVMSG to target (either channel, service, or user).
func (*Commands) Mode ΒΆ
Mode sends a mode change to the server which should be applied to target (usually a channel or user), along with a set of modes (generally "+m", "+mmmm", or "-m", where "m" is the mode you want to change). Params is only needed if the mode change requires a parameter (ban or invite-only exclude.)
func (*Commands) Monitor ΒΆ
Monitor sends a MONITOR query to the server. The results of the query depends on the given modifier, see https://ircv3.net/specs/core/monitor-3.2.html
func (*Commands) Noticef ΒΆ
Noticef sends a formated NOTICE to target (either channel, service, or user).
func (*Commands) Oper ΒΆ
Oper sends a OPER authentication query to the server, with a username and password.
func (*Commands) PartMessage ΒΆ
PartMessage leaves an IRC channel with a specified leave message.
func (*Commands) Ping ΒΆ
Ping sends a PING query to the server, with a specific identifier that the server should respond with.
func (*Commands) Pong ΒΆ
Pong sends a PONG query to the server, with an identifier which was received from a previous PING query received by the client.
func (*Commands) Reply ΒΆ
Reply sends a reply to channel or user, based on where the supplied event originated from. See also ReplyTo(). Panics if the incoming event has no source.
func (*Commands) ReplyTo ΒΆ
ReplyTo sends a reply to a channel or user, based on where the supplied event originated from. ReplyTo(), when originating from a channel will default to replying with "<user>, <message>". See also Reply(). Panics if the incoming event has no source.
func (*Commands) ReplyTof ΒΆ
ReplyTof sends a reply to a channel or user with a format string, based on where the supplied event originated from. ReplyTo(), when originating from a channel will default to replying with "<user>, <message>". See also Replyf(). Panics if the incoming event has no source.
func (*Commands) Replyf ΒΆ
Replyf sends a reply to channel or user with a format string, based on where the supplied event originated from. See also ReplyTof(). Panics if the incoming event has no source.
func (*Commands) SendCTCP ΒΆ
SendCTCP sends a CTCP request to target. Note that this method uses PRIVMSG specifically. ctcpType is the CTCP command, e.g. "FINGER", "TIME", "VERSION", etc.
func (*Commands) SendCTCPReply ΒΆ
SendCTCPReply sends a CTCP response to target. Note that this method uses NOTICE specifically.
func (*Commands) SendCTCPReplyf ΒΆ
SendCTCPReplyf sends a CTCP response to target using a specific format. Note that this method uses NOTICE specifically. ctcpType is the CTCP command, e.g. "FINGER", "TIME", "VERSION", etc.
func (*Commands) SendCTCPf ΒΆ
SendCTCPf sends a CTCP request to target using a specific format. Note that this method uses PRIVMSG specifically. ctcpType is the CTCP command, e.g. "FINGER", "TIME", "VERSION", etc.
func (*Commands) SendRaw ΒΆ
SendRaw sends a raw string (or multiple) to the server, without carriage returns or newlines. Returns an error if one of the raw strings cannot be properly parsed.
func (*Commands) SendRawf ΒΆ
SendRawf sends a formated string back to the server, without carriage returns or newlines.
func (*Commands) Topic ΒΆ
Topic sets the topic of channel to message. Does not verify the length of the topic.
func (*Commands) Who ΒΆ
Who sends a WHO query to the server, which will attempt WHOX by default. See http://faerion.sourceforge.net/doc/irc/whox.var for more details. This sends "%tcuhnr,2" per default. Do not use "1" as this will conflict with girc's builtin tracking functionality.
type Config ΒΆ
type Config struct { // Server is a host/ip of the server you want to connect to. This only // has an affect during the dial process Server string // ServerPass is the server password used to authenticate. This only has // an affect during the dial process. ServerPass string // Port is the port that will be used during server connection. This only // has an affect during the dial process. Port int // Nick is an rfc-valid nickname used during connection. This only has an // affect during the dial process. Nick string // User is the username/ident to use on connect. Ignored if an identd // server is used. This only has an affect during the dial process. User string // Name is the "realname" that's used during connection. This only has an // affect during the dial process. Name string // SASL contains the necessary authentication data to authenticate // with SASL. See the documentation for SASLMech for what is currently // supported. Capability tracking must be enabled for this to work, as // this requires IRCv3 CAP handling. SASL SASLMech // WebIRC allows forwarding source user hostname/ip information to the server // (if supported by the server) to ensure the source machine doesn't show as // the source. See the WebIRC type for more information. WebIRC WebIRC // Bind is used to bind to a specific host or ip during the dial process // when connecting to the server. This can be a hostname, however it must // resolve to an IPv4/IPv6 address bindable on your system. Otherwise, // you can simply use a IPv4/IPv6 address directly. This only has an // affect during the dial process and will not work with DialerConnect(). Bind string // SSL allows dialing via TLS. See TLSConfig to set your own TLS // configuration (e.g. to not force hostname checking). This only has an // affect during the dial process. SSL bool // DisableSTS disables the use of automatic STS connection upgrades // when the server supports STS. STS can also be disabled using the environment // variable "GIRC_DISABLE_STS=true". As many clients may not propagate options // like this back to the user, this allows to directly disable such automatic // functionality. DisableSTS bool // DisableSTSFallback disables the "fallback" to a non-tls connection if the // strict transport policy expires and the first attempt to reconnect back to // the tls version fails. DisableSTSFallback bool // TLSConfig is an optional user-supplied tls configuration, used during // socket creation to the server. SSL must be enabled for this to be used. // This only has an affect during the dial process. TLSConfig *tls.Config // AllowFlood allows the client to bypass the rate limit of outbound // messages. AllowFlood bool // GlobalFormat enables passing through all events which have trailing // text through the color Fmt() function, so you don't have to wrap // every response in the Fmt() method. // // Note that this only actually applies to PRIVMSG, NOTICE and TOPIC // events, to ensure it doesn't clobber unwanted events. GlobalFormat bool // Debug is an optional, user supplied location to log the raw lines // sent from the server, or other useful debug logs. Defaults to // ioutil.Discard. For quick debugging, this could be set to os.Stdout. Debug io.Writer // Out is used to write out a prettified version of incoming events. For // example, channel JOIN/PART, PRIVMSG/NOTICE, KICk, etc. Useful to get // a brief output of the activity of the client. If you are looking to // log raw messages, look at a handler and girc.ALLEVENTS and the relevant // Event.Bytes() or Event.String() methods. Out io.Writer // RecoverFunc is called when a handler throws a panic. If RecoverFunc is // set, the panic will be considered recovered, otherwise the client will // panic. Set this to DefaultRecoverHandler if you don't want the client // to panic, however you don't want to handle the panic yourself. // DefaultRecoverHandler will log the panic to Debug or os.Stdout if // Debug is unset. RecoverFunc func(c *Client, e *HandlerError) // SupportedCaps are the IRCv3 capabilities you would like the client to // support on top of the ones which the client already supports (see // cap.go for which ones the client enables by default). Only use this // if you have not called DisableTracking(). The keys value gets passed // to the server if supported. SupportedCaps map[string][]string // Version is the application version information that will be used in // response to a CTCP VERSION, if default CTCP replies have not been // overwritten or a VERSION handler was already supplied. Version string // PingDelay is the frequency between when the client sends a keep-alive // PING to the server, and awaits a response (and times out if the server // doesn't respond in time). This should be between 20-600 seconds. See // Client.Latency() if you want to determine the delay between the server // and the client. If this is set to -1, the client will not attempt to // send client -> server PING requests. PingDelay time.Duration // PingTimeout specifies the duration at which girc will assume // that the connection to the server has been lost if no PONG // message has been received in reply to an outstanding PING. PingTimeout time.Duration // HandleNickCollide when set, allows the client to handle nick collisions // in a custom way. If unset, the client will attempt to append a // underscore to the end of the nickname, in order to bypass using // an invalid nickname. For example, if "test" is already in use, or is // blocked by the network/a service, the client will try and use "test_", // then it will attempt "test__", "test___", and so on. // // If HandleNickCollide returns an empty string, the client will not // attempt to fix nickname collisions, and you must handle this yourself. HandleNickCollide func(oldNick string) (newNick string) // contains filtered or unexported fields }
Config contains configuration options for an IRC client
type Dialer ΒΆ
type Dialer interface { // Dial takes two arguments. Network, which should be similar to "tcp", // "tdp6", "udp", etc -- as well as address, which is the hostname or ip // of the network. Note that network can be ignored if your transport // doesn't take advantage of network types. Dial(network, address string) (net.Conn, error) }
Dialer is an interface implementation of net.Dialer. Use this if you would like to implement your own dialer which the client will use when connecting.
type ErrEvent ΒΆ
type ErrEvent struct {
Event *Event
}
ErrEvent is an error returned when the server (or library) sends an ERROR message response. The string returned contains the trailing text from the message.
type ErrInvalidConfig ΒΆ
type ErrInvalidConfig struct { Conf Config // Conf is the configuration that was not valid. // contains filtered or unexported fields }
ErrInvalidConfig is returned when the configuration passed to the client is invalid.
func (ErrInvalidConfig) Error ΒΆ
func (e ErrInvalidConfig) Error() string
type ErrParseEvent ΒΆ
type ErrParseEvent struct {
Line string
}
ErrParseEvent is returned when an event cannot be parsed with ParseEvent().
func (ErrParseEvent) Error ΒΆ
func (e ErrParseEvent) Error() string
type ErrSTSUpgradeFailed ΒΆ
type ErrSTSUpgradeFailed struct {
Err error
}
ErrSTSUpgradeFailed is an error that occurs when a connection that was attempted to be upgraded via a strict transport policy, failed. This does not necessarily indicate that STS was to blame, but the underlying connection failed for some reason.
func (ErrSTSUpgradeFailed) Error ΒΆ
func (e ErrSTSUpgradeFailed) Error() string
type ErrTimedOut ΒΆ
type ErrTimedOut struct { // TimeSinceSuccess is how long ago we received a successful pong. TimeSinceSuccess time.Duration // LastPong is the time we received our last successful pong. LastPong time.Time // LastPong is the last time we sent a pong request. LastPing time.Time // Delay is the configured delay between how often we send a ping request. Delay time.Duration }
ErrTimedOut is returned when we attempt to ping the server, and timed out before receiving a PONG back.
func (ErrTimedOut) Error ΒΆ
func (ErrTimedOut) Error() string
type Event ΒΆ
type Event struct { // Source is the origin of the event. Source *Source `json:"source"` // Tags are the IRCv3 style message tags for the given event. Only use // if network supported. Tags Tags `json:"tags"` // Timestamp is the time the event was received. This could optionally be // used for client-stored sent messages too. If the server supports the // "server-time" capability, this is synced to the UTC time that the server // specifies. Timestamp time.Time `json:"timestamp"` // Command that represents the event, e.g. JOIN, PRIVMSG, KILL. Command string `json:"command"` // Params (parameters/args) to the command. Commonly nickname, channel, etc. // The last item in the slice could potentially contain spaces (commonly // referred to as the "trailing" parameter). Params []string `json:"params"` // Sensitive should be true if the message is sensitive (e.g. and should // not be logged/shown in debugging output). Sensitive bool `json:"sensitive"` // If the event is an echo-message response. Echo bool `json:"echo"` }
Event represents an IRC protocol message, see RFC1459 section 2.3.1
<message> :: [':' <prefix> <SPACE>] <command> <params> <crlf> <prefix> :: <servername> | <nick> ['!' <user>] ['@' <host>] <command> :: <letter>{<letter>} | <number> <number> <number> <SPACE> :: ' '{' '} <params> :: <SPACE> [':' <trailing> | <middle> <params>] <middle> :: <Any *non-empty* sequence of octets not including SPACE or NUL or CR or LF, the first of which may not be ':'> <trailing> :: <Any, possibly empty, sequence of octets not including NUL or CR or LF> <crlf> :: CR LF
func ParseEvent ΒΆ
ParseEvent takes a string and attempts to create a Event struct. Returns nil if the Event is invalid.
func (*Event) Bytes ΒΆ
Bytes returns a []byte representation of event. Strips all newlines and carriage returns.
func (*Event) Copy ΒΆ
Copy makes a deep copy of a given event, for use with allowing untrusted functions/handlers edit the event without causing potential issues with other handlers.
func (*Event) IsCTCP ΒΆ
IsCTCP checks to see if the event is a CTCP event, and if so, returns the converted CTCP event.
func (*Event) IsFromChannel ΒΆ
IsFromChannel checks to see if a message was from a channel (rather than a private message).
func (*Event) IsFromUser ΒΆ
IsFromUser checks to see if a message was from a user (rather than a channel).
func (*Event) Len ΒΆ
Len calculates the length of the string representation of event (including tags). Note that this will return the true length (even if longer than what IRC supports), which may be useful if you are trying to check and see if a message is too long, to trim it down yourself.
func (*Event) LenOpts ΒΆ
LenOpts calculates the length of the string representation of event (with a toggle for tags). Note that this will return the true length (even if longer than what IRC supports), which may be useful if you are trying to check and see if a message is too long, to trim it down yourself.
func (*Event) Pretty ΒΆ
Pretty returns a prettified string of the event. If the event doesn't support prettification, ok is false. Pretty is not just useful to make an event prettier, but also to filter out events that most don't visually see in normal IRC clients. e.g. most clients don't show WHO queries.
func (*Event) String ΒΆ
String returns a string representation of this event. Strips all newlines and carriage returns.
func (*Event) StripAction ΒΆ
StripAction returns the stripped version of the action encoding from a PRIVMSG ACTION (/me).
type HandlerError ΒΆ
type HandlerError struct { Event Event // Event is the event that caused the error. ID string // ID is the CUID of the handler. File string // File is the file from where the panic originated. Line int // Line number where panic originated. Func string // Function name where panic originated. Panic interface{} // Panic is the error that was passed to panic(). Stack []byte // Stack is the call stack. Note you may have to skip 1 or 2 due to debug functions. // contains filtered or unexported fields }
HandlerError is the error returned when a panic is intentionally recovered from. It contains useful information like the handler identifier (if applicable), filename, line in file where panic occurred, the call trace, and original event.
func (*HandlerError) Error ΒΆ
func (e *HandlerError) Error() string
Error returns a prettified version of HandlerError, containing ID, file, line, and basic error string.
func (*HandlerError) String ΒΆ
func (e *HandlerError) String() string
String returns the error that panic returned, as well as the entire call trace of where it originated.
type HandlerFunc ΒΆ
HandlerFunc is a type that represents the function necessary to implement Handler.
func (HandlerFunc) Execute ΒΆ
func (f HandlerFunc) Execute(client *Client, event Event)
Execute calls the HandlerFunc with the sender and irc message.
type Perms ΒΆ
type Perms struct { // Owner (non-rfc) indicates that the user has full permissions to the // channel. More than one user can have owner permission. Owner bool `json:"owner"` // Admin (non-rfc) is commonly given to users that are trusted enough // to manage channel permissions, as well as higher level service settings. Admin bool `json:"admin"` // Op is commonly given to trusted users who can manage a given channel // by kicking, and banning users. Op bool `json:"op"` // HalfOp (non-rfc) is commonly used to give users permissions like the // ability to kick, without giving them greater abilities to ban all users. HalfOp bool `json:"half_op"` // Voice indicates the user has voice permissions, commonly given to known // users, with very light trust, or to indicate a user is active. Voice bool `json:"voice"` }
Perms contains all channel-based user permissions. The minimum op, and voice should be supported on all networks. This also supports non-rfc Owner, Admin, and HalfOp, if the network has support for it.
type SASLExternal ΒΆ
type SASLExternal struct { // Identity is an optional field which allows the client to specify // pre-authentication identification. This means that EXTERNAL will // supply this in the initial response. This usually isn't needed (e.g. // CertFP). Identity string `json:"identity"` }
SASLExternal implements the "EXTERNAL" SASL type.
func (*SASLExternal) Encode ΒΆ
func (sasl *SASLExternal) Encode(params []string) string
Encode for external SALS authentication should really only return a "+", unless the user has specified pre-authentication or identification data. See https://tools.ietf.org/html/rfc4422#appendix-A for more info.
func (*SASLExternal) Method ΒΆ
func (sasl *SASLExternal) Method() string
Method identifies what type of SASL this implements.
type SASLMech ΒΆ
type SASLMech interface { // Method returns the uppercase version of the SASL mechanism name. Method() string // Encode returns the response that the SASL mechanism wants to use. If // the returned string is empty (e.g. the mechanism gives up), the handler // will attempt to panic, as expectation is that if SASL authentication // fails, the client will disconnect. Encode(params []string) (output string) }
SASLMech is an representation of what a SASL mechanism should support. See SASLExternal and SASLPlain for implementations of this.
type SASLPlain ΒΆ
type SASLPlain struct { User string `json:"user"` // User is the username for SASL. Pass string `json:"pass"` // Pass is the password for SASL. }
SASLPlain contains the user and password needed for PLAIN SASL authentication.
func (*SASLPlain) Encode ΒΆ
Encode encodes the plain user+password into a SASL PLAIN implementation. See https://tools.ietf.org/rfc/rfc4422.txt for more info.
type Source ΒΆ
type Source struct { // Name is the nickname, server name, or service name, in its original // non-rfc1459 form. Name string `json:"name"` // Ident is commonly known as the "user". Ident string `json:"ident"` // Host is the hostname or IP address of the user/service. Is not accurate // due to how IRC servers can spoof hostnames. Host string `json:"host"` }
Source represents the sender of an IRC event, see RFC1459 section 2.3.1. <servername> | <nick> [ '!' <user> ] [ '@' <host> ]
func ParseSource ΒΆ
ParseSource takes a string and attempts to create a Source struct.
func (*Source) ID ΒΆ
ID is the nickname, server name, or service name, in it's converted and comparable) form.
func (*Source) IsHostmask ΒΆ
IsHostmask returns true if source looks like a user hostmask.
type Tags ΒΆ
Tags represents the key-value pairs in IRCv3 message tags. The map contains the encoded message-tag values. If the tag is present, it may still be empty. See Tags.Get() and Tags.Set() for use with getting/setting information within the tags.
Note that retrieving and setting tags are not concurrent safe. If this is necessary, you will need to implement it yourself.
func ParseTags ΒΆ
ParseTags parses out the key-value map of tags. raw should only be the tag data, not a full message. For example:
@aaa=bbb;ccc;example.com/ddd=eee
NOT:
@aaa=bbb;ccc;example.com/ddd=eee :nick!ident@host.com PRIVMSG me :Hello
Technically, there is a length limit of 4096, but the server should reject tag messages longer than this.
func (Tags) Bytes ΒΆ
Bytes returns a []byte representation of this tag map, including the tag prefix ("@"). Note that this will return the tags sorted, regardless of the order of how they were originally parsed.
func (Tags) Equals ΒΆ
Equals compares two Tags for equality. With the msgid IRCv3 spec +\ echo-message (amongst others), we may receive events that have msgid's, whereas our local events will not have the msgid. As such, don't compare all tags, only the necessary/important tags.
func (Tags) Get ΒΆ
Get returns the unescaped value of given tag key. Note that this is not concurrent safe.
func (Tags) Len ΒΆ
Len determines the length of the bytes representation of this tag map. This does not include the trailing space required when creating an event, but does include the tag prefix ("@").
type User ΒΆ
type User struct { // Nick is the users current nickname. rfc1459 compliant. Nick string `json:"nick"` // Ident is the users username/ident. Ident is commonly prefixed with a // "~", which indicates that they do not have a identd server setup for // authentication. Ident string `json:"ident"` // Host is the visible host of the users connection that the server has // provided to us for their connection. May not always be accurate due to // many networks spoofing/hiding parts of the hostname for privacy // reasons. Host string `json:"host"` // ChannelList is a sorted list of all channels that we are currently // tracking the user in. Each channel name is rfc1459 compliant. See // User.Channels() for a shorthand if you're looking for the *Channel // version of the channel list. ChannelList []string `json:"channels"` // FirstSeen represents the first time that the user was seen by the // client for the given channel. Only usable if from state, not in past. FirstSeen time.Time `json:"first_seen"` // LastActive represents the last time that we saw the user active, // which could be during nickname change, message, channel join, etc. // Only usable if from state, not in past. LastActive time.Time `json:"last_active"` // Perms are the user permissions applied to this user that affect the given // channel. This supports non-rfc style modes like Admin, Owner, and HalfOp. Perms *UserPerms `json:"perms"` // Extras are things added on by additional tracking methods, which may // or may not work on the IRC server in mention. Extras struct { // Name is the users "realname" or full name. Commonly contains links // to the IRC client being used, or something of non-importance. May // also be empty if unsupported by the server/tracking is disabled. Name string `json:"name"` // Account refers to the account which the user is authenticated as. // This differs between each network (e.g. usually Nickserv, but // could also be something like Undernet). May also be empty if // unsupported by the server/tracking is disabled. Account string `json:"account"` // Away refers to the away status of the user. An empty string // indicates that they are active, otherwise the string is what they // set as their away message. May also be empty if unsupported by the // server/tracking is disabled. Away string `json:"away"` } `json:"extras"` }
User represents an IRC user and the state attached to them.
func (*User) Active ΒΆ
Active represents the the amount of time that has passed since we have last seen the user.
func (User) Channels ΒΆ
Channels returns a reference of *Channels that the client knows the user is in. If you're just looking for the namme of the channels, use User.ChannelList.
func (*User) Copy ΒΆ
Copy returns a deep copy of the user which can be modified without making changes to the actual state.
type UserPerms ΒΆ
type UserPerms struct {
// contains filtered or unexported fields
}
UserPerms contains all of the permissions for each channel the user is in.
func (*UserPerms) Lookup ΒΆ
Lookup looks up the users permissions for a given channel. ok is false if the user is not in the given channel.
func (*UserPerms) MarshalJSON ΒΆ
MarshalJSON implements json.Marshaler.
type WebIRC ΒΆ
type WebIRC struct { // Password that authenticates the WEBIRC command from this client. Password string // Gateway or client type requesting spoof (cgiirc defaults to cgiirc, as an // example). Gateway string // Hostname of user. Hostname string // Address either in IPv4 dotted quad notation (e.g. 192.0.0.2) or IPv6 // notation (e.g. 1234:5678:9abc::def). IPv4-in-IPv6 addresses // (e.g. ::ffff:192.0.0.2) should not be sent. Address string }
WebIRC is useful when a user connects through an indirect method, such web clients, the indirect client sends its own IP address instead of sending the user's IP address unless WebIRC is implemented by both the client and the server.
Client expectations:
- Perform any proxy resolution.
- Check the reverse DNS and forward DNS match.
- Check the IP against suitable access controls (ipaccess, dnsbl, etc).
More information: