irc

package
v0.0.0-...-43f74f9 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2017 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChanPrefixNetwork = "#"
	ChanPrefixLocal   = "&"
)
View Source
const (
	CapCmd     = "CAP"
	CapLsCmd   = "LS"
	CapReqCmd  = "REQ"
	CapEndCmd  = "END"
	JoinCmd    = "JOIN"
	ModeCmd    = "MODE"
	NamesCmd   = "NAMES"
	NickCmd    = "NICK"
	OperCmd    = "OPER"
	PartCmd    = "PART"
	PassCmd    = "PASS"
	PingCmd    = "PING"
	PongCmd    = "PONG"
	PrivMsgCmd = "PRIVMSG"
	TopicCmd   = "TOPIC"
	UserCmd    = "USER"
	QuitCmd    = "QUIT"
	WhoCmd     = "WHO"
)
View Source
const (
	ErrAlreadyRegistered = "462"
	ErrBadChannelKey     = "475"
	ErrCannotSendToChan  = "404"
	ErrChannelIsFull     = "471"
	ErrChanOpPrivsNeeded = "482"
	ErrInvalidCapCmd     = "410"
	ErrNeedMoreParams    = "461"
	ErrNickNameInUse     = "433"
	ErrNoMotd            = "422"
	ErrNoNickNameGiven   = "431"
	ErrNoSuchChannel     = "403"
	ErrNoSuchNick        = "401"
	ErrNotOnChannel      = "442"
	ErrNotRegistered     = "451"
	ErrPasswordMismatch  = "464"
	ErrUModeUnknownFlag  = "501"
	ErrUnknownMode       = "472"
	ErrUsersDontMatch    = "502"
)
View Source
const (
	ModeGrant  = "+"
	ModeRevoke = "-"
)
View Source
const (
	ChanModeBan            = "b"
	ChanModeBanException   = "e"
	ChanModeInviteOnly     = "i"
	ChanModeInvitationMask = "I"
	ChanModeKeylock        = "k"
	ChanModeLimit          = "l"
	ChanModeModerated      = "m"
	ChanModeNoExternalMsgs = "n"
	ChanModeOper           = "o"
	ChanModePrivate        = "p"
	ChanModeSecret         = "s"
	ChanModeTopicLock      = "t"
	ChanModeVoice          = "v"
)
View Source
const (
	UserModeAway           = "a"
	UserModeInvisible      = "i"
	UserModeGlobalOperator = "o"
	UserModeLocalOperator  = "O"
)
View Source
const (
	NickMaxLen       = 40
	NickExpireDelay  = 10 * time.Minute
	NickReapInterval = 1 * time.Minute
)
View Source
const (
	RplBanList       = "367"
	RplChannelModeIs = "324"
	RplCreated       = "003"
	RplEndOfBanList  = "368"
	RplEndOfMotd     = "376"
	RplEndOfNames    = "366"
	RplEndOfWho      = "315"
	RplMotdStart     = "375"
	RplMyInfo        = "004"
	RplNameReply     = "353"
	RplNoTopic       = "331"
	RplTopic         = "332"
	RplWelcome       = "001"
	RplWhoReply      = "352"
	RplYoureOper     = "381"
	RplYourHost      = "002"
)
View Source
const MessageMaxLen = 512
View Source
const (
	Version = "chatty-0"
)

Variables

View Source
var (
	BucketConfig = []byte("config")
	BucketOpers  = []byte("opers")
)
View Source
var (
	ConfigPass = []byte("pass")
	ConfigSalt = []byte("salt")
	ConfigCert = []byte("cert")
	ConfigKey  = []byte("key")
)
View Source
var (
	OperPass = []byte("pass")
	OperSalt = []byte("salt")
)
View Source
var (
	Addr       = ":6697"
	ServerName = "localhost"
)
View Source
var Buckets [][]byte = [][]byte{
	BucketConfig,
	BucketOpers,
}
View Source
var DefaultOper = []byte("irc")
View Source
var ErrorText = map[string]string{
	ErrAlreadyRegistered: "Unauthorized command (already registered)",
	ErrBadChannelKey:     "Cannot join channel (+k)",
	ErrCannotSendToChan:  "Cannot send to channel",
	ErrChannelIsFull:     "Cannot join channel (+l)",
	ErrChanOpPrivsNeeded: "You're not channel operator",
	ErrInvalidCapCmd:     "Invalid CAP command",
	ErrNeedMoreParams:    "Not enough parameters",
	ErrNickNameInUse:     "Nickname is already in use",
	ErrNoNickNameGiven:   "No nickname given",
	ErrNoSuchChannel:     "No such channel",
	ErrNoSuchNick:        "No such nick/channel",
	ErrNotOnChannel:      "You're not on that channel",
	ErrNotRegistered:     "You have not registered",
	ErrPasswordMismatch:  "Password incorrect",
	ErrUModeUnknownFlag:  "Unknown MODE flag",
	ErrUnknownMode:       "is unknown mode char to me",
	ErrUsersDontMatch:    "Cannot change mode for other users",
}
View Source
var Quit = errors.New("quit")
View Source
var RplText = map[string]string{
	RplEndOfBanList: "End of Channel Ban List",
	RplEndOfNames:   "End of NAMES list.",
	RplEndOfWho:     "End of WHO list.",
	RplNoTopic:      "No topic is set.",
	RplYoureOper:    "You are now an IRC Operator",
}

Functions

func HasChanPrefix

func HasChanPrefix(chname string) bool

func NewError

func NewError(numeric string, params ...string) error

Types

type Chan

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

func NewChan

func NewChan(name string, nicks *Nicks) *Chan

func (*Chan) Join

func (c *Chan) Join(src *Client, key string) error

func (*Chan) Members

func (c *Chan) Members() []*Client

func (*Chan) Mode

func (c *Chan) Mode(src *Client) ([]Mode, error)

func (*Chan) Name

func (c *Chan) Name() string

func (*Chan) Names

func (c *Chan) Names() []string

func (*Chan) Part

func (c *Chan) Part(src *Client, reason string) error

func (*Chan) PrivMsg

func (c *Chan) PrivMsg(src *Client, text string) error

func (*Chan) Quit

func (c *Chan) Quit(src *Client)

func (*Chan) SetMode

func (c *Chan) SetMode(src *Client) ChanModeCmds

func (*Chan) SetTopic

func (c *Chan) SetTopic(src *Client, topic string) error

func (*Chan) Status

func (c *Chan) Status() string

func (*Chan) Topic

func (c *Chan) Topic(src *Client) (string, error)

type ChanModeCmds

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

func (*ChanModeCmds) Ban

func (cmd *ChanModeCmds) Ban(action string, who string) error

func (ChanModeCmds) Done

func (cmd ChanModeCmds) Done()

func (*ChanModeCmds) Keylock

func (cmd *ChanModeCmds) Keylock(action string, key string) error

func (*ChanModeCmds) Limit

func (cmd *ChanModeCmds) Limit(action string, strlimit string) error

func (*ChanModeCmds) Moderated

func (cmd *ChanModeCmds) Moderated(action string) error

func (*ChanModeCmds) NoExternalMsgs

func (cmd *ChanModeCmds) NoExternalMsgs(action string) error

func (*ChanModeCmds) Oper

func (cmd *ChanModeCmds) Oper(action string, name string) error

func (*ChanModeCmds) TopicLock

func (cmd *ChanModeCmds) TopicLock(action string) error

func (*ChanModeCmds) Voice

func (cmd *ChanModeCmds) Voice(action string, name string) error

type ChanModes

type ChanModes struct {
	Bans           []string
	BanExceptions  []string
	InviteOnly     bool
	InviationMasks []string
	Key            string
	Limit          int
	Moderated      bool
	NoExternalMsgs bool
	Operators      map[UserID]bool
	Private        bool
	Secret         bool
	TopicLock      bool
	Voiced         map[UserID]bool
}

https://www.alien.net.au/irc/chanmodes.html

func NewChanModes

func NewChanModes() *ChanModes

func (ChanModes) UserPrefix

func (c ChanModes) UserPrefix(id UserID) string

type Client

type Client struct {
	User       *User
	ServerName string
	// contains filtered or unexported fields
}

func (*Client) Quit

func (c *Client) Quit()

func (*Client) Relay

func (c *Client) Relay(o Origin, cmd string, params ...string) *Client

func (*Client) Reply

func (c *Client) Reply(cmd string, params ...string) *Client

func (*Client) Send

func (c *Client) Send(cmd string, params ...string) *Client

func (*Client) SendError

func (c *Client) SendError(err error) *Client

func (*Client) SendMessage

func (c *Client) SendMessage(m Message)

func (*Client) SetRegistered

func (c *Client) SetRegistered()

type Command

type Command struct {
	Name   string
	Params []string
}

type DefaultHandler

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

func (*DefaultHandler) Handle

func (h *DefaultHandler) Handle(cmd Command) error

type Error

type Error struct {
	Numeric string
	Params  []string
}

func (Error) Error

func (e Error) Error() string

type Handler

type Handler interface {
	Handle(Command) error
}

func NewDefaultHandler

func NewDefaultHandler(s *Service, c *Client) Handler

type Message

type Message struct {
	Prefix   string
	Cmd      string
	Target   string
	Params   []string
	NoSpaces bool
}

func DecodeMessage

func DecodeMessage(line string) Message

func NewMessage

func NewMessage(cmd string, params ...string) Message

func (Message) Encode

func (m Message) Encode() string

func (Message) String

func (m Message) String() string

type Mode

type Mode struct {
	Action string
	Char   string
	Param  string
	List   []string
}

type NewHandlerFunc

type NewHandlerFunc func(*Service, *Client) Handler

type Nicks

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

func NewNicks

func NewNicks() *Nicks

func (*Nicks) Close

func (n *Nicks) Close()

func (*Nicks) Get

func (n *Nicks) Get(name string) (User, bool)

func (*Nicks) Register

func (n *Nicks) Register(nick string, u *User) bool

func (*Nicks) Unregister

func (n *Nicks) Unregister(u *User)

type Origin

type Origin interface {
	Origin() string
}

type Server

type Server struct {
	Name     string
	Addr     string
	Debug    bool
	Insecure bool
	DataFile string

	NewHandlerFunc       NewHandlerFunc
	RegistrationDeadline time.Duration
	// contains filtered or unexported fields
}

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

func (*Server) Prefix

func (s *Server) Prefix() string

func (*Server) Quit

func (s *Server) Quit()

type Service

type Service struct {
	Name    string
	Started time.Time
	// contains filtered or unexported fields
}

func (*Service) Chan

func (s *Service) Chan(name string) (*Chan, error)

func (*Service) Join

func (s *Service) Join(c *Client, name string, key string) (*Chan, error)

func (*Service) Login

func (s *Service) Login(c *Client)

func (*Service) Mode

func (s *Service) Mode(src *Client) *UserModeCmds

func (*Service) Nick

func (s *Service) Nick(c *Client, nick string) error

func (*Service) Oper

func (s *Service) Oper(c *Client, nick string, plaintext string) error

func (*Service) Origin

func (s *Service) Origin() string

func (*Service) Part

func (s *Service) Part(c *Client, name string, reason string) error

func (*Service) PrivMsg

func (s *Service) PrivMsg(src *Client, dest string, text string) error

func (*Service) Quit

func (s *Service) Quit(src *Client, reason string)

type User

type User struct {
	ID       UserID
	Nick     string
	Name     string
	Host     string
	RealHost string
	FullName string
}

func (User) Origin

func (u User) Origin() string

type UserID

type UserID uint64

type UserModeCmds

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

func (UserModeCmds) Done

func (cmd UserModeCmds) Done()

func (*UserModeCmds) Invisible

func (cmd *UserModeCmds) Invisible(action string) error

type UserModes

type UserModes struct {
	Away           bool
	Invisible      bool
	GlobalOperator bool
	LocalOperator  bool
}

Jump to

Keyboard shortcuts

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