Documentation ¶
Index ¶
- Variables
- func CmdIson(s Server, u *User, msg *irc.Message) error
- func CmdJoin(s Server, u *User, msg *irc.Message) error
- func CmdMotd(s Server, u *User, _ *irc.Message) error
- func CmdNames(s Server, u *User, msg *irc.Message) error
- func CmdNick(s Server, u *User, msg *irc.Message) error
- func CmdPart(s Server, u *User, msg *irc.Message) error
- func CmdPing(s Server, u *User, msg *irc.Message) error
- func CmdPrivMsg(s Server, u *User, msg *irc.Message) error
- func CmdQuit(s Server, u *User, msg *irc.Message) error
- func CmdWho(s Server, u *User, msg *irc.Message) error
- func ID(s string) string
- func SetLogger(l log.Logger)
- type Channel
- type Commands
- type Conn
- type Event
- type EventKind
- type Handler
- type Prefixer
- type Publisher
- type Server
- type ServerConfig
- type User
- func (u *User) Channels() []Channel
- func (u *User) Close() error
- func (user *User) Decode() (*irc.Message, error)
- func (user *User) Encode(msgs ...*irc.Message) (err error)
- func (u *User) ID() string
- func (u *User) NumChannels() int
- func (u *User) Prefix() *irc.Prefix
- func (u *User) String() string
- func (u *User) VisibleTo() []*User
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrHandshakeFailed = errors.New("handshake failed")
View Source
var ErrUnknownCommand = errors.New("unknown command")
The error returned when an invalid command is issued.
Functions ¶
func CmdPrivMsg ¶
CmdPrivMsg is a handler for the /PRIVMSG command.
Types ¶
type Channel ¶
type Channel interface { Prefixer Publisher // ID is a normalized unique identifier for the channel ID() string // Created returns the time when the Channel was created. Created() time.Time // Names returns a sorted slice of Nicks in the channel Names() []string // Users returns a slice of Users in the channel. Users() []*User // HasUser returns whether a User is in the channel. HasUser(*User) bool // Invite prompts the User to join the Channel on behalf of Prefixer. Invite(from Prefixer, u *User) error // Join introduces the User to the channel (handler for JOIN). Join(u *User) error // Part removes the User from the channel (handler for PART). Part(u *User, text string) // Message transmits a message from a User to the channel (handler for PRIVMSG). Message(u *User, text string) // Topic sets the topic of the channel (handler for TOPIC). Topic(from Prefixer, text string) // Unlink will disassociate the Channel from its Server. Unlink() // Len returns the number of Users in the channel. Len() int // String returns the name of the channel String() string }
Channel is a representation of a room in our server
func NewChannel ¶
NewChannel returns a Channel implementation for a given Server.
type Commands ¶
func DefaultCommands ¶
func DefaultCommands() Commands
type Conn ¶
type Conn interface { Close() error Encode(*irc.Message) error Decode() (*irc.Message, error) // ResolveHost returns the resolved host of the RemoteAddr ResolveHost() string }
Conn abstracts the encoding/decoding and sending/receiving when speaking IRC.
type Event ¶
type Event interface { // String returns a user-friendly presentation of the event. String() string // Kind is the event kind. Kind() EventKind // Server associated with the event (or nil). Server() Server // Channel associated with the event (or nil). Channel() Channel // User associated with the event (or nil). User() *User // Message returns the original irc.Message that triggered the event (or nil). Message() *irc.Message }
Event is emitted by a Publisher.
type EventKind ¶
type EventKind int
const ( // ConnectEvent is emitted when a User successfully connects and handshakes with a Server. ConnectEvent EventKind // QuitEvent is emitted when a User is disconnected from a Server. QuitEvent // JoinEvent is emitted when a User joins a Channel. JoinEvent // PartEvent is emitted when a User leaves a Channel. PartEvent // UserMsgEvent is emitted when a User sends a message to another User. UserMsgEvent // ChanMsgEvent is emitted when a User sends a message to a Channel. ChanMsgEvent // EmptyChanEvent is emitted when the last User leaves a Channel. EmptyChanEvent // NewChanEvent is emitted when a new Channel is created. NewChanEvent // ShutdownEvent is emitted when the server shuts down. ShutdownEvent )
type Handler ¶
type Handler struct { // Command is the IRC command that Call handles. Command string // Handler is a function that takes the server, user who sent the message, and a message to perform some command. Call func(s Server, u *User, msg *irc.Message) error // MinParams is the minimum number of params required on the message. MinParams int }
Handler is a container for an irc.Message handler.
type Publisher ¶
type Publisher interface { // Subscribe registers channel to receive events. Will skip events if channel is full. Subscribe(chan<- Event) // Publish emits the Event to all the subscribers. Publish(Event) // Close will close all the subscribing channels. Close() error }
Publisher emits Events to existing subscribers.
func SyncPublisher ¶
func SyncPublisher() Publisher
SyncPublisher creates a Publisher which blocks on all operations.
type Server ¶
type Server interface { Prefixer Publisher // Name of the server (usually hostname). Name() string // Motd is the Message of the Day for the server. Motd() []string // Connect starts the handshake for a new user, blocks until it's completed or failed with an error. Connect(*User) error // Quit removes the user from all the channels and disconnects. Quit(*User, string) // HasUser returns an existing User with a given Nick. HasUser(string) (*User, bool) // RenameUser changes the Nick of a User if the new name is available. // Returns whether the rename was was successful. RenameUser(*User, string) bool // Channel gets or creates a new channel with the given name. Channel(string) Channel // HasChannel returns an existing Channel with a given name. HasChannel(string) (Channel, bool) // UnlinkChannel removes the channel from the server's storage if it // exists. Once removed, the server is free to create a fresh channel with // the same ID. The server is not responsible for evicting members of an // unlinked channel. UnlinkChannel(Channel) }
type ServerConfig ¶
type ServerConfig struct { // Name is used as the prefix for the server. Name string // Version string of the server (default: go-irckit). Version string // Motd is the message of the day for the server, list of message lines where each line should be max 80 chars. Motd []string // InviteOnly prevents regular users from joining and making new channels. InviteOnly bool // MaxNickLen is the maximum length for a NICK value (default: 32) MaxNickLen int // Publisher to use. If nil, a new SyncPublisher will be used. Publisher Publisher // DiscardEmpty setting will start a goroutine to discard empty channels. DiscardEmpty bool // NewChannel overrides the constructor for a new Channel in a given Server and Name. NewChannel func(s Server, name string) Channel // Commands is the handler registry to use (default: DefaultCommands()) Commands Commands }
ServerConfig produces a Server setup with configuration options.
func (ServerConfig) Server ¶
func (c ServerConfig) Server() Server
type User ¶
type User struct { Conn sync.RWMutex Nick string // From NICK command User string // From USER command Real string // From USER command Host string // contains filtered or unexported fields }
func NewUserNet ¶
NewUserNet creates a *User from a net.Conn connection.
func (*User) NumChannels ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.