irc

package
v0.0.0-...-27f5e65 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 8 Imported by: 19

Documentation

Overview

Package irc defines types to be used by most other packages in the ultimateq system. It is small and comprised mostly of helper like types and constants.

Index

Constants

View Source
const (
	INFO_RFC         = "RFC"
	INFO_IRCD        = "IRCD"
	INFO_CASEMAPPING = "CASEMAPPING"
	INFO_PREFIX      = "PREFIX"
	INFO_CHANTYPES   = "CHANTYPES"
	INFO_CHANMODES   = "CHANMODES"
	INFO_CHANLIMIT   = "CHANLIMIT"
	INFO_CHANNELLEN  = "CHANNELLEN"
	INFO_NICKLEN     = "NICKLEN"
	INFO_TOPICLEN    = "TOPICLEN"
	INFO_AWAYLEN     = "AWAYLEN"
	INFO_KICKLEN     = "KICKLEN"
	INFO_MODES       = "MODES"
)

These constants are the mappings from the 004 and 005 events to their respective spots inside the NetworkInfo type.

View Source
const (
	INFO_DEFAULT_SERVERNAME  = "unknown"
	INFO_DEFAULT_IRCDVERSION = "unknown"
	INFO_DEFAULT_USERMODES   = "acCiorRswx"
	INFO_DEFAULT_LCHANMODES  = "beiIklmnoOPrRstvz"

	INFO_DEFAULT_RFC         = "RFC2812"
	INFO_DEFAULT_IRCD        = "unknown"
	INFO_DEFAULT_CASEMAPPING = "ascii"
	INFO_DEFAULT_PREFIX      = "(ov)@+"
	INFO_DEFAULT_CHANTYPES   = "#&~"
	INFO_DEFAULT_CHANMODES   = "beI,k,l,imnOPRstz"
	INFO_DEFAULT_CHANLIMIT   = 20
	INFO_DEFAULT_CHANNELLEN  = 50
	INFO_DEFAULT_NICKLEN     = 9
	INFO_DEFAULT_TOPICLEN    = 490
	INFO_DEFAULT_AWAYLEN     = 127
	INFO_DEFAULT_KICKLEN     = 400
	INFO_DEFAULT_MODES       = 5
)

These constants are healthy defaults for a NetworkInfo type. They were taken from ngircd.

View Source
const (
	JOIN    = "JOIN"
	KICK    = "KICK"
	MODE    = "MODE"
	NICK    = "NICK"
	NOTICE  = "NOTICE"
	PART    = "PART"
	PING    = "PING"
	PONG    = "PONG"
	PRIVMSG = "PRIVMSG"
	QUIT    = "QUIT"
	TOPIC   = "TOPIC"

	CTCP      = PRIVMSG
	CTCPReply = NOTICE
)

IRC Events, these events are 1-1 constant to string lookups for ease of use when registering handlers etc.

View Source
const (
	RPL_WELCOME         = "001"
	RPL_YOURHOST        = "002"
	RPL_CREATED         = "003"
	RPL_MYINFO          = "004"
	RPL_ISUPPORT        = "005"
	RPL_BOUNCE          = "005"
	RPL_USERHOST        = "302"
	RPL_ISON            = "303"
	RPL_AWAY            = "301"
	RPL_UNAWAY          = "305"
	RPL_NOWAWAY         = "306"
	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_LISTSTART       = "321"
	RPL_LIST            = "322"
	RPL_LISTEND         = "323"
	RPL_UNIQOPIS        = "325"
	RPL_CHANNELMODEIS   = "324"
	RPL_NOTOPIC         = "331"
	RPL_TOPIC           = "332"
	RPL_INVITING        = "341"
	RPL_SUMMONING       = "342"
	RPL_INVITELIST      = "346"
	RPL_ENDOFINVITELIST = "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_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"

	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_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"
)

IRC Reply and Error Events. These are sent in reply to a previous event.

View Source
const (
	RAW        = "RAW"
	CONNECT    = "CONNECT"
	DISCONNECT = "DISCONNECT"
)

Pseudo Events, these events are not real events defined by the irc protocol but the bot provides them to allow for additional events to be handled such as connect or disconnects which the irc protocol has no protocol defined for.

View Source
const (
	// IRC_MAX_LENGTH is the maximum length for an irc message. Normally it is
	// 510 bytes + crlf but the server has to truncate extra to allow for our
	// fullhost on rebroadcast to clients, so we should send less than
	// this by the maximum allowed fullhost length.
	IRC_MAX_LENGTH = 510 - 62
	// SPLIT_BACKWARD is the maximum number of characters split will search
	// backwards from IRC_MAX_LENGTH for a space when spliting message to long
	// to fit on one line
	SPLIT_BACKWARD = 20
)

Variables

This section is empty.

Functions

func CTCPpack

func CTCPpack(tag, data []byte) []byte

CTCPpack packs a message into CTCP format.

func CTCPpackString

func CTCPpackString(tag, data string) string

CTCPpackString packs a message into CTCP format from strings.

func CTCPunpack

func CTCPunpack(msg []byte) (tag []byte, data []byte)

CTCPunpack unpacks a CTCP message.

func CTCPunpackString

func CTCPunpackString(msg string) (tag, data string)

CTCPunpackString unpacks a CTCP message to strings.

func Hostname

func Hostname(host string) string

Hostname returns the host of the host.

func IsCTCP

func IsCTCP(msg []byte) bool

IsCTCP checks if the current byte string is a CTCP message.

func IsCTCPString

func IsCTCPString(msg string) bool

IsCTCPString checks if the current string is a CTCP message.

func Nick

func Nick(host string) string

Nick returns the nick of the host.

func Split

func Split(host string) (nick, user, hostname string)

Split splits a host into it's fragments: nick, user, and hostname. If the format is not acceptable empty string is returned for everything.

func Username

func Username(host string) string

Username returns the username of the host.

Types

type Event

type Event struct {
	// Name of the event. Uppercase constant name or numeric.
	Name string `msgpack:"name"`
	// Sender is the server or user that sent the event, normally a fullhost.
	Sender string `msgpack:"sender"`
	// Args split by space delimiting.
	Args []string `msgpack:"args"`
	// Times is the time this event was received.
	Time time.Time `msgpack:"time"`
	// NetworkID is the ID of the network that sent this event.
	NetworkID string `msgpack:"network_id"`
	// NetworkInfo is the networks information.
	NetworkInfo *NetworkInfo `msgpack:"-"`
}

Event contains all the information about an irc event.

func NewEvent

func NewEvent(netID string, ni *NetworkInfo, name, sender string,
	args ...string) *Event

NewEvent constructs a event object that has a timestamp.

func (*Event) Hostname

func (e *Event) Hostname() string

Hostname returns the host of the sender. Will be empty string if it was not able to parse the sender.

func (*Event) IsCTCP

func (e *Event) IsCTCP() bool

IsCTCP checks if this event is a CTCP event. This means it's delimited by the CTCPDelim as well as being PRIVMSG or NOTICE only.

func (*Event) IsTargetChan

func (e *Event) IsTargetChan() bool

IsTargetChan uses the underlying NetworkInfo to decide if this is a channel or not. If there is no NetworkInfo it will panic.

func (*Event) Message

func (e *Event) Message() string

Message retrieves the message sent to the user or channel. Before using this method it would be prudent to check that the Event.Name is a message that supports a Message argument.

func (*Event) Nick

func (e *Event) Nick() string

Nick returns the nick of the sender. Will be empty string if it was not able to parse the sender.

func (*Event) SplitArgs

func (e *Event) SplitArgs(index int) []string

SplitArgs splits string arguments. A convenience method to avoid having to call splits and import strings.

func (*Event) SplitHost

func (e *Event) SplitHost() (nick, user, hostname string)

SplitHost splits the sender into it's fragments: nick, user, and hostname. If the format is not acceptable empty string is returned for everything.

func (*Event) String

func (e *Event) String() string

String turns this back into an IRC style message.

func (*Event) Target

func (e *Event) Target() string

Target retrieves the channel or user this event was sent to. Before using this method it would be prudent to check that the Event.Name is a message that supports a Target argument.

func (*Event) UnpackCTCP

func (e *Event) UnpackCTCP() (tag, data string)

UnpackCTCP can be called to retrieve a tag and data from a CTCP event.

func (*Event) Username

func (e *Event) Username() string

Username returns the username of the sender. Will be empty string if it was not able to parse the sender.

type Helper

type Helper struct {
	io.Writer
}

Helper fullfills the Writer's many interface requirements.

func (Helper) CTCP

func (h Helper) CTCP(target, tag string, data ...interface{}) error

CTCP sends a string with spaces between non-strings.

func (Helper) CTCPReply

func (h Helper) CTCPReply(target, tag string, data ...interface{}) error

CTCPReply sends a string with spaces between non-strings.

func (Helper) CTCPReplyf

func (h Helper) CTCPReplyf(target, tag, format string,
	data ...interface{}) error

CTCPReplyf sends a formatted CTCPReply.

func (Helper) CTCPReplyln

func (h Helper) CTCPReplyln(target, tag string, data ...interface{}) error

CTCPReplyln sends a CTCPReply with spaces between everything. Does not send newline.

func (Helper) CTCPf

func (h Helper) CTCPf(target, tag, format string, data ...interface{}) error

CTCPf sends a formatted CTCP.

func (Helper) CTCPln

func (h Helper) CTCPln(target, tag string, data ...interface{}) error

CTCPln sends a CTCP with spaces between everything. Does not send newline.

func (Helper) Join

func (h Helper) Join(targets ...string) error

Join sends a join message to the writer.

func (Helper) Notice

func (h Helper) Notice(target string, args ...interface{}) error

Notice sends a string with spaces between non-strings.

func (Helper) Noticef

func (h Helper) Noticef(target, format string, args ...interface{}) error

Noticef sends a formatted notice.

func (Helper) Noticeln

func (h Helper) Noticeln(target string, args ...interface{}) error

Noticeln sends a notice with spaces between everything. Does not send newline.

func (Helper) Notify

func (h Helper) Notify(ev *Event, target string, args ...interface{}) error

Notify sends a string with spaces between non-strings. See irc.Writer.Notify for details of use.

func (Helper) Notifyf

func (h Helper) Notifyf(ev *Event, target, format string,
	args ...interface{}) error

Notifyf sends a formatted notification. See irc.Writer.Notify for details of use.

func (Helper) Notifyln

func (h Helper) Notifyln(ev *Event, target string, args ...interface{}) error

Notifyln sends a notify with spaces between everything. Does not send newline. See irc.Writer.Notify for details of use.

func (Helper) Part

func (h Helper) Part(targets ...string) error

Part sends a part message to the writer.

func (Helper) Privmsg

func (h Helper) Privmsg(target string, args ...interface{}) error

Privmsg sends a string with spaces between non-strings.

func (Helper) Privmsgf

func (h Helper) Privmsgf(target, format string, args ...interface{}) error

Privmsgf sends a formatted privmsg.

func (Helper) Privmsgln

func (h Helper) Privmsgln(target string, args ...interface{}) error

Privmsgln sends a privmsg with spaces between everything. Does not send newline.

func (Helper) Quit

func (h Helper) Quit(msg string) error

Quit sends a quit message to the writer.

func (Helper) Send

func (h Helper) Send(args ...interface{}) error

Send sends a string with spaces between non-strings.

func (Helper) Sendf

func (h Helper) Sendf(format string, args ...interface{}) error

Sendf sends a formatted string.

func (Helper) Sendln

func (h Helper) Sendln(args ...interface{}) error

Sendln sends a string with spaces between everything. Does not send newline.

type Host

type Host string

Host is a type that represents an irc hostname. nickname!username@hostname

func (Host) Hostname

func (h Host) Hostname() string

Hostname returns the host of the host.

func (Host) IsValid

func (h Host) IsValid() bool

IsValid checks to ensure the host is in valid format.

func (Host) Match

func (h Host) Match(m Mask) bool

Match checks if a given mask is satisfied by the host.

func (Host) Nick

func (h Host) Nick() string

Nick returns the nick of the host.

func (Host) Split

func (h Host) Split() (nick, user, hostname string)

Split splits a host into it's fragments: nick, user, and hostname. If the format is not acceptable empty string is returned for everything.

func (Host) String

func (h Host) String() string

String returns the fullhost of this host.

func (Host) Username

func (h Host) Username() string

Username returns the username of the host.

type Mask

type Mask string

Mask is an irc hostmask that contains wildcard characters ? and *

func (Mask) IsValid

func (m Mask) IsValid() bool

IsValid checks to ensure the mask is in valid format.

func (Mask) Match

func (m Mask) Match(h Host) bool

Match checks if the mask satisfies the given host.

func (Mask) Split

func (m Mask) Split() (nick, user, host string)

Split splits a mask into it's fragments: nick, user, and host. If the format is not acceptable empty string is returned for everything.

type NetworkInfo

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

NetworkInfo is used to record the server capabilities, this later aids in parsing irc protocol.

func NewNetworkInfo

func NewNetworkInfo() *NetworkInfo

NewNetworkInfo initializes a networkinfo struct.

func (*NetworkInfo) Awaylen

func (p *NetworkInfo) Awaylen() int

Awaylen gets the awaylen from the NetworkInfo.

func (*NetworkInfo) Casemapping

func (p *NetworkInfo) Casemapping() string

Casemapping gets the casemapping from the NetworkInfo.

func (*NetworkInfo) Chanlimit

func (p *NetworkInfo) Chanlimit() int

Chanlimit gets the chanlimit from the NetworkInfo.

func (*NetworkInfo) Chanmodes

func (p *NetworkInfo) Chanmodes() string

Chanmodes gets the chanmodes from the NetworkInfo.

func (*NetworkInfo) Channellen

func (p *NetworkInfo) Channellen() int

Channellen gets the channellen from the NetworkInfo.

func (*NetworkInfo) Chantypes

func (p *NetworkInfo) Chantypes() string

Chantypes gets the chantypes from the NetworkInfo.

func (*NetworkInfo) Clone

func (p *NetworkInfo) Clone() *NetworkInfo

Clone safely clones this networkinfo instance.

func (*NetworkInfo) Extra

func (p *NetworkInfo) Extra(key string) string

Extra gets any non-hardcoded modes from the NetworkInfo.

func (*NetworkInfo) Extras

func (p *NetworkInfo) Extras() map[string]string

Extras clones the internal map and returns it

func (*NetworkInfo) IRCD

func (p *NetworkInfo) IRCD() string

IRCD gets the ircd from the NetworkInfo.

func (*NetworkInfo) IrcdVersion

func (p *NetworkInfo) IrcdVersion() string

IrcdVersion gets the irc version from the NetworkInfo.

func (*NetworkInfo) IsChannel

func (p *NetworkInfo) IsChannel(target string) (isChan bool)

IsChannel checks to see if the target is a channel based on this instances chantypes.

func (*NetworkInfo) Kicklen

func (p *NetworkInfo) Kicklen() int

Kicklen gets the kicklen from the NetworkInfo.

func (*NetworkInfo) LegacyChanmodes

func (p *NetworkInfo) LegacyChanmodes() string

LegacyChanmodes gets the legacy channel modes from the NetworkInfo.

func (*NetworkInfo) Modes

func (p *NetworkInfo) Modes() int

Modes gets the modes from the NetworkInfo.

func (*NetworkInfo) Nicklen

func (p *NetworkInfo) Nicklen() int

Nicklen gets the nicklen from the NetworkInfo.

func (*NetworkInfo) ParseISupport

func (p *NetworkInfo) ParseISupport(e *Event)

ParseISupport adds all values in a 005 to the current networkinfo object.

func (*NetworkInfo) ParseMyInfo

func (p *NetworkInfo) ParseMyInfo(e *Event)

ParseMyInfo adds all values in a 005 to the current networkinfo object.

func (*NetworkInfo) Prefix

func (p *NetworkInfo) Prefix() string

Prefix gets the prefix from the NetworkInfo.

func (*NetworkInfo) RFC

func (p *NetworkInfo) RFC() string

RFC gets the rfc from the NetworkInfo.

func (*NetworkInfo) ServerName

func (p *NetworkInfo) ServerName() string

ServerName gets the servername from the NetworkInfo.

func (*NetworkInfo) Topiclen

func (p *NetworkInfo) Topiclen() int

Topiclen gets the topiclen from the NetworkInfo.

func (*NetworkInfo) Usermodes

func (p *NetworkInfo) Usermodes() string

Usermodes gets the usermodes from the NetworkInfo.

type Writer

type Writer interface {
	io.Writer
	// Send sends a string with spaces between non-strings.
	Send(...interface{}) error
	// Sendln sends a string with spaces between everything.
	// Does not send newline.
	Sendln(...interface{}) error
	// Sendf sends a formatted string.
	Sendf(string, ...interface{}) error

	// Privmsg sends a privmsg with spaces between non-strings.
	Privmsg(string, ...interface{}) error
	// Privmsgln sends a privmsg with spaces between everything.
	// Does not send newline.
	Privmsgln(string, ...interface{}) error
	// Privmsgf sends a formatted privmsg.
	Privmsgf(string, string, ...interface{}) error

	// Notice sends a notice with spaces between non-strings.
	Notice(string, ...interface{}) error
	// Noticeln sends a notice with spaces between everything.
	// Does not send newline.
	Noticeln(string, ...interface{}) error
	// Noticef sends a formatted notice.
	Noticef(string, string, ...interface{}) error

	// CTCP sends a CTCP with spaces between non-strings.
	CTCP(string, string, ...interface{}) error
	// CTCPln sends a CTCP with spaces between everything.
	// Does not send newline.
	CTCPln(string, string, ...interface{}) error
	// CTCPf sends a formatted CTCP.
	CTCPf(string, string, string, ...interface{}) error

	// CTCPReply sends a CTCPReply with spaces between non-strings.
	CTCPReply(string, string, ...interface{}) error
	// CTCPReplyln sends a CTCPReply with spaces between everything.
	// Does not send newline.
	CTCPReplyln(string, string, ...interface{}) error
	// CTCPReplyf sends a formatted CTCPReply.
	CTCPReplyf(string, string, string, ...interface{}) error

	// Notify sends a notification with spaces between non-strings.
	// If the Event is designated towards a #channel, then the notification
	// will be sent to that channel. If the Event is designated towards a user
	// (normally the bot itself) then the notification will be sent to the
	// given target.
	Notify(*Event, string, ...interface{}) error
	// Notifyln sends a notification with spaces between everything.
	// Does not send newline. See Notify for details of use.
	Notifyln(*Event, string, ...interface{}) error
	// Notifyf sends a formatted notification. See Notify for details of use.
	Notifyf(*Event, string, string, ...interface{}) error

	// Sends a join message to the writer.
	Join(...string) error
	// Sends a part message to the writer.
	Part(...string) error
	// Sends a quit message to the writer.
	Quit(string) error
}

Writer provides common write operations in IRC protocol fashion to an underlying io.Writer.

Jump to

Keyboard shortcuts

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